API Forex

Forex.com (StoneX / CityIndex)

Forex.com is a retail trading venue operated by StoneX. The component wraps the Trading REST API and the Lightstreamer-based streaming service used by Forex.com, StoneX and CityIndex (all three share the same platform). The following APIs are supported:

  1. Streaming API: Lightstreamer TLCP 2.5 over WebSocket. Price ticks, order updates, position updates, account margin and quotes are pushed in real time after a successful REST LogOn.
  2. REST API: session login (UserName + Password + AppKey), trade and stop-limit order management, account queries and market data. Uses HTTPS.

Components

Published Properties

Published Events

OnForexConnect

Fired once the streaming session has been created and subscriptions can start.

OnForexDisconnect

Fired when the streaming session ends (server close, network drop or explicit Disconnect).

OnForexException

Raised on REST errors (including LogOn failure) and on streaming session faults.

OnForexPriceTick

Fired for every PRICES update: Bid, Offer, Price, Change, Direction, AuditId, TickDate.

OnForexOrderUpdate

Fired for every ORDERS update (new, filled, cancelled, rejected).

OnForexPositionUpdate

Fired for every open-position update on the active TradingAccount.

OnForexAccountMargin

Fired for every CLIENTACCOUNTMARGIN / TRADEMARGIN update (equity, margin, free margin, currency).

OnForexQuote

Fired for every QUOTES update (request-for-quote workflow).

Most common uses

Sample

Create the client, set credentials, connect, subscribe to a market price stream and disconnect.


oForex := TsgcWSAPI_Forex.Create(nil);
oForex.Credentials.UserName := '<username>';
oForex.Credentials.Password := '<password>';
oForex.Credentials.AppKey  := '<appkey>';
oForex.OnForexPriceTick := ForexPriceTick;
oForex.Connect;
oForex.WatchMarket(401484830); // EUR/USD market id
// ... receive price ticks in OnForexPriceTick ...
oForex.Disconnect;