The next sgcWebSockets release — version 2026.5.0 — adds native support for the Forex.com / StoneX / CityIndex Trading API: REST order management plus real-time Lightstreamer streaming, all delivered through a single Delphi component you can drop onto a form.
Three new components cover the whole surface: TsgcHTTP_API_Forex for REST trading, TsgcWSPClient_Lightstreamer for the native Lightstreamer TLCP 2.5 streaming channel, and TsgcWSAPI_Forex as the unified facade that wires them together and publishes typed OnForex* events for prices, orders, positions, quotes and account margin.
What is Included
Every endpoint and streaming adapter the live Forex.com server serves today is supported out of the box.
|
REST Trading LogOn / LogOff / Ping / GetServiceStatus, plus the five order endpoints: NewTradeOrder, UpdateTradeOrder, NewStopLimitOrder, UpdateStopLimitOrder and CancelOrder. Each one ships with three overloads — raw JSON, scalar parameters, or a typed order-object with full IfDone brackets and partial-close support. |
Account & Market Data GetClientAndTradingAccount, ListOpenPositions, ListActiveStopLimitOrders, GetOrder, ListTradeHistory, ListStopLimitOrderHistory, SimulateTrade, GetMarketInformation, ListCfdMarkets, FullSearchWithTags, GetPriceBars and GetPriceTicks. |
|
Real-Time Streaming Five Lightstreamer data adapters under the STREAMINGALL adapter set — PRICES, ORDERS, QUOTES, CLIENTACCOUNTMARGIN and TRADEMARGIN. Each one dispatches parsed records to a typed event: OnForexPriceTick, OnForexOrderUpdate, OnForexPositionUpdate, OnForexAccountMargin, OnForexQuote. |
Unified Facade Component TsgcWSAPI_Forex aggregates the REST client plus the internal Lightstreamer client behind one visual component. Call Connect — REST LogOn runs first, its Session token is forwarded to the Lightstreamer handshake as LS_password, and streaming starts. One component, one call. |
|
Auto-Reconnect Handled by the underlying WebSocket client WatchDog. Before every reconnect attempt the facade refreshes the REST session token; TLCP LOOP frames rebind and replay every active subscription after the network drops. Session expiry re-runs LogOn transparently. |
Platform Reach Delphi 7 through Delphi 13, Professional edition and above. Windows, macOS, Linux, iOS and Android where the compiler supports it. Ships with a .NET mirror (net40+, .NET Standard 2.0, .NET 5-9) backed by the native sgcWebSockets DLL. |
Under the Hood
The streaming half of this integration is the most interesting piece. Forex.com delivers real-time data over Lightstreamer — a proprietary streaming protocol used by a number of brokers and financial data vendors. Until now there has been no native TLCP client for Delphi; existing integrations with Lightstreamer-powered venues all wrap the Lightstreamer JavaScript or Java SDK through browser embeds or external processes.
TsgcWSPClient_Lightstreamer is a from-scratch native implementation of the Lightstreamer TLCP 2.5 protocol: create_session, bind_session, control (subscribe / unsubscribe), the LOOP auto-rebind handler and subscription replay after reconnect — advertised on the wire through the Sec-WebSocket-Protocol: TLCP-2.5.0.lightstreamer.com subprotocol header. This makes sgcWebSockets the first Delphi component library with native TLCP support, and the client is deliberately generic: it ships as its own reusable component, not welded to Forex.com, so the same code path drives any Lightstreamer-based broker (IG Markets, for example) or data vendor.
Item addressing. Every Forex.com adapter uses the same ID.{numericId} item form — the numeric id is a MarketId, ClientAccountId or TradingAccountId, and the DataAdapter selector on the SUB frame (PRICES / ORDERS / QUOTES / CLIENTACCOUNTMARGIN / TRADEMARGIN) decides which dataset is streamed for that id. There are no legacy PRICE.{id} prefixes.
Order-object pattern. Trade requests follow the same Kucoin-style design used elsewhere in the library: TsgcHTTPForexTradeOrder, TsgcHTTPForexStopLimitOrder and TsgcHTTPForexCancelOrder. Build the order once, modify a few fields, send again. Typed IfDone brackets (attached stop / limit / guaranteed-stop / trailing-stop), Close arrays for partial-close semantics, PositionMethodId (netting vs. hedging) and client Reference fields are all first-class.
Code Sample
Drop the facade on a form, set credentials, wire the price tick event, call Connect and WatchMarket. The snippet below is a complete, working example.
var
Forex: TsgcWSAPI_Forex;
begin
Forex := TsgcWSAPI_Forex.Create(nil);
Try
Forex.Credentials.UserName := 'YOUR_USER';
Forex.Credentials.Password := 'YOUR_PASSWORD';
Forex.Credentials.AppKey := 'YOUR_APPKEY';
Forex.OnForexPriceTick := OnPriceTick;
Forex.Connect; // REST LogOn + Lightstreamer
Forex.WatchMarket(401484830); // EUR/USD
Forex.WatchAccount; // ORDERS + margin
// ... run app, receive ticks and order updates ...
Finally
Forex.Free;
End;
end;
procedure TForm1.OnPriceTick(Sender: TObject;
const aTick: TsgcForexPriceTick);
begin
Memo1.Lines.Add(Format('%d bid=%.5f offer=%.5f audit=%s',
[aTick.MarketId, aTick.Bid, aTick.Offer, aTick.AuditId]));
end;
Demo
A full VCL demo lives in Demos\05.Crypto\22.Forex. It is split across three tabs:
- Login — UserName / Password / AppKey fields, Connect / Disconnect / Ping, AutoReconnect toggle, live session / account ids and a running event log. Credentials are persisted to
sgcForexDemo.iniso you only type them once. - REST Trading — market search (FullSearchWithTags), NewTradeOrder / UpdateTradeOrder / NewStopLimitOrder / UpdateStopLimitOrder / CancelOrder, SimulateTrade, GetOrder, ListOpenPositions, ListActiveStopLimitOrders, ListTradeHistory and ListStopLimitOrderHistory.
- Streaming — WatchMarket / UnwatchMarket, live price grid, positions and orders list-views updated in real time from the STREAMINGALL adapter set, and a live account-margin panel (Cash / Margin / NetEquity / TradeableFunds / Currency).
Availability
Available in the next sgcWebSockets release — version 2026.5.0. Existing Enterprise and All-Access license holders receive it as part of their subscription; Professional licenses receive it with their renewal.
Signup for a free Forex.com demo account (including UserName / Password / AppKey) at www.forex.com, with the full API reference at docs.labs.gaincapital.com.
Links
- Component documentation: esegece.com/help/sgcwebsockets/
- Demo folder:
Demos\05.Crypto\22.Forex - Forex.com signup: www.forex.com
- API reference: docs.labs.gaincapital.com
- Lightstreamer TLCP 2.5 specification: TLCP 2.5 PDF
- sgcWebSockets product page: esegece.com