sgcWebSockets Exchange Feeds
Twenty-seven components, one per trading venue, each wrapping that exchange's WebSocket feed: subscribe to trades, order books, tickers and candles, and on most of them subscribe to your own account's private stream.
They follow the same shape as the other protocol components: each attaches to a
TsgcWebSocketClient through its Client property, and each carries an options
object holding the credentials and venue switches.
When to use this skill
- Stream market data from a crypto or forex venue into Delphi
- Subscribe to trades, order book depth, tickers or candlesticks
- Watch your own orders and balances on a private user stream
- Place or query orders through the venue's REST API alongside the socket
Install and uses clause
uses
sgcWebSocket, // TsgcWebSocketClient, the transport
sgcWebSocket_APIs, // 26 of the 27 components
sgcWebSocket_Classes; // TsgcWSConnection
TsgcHTTP_Cryptohopper is the exception and lives in sgcLibs.
The shape they all share
FBinance := TsgcWSAPI_Binance.Create(Self);
FBinance.Client := FWebSocketClient;
FBinance.Binance.ApiKey := GetKeyFromConfig;
FWebSocketClient.Active := True;
Three things are consistent across the set:
- The options object is named after the venue:
FBinance.Binance,FKraken.Kraken, and so on. Credentials and venue switches live there. Subscribe...methods return anIntegersubscription id. Keep it if you intend to unsubscribe selectively later.- Many components expose a
REST_APIproperty for the venue's request/response API, so the socket and the REST calls share one configured component.
Subscribe after the socket is up, not before. The venue has to have accepted the connection before a subscription means anything.
Before you start, ask the developer
Use a structured question tool if your host has one, for example Claude Code's
AskUserQuestion. Otherwise ask in chat:
- Which venue, and is it the main site or a regional one? Binance.com and
Binance.US behave differently and the switch is
Binance.BinanceUS. - Public market data or the private user stream? The private stream needs credentials, and on some venues it now needs a second connection.
- Live or test net? Most options objects have a
TestNetswitch. Ask before pointing generated code at a live trading account. - Which product? Spot and futures are usually separate components, for
example
TsgcWSAPI_BinanceagainstTsgcWSAPI_Binance_Futures. - Do they also need REST? Placing orders is REST, not the socket.
Never write an API key or secret into generated source. Read them from configuration. A leaked exchange key can move real money.
Venues covered
Binance and Binance Futures, Bitfinex, Bitstamp, Bitmex, Bybit, Coinbase, Crypto.com, Deribit, GateIO, Bitget, HTX, Huobi, Kraken (v1, v2 and Futures), Kucoin and Kucoin Futures, MEXC and MEXC Futures, OKX, Cex and CexPlus, ThreeCommas, Cryptohopper, XTB, and a generic Forex feed.
Two venue specifics worth knowing before you write code
Binance spot user data changed. Binance retired the spot listenKey REST
endpoints on 2026-02-20. The replacement lives on a different host from the
market data feed, so the user stream now runs on its own connection, which the
component manages internally. The practical consequence for your code is that
binance.com spot now needs both ApiKey and ApiSecret, because the
subscription is signed. The old listen-key flow only ever needed the key:
FBinance.Binance.ApiKey := GetKeyFromConfig;
FBinance.Binance.ApiSecret := GetSecretFromConfig; // now required for spot
FBinance.Binance.UserStream := True;
Binance.US still uses the listen-key flow and is unaffected. For USD-M futures,
Binance.FuturesStreamEndpoint selects which stream endpoint is used.
Kraken v2 is a separate component, not a version switch. Use
TsgcWSAPI_Kraken_V2 for the v2 feed and TsgcWSAPI_Kraken for v1. Kraken has
announced no deprecation of v1, so do not tell a developer they must migrate.
TsgcWSAPI_Kraken_Futures is a third, separate component.
Quickstart, market data
uses
sgcWebSocket, sgcWebSocket_APIs, sgcWebSocket_Classes;
procedure TForm1.FormCreate(Sender: TObject);
begin
FClient := TsgcWebSocketClient.Create(Self);
FBinance := TsgcWSAPI_Binance.Create(Self);
FBinance.Client := FClient;
FBinance.Binance.TestNet := False;
FBinance.OnConnect := BinanceConnect;
FClient.Active := True;
end;
procedure TForm1.BinanceConnect(Connection: TsgcWSConnection);
begin
FBinance.SubscribeTrades('BTCUSDT');
FBinance.SubscribeKLine('BTCUSDT', bci1m);
FSubId := FBinance.SubscribeMiniTicker('ETHUSDT');
end;
Each venue names its own events, so read the Events section of the component's
API page rather than assuming a common set. The candle interval is an
enumeration specific to the venue: Binance uses TsgcWSBinanceChartIntervals,
which is (bci1s, bci1m, bci3m, bci5m, bci15m, bci30m, bci1h, bci2h, bci4h, bci6h, bci8h, bci12h, bci1d, bci3d, bci1w, bci1Mo).
Things that catch people out
- Subscribing before the connection is up does nothing. Subscribe from the connect event.
- Credentials belong in the venue options object, not on the transport client.
FClientknows nothing about your exchange account. - Spot and futures are different components with different symbols and different endpoints. They are not a switch on one component.
TestNetpoints at a sandbox with separate credentials. Live keys will not authenticate against it.- Exchanges rate limit aggressively. The
Throttleoptions exist for that reason, and subscribing to hundreds of symbols in a loop will get you disconnected. - Reconnecting does not automatically restore subscriptions unless the venue
options say so. Look for a
Resubscribeswitch, and otherwise resubscribe from the connect event, which is another reason to put subscriptions there.
Routing
- Find a component:
reference/components-index.mdlists every component, itsunit, and its edition, grouped by Reg module. - Uses clause: add the component's
unit:value (shown on its API page) to yourusesclause. Nothing compiles without it. - API detail:
reference/api/<Component>.mdhas the Properties, Events and Methods, each in both Delphi and C++Builder form. - Option / enum / event types: property and event types link to
reference/types/<TypeName>.md, which documents the sub-properties of option classes, the values of enums, and the parameter list of event handlers. - Examples:
examples/index.mdis the full demo catalog;examples/<Component>.mdis a focused, real usage snippet for the most-used components. - Concepts:
concepts/overview.md(getting started + uses-clause rule) andconcepts/editions-and-features.md(which components your edition includes). - Bundled resources:
concepts/resources.mdlists the browser-side assets (JavaScript, HTML, CSS) the server components serve or embed, so a browser client works without an external CDN. - Version history:
reference/history.mdlists what changed in each sgcWebSockets release.
Editions
Components are gated by edition (Professional, Enterprise, All-Access) or by a feature define. Check the edition column in the components index, or concepts/editions-and-features.md, before relying on a component.
Only public and published members are documented. Method bodies, private fields and protected members are intentionally not included.