• Yes, requires OpenSSL
  • No, only Blocking mode
  • Yes, Requires Win8.+

From sgcWebSockets 4.3.1, WebSocket client supports Token Authentication.

When a server requires a websocket connection with token authentication, use Authentication.Token property in TsgcWebSocketClient to configure Token Authentication.

 

Example: server requires connect with token "akks9932nefdvf8989dfvnv8998dfvnnna".

oClient := TsgcWebSocketClient.Create(nil);

oClient.Host := 'server host';

oClient.Port := server port;

oClient.Authentication.Enabled := True;

oClient.Authentication.Token.Enabled := True;

oClient.Authentication.Token.AuthToken := 'akks9932nefdvf8989dfvnv8998dfvnnna';

oClient.Authentication.Token.AuthName := 'Bearer';

oClient.Active := True;

From sgcWebSockets 4.3.1, MQTT 5.0 is supported.

New version adds several improvements over 3.1.1 version:

  • Improved error reporting (Reason Code & Reason Name).
  • Message expiration to prevent clients from receiving stale/irrelevant information.
  • Server Brokers can tell clients to re-connect to other broker servers.
  • Extensibility mechanisms including user properties, payload format and content type.
  • Enhanced authentication mechanism.

To implement all these features, new methods and events have been modified/added. 

Basically methods are backward compatible with 3.1.1, so there is no need to change your code. New properties have been implemented in overloaded methods or as parameters with default values.

Events have been modified, so must been re-created again with new parameters. Basically, now events have as new parameters: ReasonCode and ReasonName which inform about packet state. And There is a new parameter with message properties.

Read more

 

Overview

Kraken WebSockets Public API offers real-time market data updates. WebSockets is a bidirectional protocol offering fastest real-time data, helping you build real-time applications. The message types presented below do not require authentication.

 

General Considerations

All messages sent and received via WebSockets are encoded in JSON format 

All floating point fields (including timestamps) are quoted to preserve precision. 

Format of each tradeable pair is A/B, where A and B are ISO 4217-A3 for standardized assets and popular unique symbol if not standardized. 

Timestamps should not be considered unique and not be considered as aliases for transaction ids. Also, the granularity of timestamps is not representative of transaction rates. 

 

Supported Pairs

ADA/CAD, ADA/ETH, ADA/EUR, ADA/USD, ADA/XBT, ATOM/CAD, ATOM/ETH, ATOM/EUR, ATOM/USD, ATOM/XBT, BCH/EUR, BCH/USD, BCH/XBT, DASH/EUR, DASH/USD, DASH/XBT, EOS/ETH, EOS/EUR, EOS/USD, EOS/XBT, GNO/ETH, GNO/EUR, GNO/USD, GNO/XBT, QTUM/CAD, QTUM/ETH, QTUM/EUR, QTUM/USD, QTUM/XBT, USDT/USD, ETC/ETH, ETC/XBT, ETC/EUR, ETC/USD, ETH/XBT, ETH/CAD, ETH/EUR, ETH/GBP, ETH/JPY, ETH/USD, LTC/XBT, LTC/EUR, LTC/USD, MLN/ETH, MLN/XBT, REP/ETH, REP/XBT, REP/EUR, REP/USD, STR/EUR, STR/USD, XBT/CAD, XBT/EUR, XBT/GBP, XBT/JPY, XBT/USD, BTC/CAD, BTC/EUR, BTC/GBP, BTC/JPY, BTC/USD, XDG/XBT, XLM/XBT, DOGE/XBT, STR/XBT, XLM/EUR, XLM/USD, XMR/XBT, XMR/EUR, XMR/USD, XRP/XBT, XRP/CAD, XRP/EUR, XRP/JPY, XRP/USD, ZEC/XBT, ZEC/EUR, ZEC/JPY, ZEC/USD, XTZ/CAD, XTZ/ETH, XTZ/EUR, XTZ/USD, XTZ/XBT

 

Methods

Ping

Client can ping server to determine whether connection is alive, server responds with pong. This is an application level ping as opposed to default ping in WebSockets standard which is server initiated

 

Ticker

Ticker information includes best ask and best bid prices, 24hr volume, last trade price, volume weighted average price, etc for a given currency pair. A ticker message is published every time a trade or a group of trade happens.

Subscribe to a ticker calling SubscribeTicker method:

SubscribeTicker(['XBT/USD']);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeTicker method:

UnSubscribeTicker(['XBT/USD']);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnKrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Ticker updates will be notified in OnKrakenData event.

 

 

OHLC

When subscribed for OHLC, a snapshot of the last valid candle (irrespective of the endtime) will be sent, followed by updates to the running candle. For example, if a subscription is made to 1 min candle and there have been no trades for 5 mins, a snapshot of the last 1 min candle from 5 mins ago will be published. The endtime can be used to determine that it is an old candle.

Subscribe to a OHLC calling SubscribeOHLC method, you must pass pair and interval.

SubscribeOHLC(['XBT/USD'], kin1min);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeOHLC method:

UnSubscribeOHLC(['XBT/USD'], kin1min);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnKrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

OHLC updates will be notified in OnKrakenData event.

  

Trade

Trade feed for a currency pair.

Subscribe to Trade feed calling SubscribeTrade method.

SubscribeTrade(['XBT/USD']);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeTrade method:

UnSubscribeTrade(['XBT/USD']);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Trade updates will be notified in OnKrakenData event.

 

 

Book

Order book levels. On subscription, a snapshot will be published at the specified depth, following the snapshot, level updates will be published.

Subscribe to a Book calling SubscribeBook method, you must pass pair and depth.

SubscribeBook(['XBT/USD'], kde10);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeBook method:

UnSubscribeBook(['XBT/USD'], kde10);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnKrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Book updates will be notified in OnKrakenData event.

 

 

Spread

Spread feed to show best bid and ask price for subscribed asset pair. Bid volume and ask volume is part of the message too.

Subscribe to Spread feed calling SubscribeSpread method.

SubscribeSpread(['XBT/USD']);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeSpread method:

UnSubscribeSpread(['XBT/USD']);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Spread updates will be notified in OnKrakenData event.

 

 

Other Methods

You can subscribe / unsubscribe to all channels with one method:

SubscribeAll(['XBT/USD']);

UnSubscribeAll(['XBT/USD']);

OHLC interval value is 1 if all channels subscribed.

 

Events

OnConnect: when websocket client is connected to client.

OnKrakenConnect: called after successful websocket connection and when server send system status.

OnKrakenSystemStatus: called when system status changes.

OnKrakenSubscribed: called after a successful subscription to a channel.

OnKrakenUnSubscribed: called after a successful unsubscription from a channel.

OnKranSubscriptionError: called if there is an error trying to subscribe / unsubscribe.

OnKrakenData: called every time a channel subscription has an update.

 

Recently, Quoine has changed websocket API, before that it was using pusher as library for websocket connections, now has moved to another host so pusher protocol doesn't works anymore.

In order to make to work again follow next steps:

1. Drop a TsgcWebSocketClient component and set URL to new websocket host:

    WSClient.URL := 'wss://tap.liquid.com/app/LIQUID?protocol=7&client=js&version=4.4.0&flash=false';

2. Server requires TLS 1.2, so configure client for this TLS version.

    WSClient.TLSOptions.Version := tls1_2;

3. Open a new connection, and OnConnect event, subscribe to channel

    procedure WSClientConnect(Connection: TsgcWSConnection);

    begin

      Connection.WriteData('{"event":"pusher:subscribe","data":{"channel":"price_ladders_cash_btcusd_sell"}}');

    end;

That's all, you will get updates in OnMessage event.

FXCM

From sgcWebSockets 4.2.4 FXCM WebSocket API is supported. FXCM, also known as Forex Capital Markets, is a retail broker for trading on the foreign exchange market. FXCM allows people to speculate on the foreign exchange market and provides trading in contract for difference (CFDs) on major indices and commodities such as gold and crude oil. It is based in London.

FXCM offers a web-based REST API which can be used to establish secure connectivity with FXCM’s trading systems for the purpose of receiving market data and trading.

FXCM sgcWebSockets component uses WebSocket (socket.io) and HTTP as transports to connect to a FXCM Servers.

Connection

To use the REST API, you will need:

  • Access Token generated with Trading Station Web https://tradingstation.fxcm.com/.

  • Select which API do you want connect: api-demo.fxcm.com or api.fxcm.com.

 

// ... create components

oClient := TsgcWebSocketClient.Create(nil);

oFXCM := TsgcWSAPI_FXCM.Create(nil);

oFXCM.Client := oClient;

 

// ... set properties FXCM

oFXCM.FXCM.AccessToken := 'here your access token';

oFXCM.FXCM.Host := 'api.fxcm.com';

oFXCM.FXCM.Port := 443;

oFXCM.FXCM.TLS := True;

 

// ... connect to server

oClient.Active := True;

 

Messages

Once authenticated against server, FXCM uses websocket to receive unsolicited messages like price updates and you can request data from server using HTTP methods.

 

oClient.OnMessage(Connection: TsgcWSConnection; const Text: string);

begin

  // ... here we receive all messages from server

end;

 

Methods

 

  • GetSymbols: Request a list of all available symbols.

  • SubscribeMarketData: After subscribing, market price updates will be pushed to the client via the socket.

  • SubscribeTradingTables: Subscribes to the updates of the data models. Update will be pushed to client via the socket. Type of update can be determined by "Model" Parameter.

  • SnapshotTradingTables: In case continuous updates of the trading tables is not needed, it is possible to request a one-time snapshot. Gets current content snapshot of the specified data models.

    • Model choices:

      • Offer

      • OpenPosition

      • ClosedPosition

      • Order

      • Summary

      • LeverageProfile

      • Account

      • Properties

  • UpdateSubscriptions: Offers table will show only symbols that we have subscribed to using update_subscriptions.

  • TradingOrder: allows to send open orders, modify, close...

  • GetHistoricalData: Allow user to retrieve candles for a given instrument at a given time frame. If time range is specified, number of candles parameter is ignored, but still required. There is a limit on the number of candles that can be returned in one request.

 sgcWebSockets SignalRCore component

From sgcWebSockets 4.2.2 SignalRCore WebSocket API is supported. ASP.NET Core SignalR is an open-source library that simplifies adding real-time web functionality to app.

 

Features

  • Handles initial handshake between server and client.
  • Supports 3 times of invocations: normal invocations, non-blocking invocations and streaming invocations.

  • Can cancel any stream invocation at any time.

  • Notify server about completion messages with result positive or negative.
  • Publish messages to all channel subscribers.

  • Keep Alive connections.

 

Read more about SignalRCore Client Component.

 sgcWebSockets API Bitmex components

From sgcWebSockets 4.2.0 Bitmex WebSocket API is supported. Bitmex is a cryptocurrency exchange and derivative trading platform.

 

Features

  • By default user is identified by a name, but this can be customized passing more data: email, company, twitter...

  • Events to Authorize if a Channel can be created, if a member is allowed...

  • Every time a new member joins a channel, all members are notified.
  • Publish messages to all channel subscribers.

 

 

If TLS is enabled by sgcWebSockets client, by default certificate server is accepted and not verified. If certificate verification is required, follow next steps:

 

1. Handle OnSSLAfterCreateHandler event on client component and enable verification:

 

procedure TfrmWebSocketClient.WSClientSSLAfterCreateHandler(Sender: TObject; aType: TwsSSLHandler; aSSLHandler: TIdSSLIOHandlerSocketBase);

begin

  TIdSSLIOHandlerSocketOpenSSL(aSSLHandler).SSLOptions.VerifyMode := [sslvrfPeer];

  TIdSSLIOHandlerSocketOpenSSL(aSSLHandler).OnVerifyPeer := OnVerifyPeerEvent

end;

 

2. Create a new method to access server certificate info and accept connection or not

 

function OnVerifyPeerEvent(Certificate: TIdX509; AOk: Boolean; ADepth, AError: Integer): Boolean;

begin

  // if certificate is valid

  AOk := True;

  // if not is valid

  AOk := False;

end;

From sgcWebSockets 4.1.10 AppRTC is supported using TsgcWSPServer_AppRTC component.

This protocol uses code from https://github.com/webrtc/apprtc and sgcWebSocket server as signaling server, so you can run your own server to allow Broadcast Audio and Video.

Online demo use viagenie STUN/TURN server, for production environment, is recommended to use own TURN/STURN servers.

AppRTC Online Demo

 sgcWebSockets API Cex components

From sgcWebSockets 4.1.10 CEX.IO WebSocket API is supported. CEX is a cryptocurrency exchange and former Bitcoin cloud mining provider.

WebSocket API allows getting real-time notifications without sending extra requests, making it a faster way to obtain data from the exchange

Cex component has a property called Cex where you can fill API Keys provided by Cex to get access to your account data.

 

Message encoding

All messages are encoded in JSON format.

Prices are presented as strings to avoid rounding errors at JSON parsing on client side

Compression of WebSocket frames is not supported by server.

Time is presented as integer UNIX timestamp in seconds.

 

Authentication

To get access to CEX.IO WebSocket data, you should be authorized.

 

Log in to CEX.IO account.

Go to https://cex.io/trade/profile#/api page.

Select type of required permissions.

Click "Generate Key" button and save your secret key, as it will become inaccessible after activation.

Activate your key.

 

Connectivity

 

If a connected Socket is inactive for 15 seconds, CEX.IO server will send a PING message.

Only server can be an Initiator of PING request.

Server sends ping only to authenticated user.

The user has to respond with a PONG message. Otherwise, the WebSocket will be DISCONNECTED. This is handled automatically by library.

For authenticated user, in case there is no notification or ping from server within 15 seconds, it would be safer to send a request like 'ticker' or 'get-balance' and receive response, in order to ensure connectivity and authentication.

 

 

Public Channels

These channels don't require to Authenticate before. Responses from server are received by OnCexMessage event. 

 

SubscribeTickers: Ticker feed with only price of transaction made on all pairs (deprecated)

 

{

    "e": "tick",

    "data": {

        "symbol1": "BTC",

        "symbol2": "USD",

        "price": "428.0123"

    }

}

 

SubscribeChart: OHLCV chart feeds with Open, High, Low, Close, Volume numbers (deprecated)

 

{

    'e': 'ohlcv24',

    'pair': 'BTC:USD',

    'data': [

        '418.2936',

        '420.277',

        '412.09',

        '416.9778',

        '201451078368'

    ]

}

 

Subscribe Pair: Market Depth feed (deprecated)

 

{

    'e': 'md_groupped', 

    'data': {

        'pair': 'BTC:USD',

        'id': 11296131,

        'sell': {

            '427.5000': 1000000,

            '480.0000': 263544334,

            ...

        },

        'buy': {

            '385.0000': 3630000,

            '390.0000': 1452458642,

            ... 400+ pairs togather with 'sell' pairs

        }

    }

}

 

Subscribe Pair: Order Book feed (deprecated)

 

{

    'e': 'md', 

    'data': {

        'pair': 'BTC:USD',

        'buy_total': 63221099,

        'sell_total': 112430315118,

        'id': 11296131,

        'sell': [

            [426.45, 10000000],

            [426.5, 66088429300],

            [427, 1000000],

            ... 50 pairs overaall

        ],

        'buy': [

            [423.3, 4130702],

            [423.2701, 10641168],

            [423.2671, 1000000],

            ... 50 pairs overaall

        ]

    }

}

 

Private Channels

To access this channels, first call Authenticate method. Responses from server are received by OnCexMessage event. 

 

GetTicker

 

{

    "e": "ticker",

    "data": {

        "timestamp": "1471427037",

        "low": "290",

        "high": "290",

        "last": "290",

        "volume": "0.02062068",

        "volume30d": "14.38062068",

        "bid": 240,

        "ask": 290,

        "pair": [

            "BTC",

            "USD"

        ]

    },

    "oid": "1471427036908_1_ticker",

    "ok": "ok"

}

 

GetBalance

 

{

    "e": "get-balance",

    "data": {

           "balance": {

            'LTC': '10.00000000', 

            'USD': '1024.00',

            'RUB': '35087.98', 

            'EUR': '217.53', 

            'GHS': '10.00000000',

            'BTC': '9.00000000'

        },

           "obalance": {

              'BTC': '0.12000000',

              'USD': "512.00",

           },

       },

       "time": 1435927928597

    "oid": "1435927928274_2_get-balance",

    "ok": "ok"

}

 

SubscribeOrderBook

 

{

"e": "order-book-subscibe",

"data": {

   "timestamp": 1435927929,

   "bids": [

      [

         241.947,

         155.91626

      ],

      [

         241,

         981.1255

      ],

   ],

   "asks": [

      [

         241.95,

         15.4613

      ],

      [

         241.99,

         17.3303

      ],

   ],

   "pair": "BTC:USD",

   "id": 67809

},

"oid": "1435927928274_5_order-book-subscribe",

"ok": "ok"

}

 

UnSubscribeOrderBook

 

{

"e": "order-book-unsubscribe",

"data": {

   "pair": "BTC:USD"

},

"oid": "1435927928274_4_order-book-unsubscribe",

"ok": "ok"

}

 

 

GetOpenOrders

 

{

"e": "open-orders",

"data": [

   {

      "id": "2477098",

      "time": "1435927928618",

      "type": "buy",

      "price": "241.9477",

      "amount": "0.02000000",

      "pending": "0.02000000"

   },

   {

      "id": "2477101",

      "time": "1435927928634",

      "type": "sell",

      "price": "241.9493",

      "amount": "0.02000000",

      "pending": "0.02000000"

   }

],

"oid": "1435927928274_9_open-orders",

"ok": "ok"

}

 

 

PlaceOrder

 

{

"e": "place-order",

"data": {

   "complete": false,

   "id": "2477098",

   "time": 1435927928618,

   "pending": "0.02000000",

   "amount": "0.02000000",

   "type": "buy",

   "price": "241.9477"

},

"oid": "1435927928274_7_place-order",

"ok": "ok"

}

 

 

CancelReplaceOrder

 

{

"e": "cancel-replace-order",

"data": {

   "complete": false,

   "id": "2689009",

   "time": 1443464955904,

   "pending": "0.04000000",

   "amount": "0.04000000",

   "type": "buy",

   "price": "243.25"

},

"oid": "1443464955209_16_cancel-replace-order",

"ok": "ok"

}

 

GetOrderRequest

 

In CEX.IO system, orders can be present in trade engine or in archive database. There can be time periods (~2 seconds or more), when order is done/canceled, but still not moved to archive database. That means, you cannot see it using calls: archived-orders/open-orders. This call allows to get order information in any case. Responses can have different format depending on orders location.

 

{

"e": "get-order",

"data": {

   "user": "XXX",

   "type": "buy",

   "symbol1": "BTC",

   "symbol2": "USD",

   "amount": "0.02000000",

   "remains": "0.02000000",

   "price": "50.75",

   "time": 1450214742160,

   "tradingFeeStrategy": "fixedFee",

   "tradingFeeBuy": "5",

   "tradingFeeSell": "5",

   "tradingFeeUserVolumeAmount": "nil",

   "a:USD:c": "1.08",

   "a:USD:s": "1.08",

   "a:USD:d": "0.00",

   "status": "a",

   "orderId": "5582060"

},

"oid": "1450214742135_10_get-order",

"ok": "ok"

}

 

CancelOrderRequest

 

{

"e": "cancel-order",

"data": {

   "order_id": "2477098"

   "time": 1443468122895

},

"oid": "1435927928274_12_cancel-order",

"ok": "ok"

}

 

GetArchivedOrders

 

{

"e": "archived-orders",

"data": [

   {

       "type": "buy",

       "symbol1": "BTC",

       "symbol2": "USD",

       "amount": 0,

       "amount2": 5000,

       "remains": 0,

       "time": "2015-04-17T10:46:27.971Z",

       "tradingFeeBuy": "2",

       "tradingFeeSell": "2",

       "ta:USD": "49.00",

       "fa:USD": "0.98",

       "orderId": "2340298",

       "status": "d",

       "a:BTC:cds": "0.18151851",

       "a:USD:cds": "50.00",

       "f:USD:cds": "0.98"

   },

   {

       "type": "buy",

       "symbol1": "BTC",

       "symbol2": "USD",

       "amount": 0,

       "amount2": 10000,

       "remains": 0,

       "time": "2015-04-08T15:46:04.651Z",

       "tradingFeeBuy": "2.99",

       "tradingFeeSell": "2.99",

       "ta:USD": "97.08",

       "fa:USD": "2.91",

       "orderId": "2265315",

       "status": "d",

       "a:BTC:cds": "0.39869578",

       "a:USD:cds": "100.00",

       "f:USD:cds": "2.91"

    }

],

"oid": "1435927928274    15_archived-orders",

"ok": "ok"

}

 

OpenPosition

 

{

    "e": "open-position",

    "oid": "1435927928274_7_open-position",

    "data": {   

        'amount': '1',

        'symbol': 'BTC',

        "pair": [

            "BTC",

            "USD"

        ],

        'leverage': '2',

        'ptype': 'long',

        'anySlippage': 'true',

        'eoprice': '650.3232',

        'stopLossPrice': '600.3232'

    }

}

 

GetPosition

 

{

  "e": "get_position",

  "ok": "ok",

  "data": {

    "user": "ud100036721",

    "pair": "BTC:USD",

    "amount": "1.00000000",

    "symbol": "BTC",

    "msymbol": "USD",

    "omamount": "1528.77",

    "lsymbol": "USD",

    "lamount": "3057.53",

    "slamount": "3380.11",

    "leverage": "3",

    "stopLossPrice": "3380.1031",

    "dfl": "3380.10310000",

    "flPrice": "3057.53333333",

    "otime": 1513002370342,

    "psymbol": "BTC",

    "ptype": "long",

    "ofee": "10",

    "pfee": "10",

    "cfee": "10",

    "tfeeAmount": "152.88",

    "rinterval": "14400000",

    "okind": "Manual",

    "a:BTC:c": "1.00000000",

    "a:BTC:s": "1.00000000",

    "oorder": "89101551",

    "pamount": "1.00000000",

    "lremains": "3057.53",

    "slremains": "3380.11",

    "oprice": "4586.3000",

    "status": "a",

    "id": "125531",

    "a:USD:cds": "4739.18"

  }

}

 

GetOpenPositions

 

{

    'e': 'open_positions',

    "oid": "1435927928256_7_open-positions",

    'ok': 'ok',

    'data': [

        {

            'user': 'ud100036721',

            'id': '104102',

            'otime': 1475602208467,

            'symbol': 'BTC',

            'amount': '1.00000000',

            'leverage': '2',

            'ptype': 'long',

            'psymbol': 'BTC',

            'msymbol': 'USD',

            'lsymbol': 'USD',

            'pair': 'BTC:USD',

            'oprice': '607.5000'

            'stopLossPrice': '520.3232',

            'ofee': '1',

            'pfee': '3',

            'cfee': '4',

            'tfeeAmount': '3.04',

            'pamount': '1.00000000',

            'omamount': '303.75',

            'lamount': '303.75',

            'oorder': '34106774',            

            'rinterval': '14400000',

            'dfl': '520.32320000',

            'slamount': '520.33',

            'slremains': '520.33',

            'lremains': '303.75',

            'flPrice': '303.75000000',

            'a:BTC:c': '1.00000000',

            'a:BTC:s': '1.00000000',

            'a:USD:cds': '610.54',

        },

        ...

    ]

}

 

ClosePosition

 

{   

    'e': 'close_position',

    "oid": "1435927928364_7_close-position",

    'ok': 'ok',

    'data': {

        'id': 104034,

        'ctime': 1475484981063,

        'ptype': 'long',

        'msymbol': 'USD'

        'pair': {

            'symbol1': 'BTC',

            'symbol2': 'USD'

        }

        'price': '607.1700',

        'profit': '-12.48',

    }

}

 

 sgcWebSockets API Huobi components

From sgcWebSockets 4.1.9 Huobi WebSocket API is supported.

Huobi is an international multi-language cryptocurrency exchange.

 

Methods

 SubscribeKLine

   K line data, including the opening price, closing price, highest price, lowest price, volume, turnover, number of transactions, etc. per unit time interval $period Optional values: { 1min, 5min, 15min, 30min, 60min, 4hour ,1day, 1mon, 1week, 1year }

 

{

  "status": "ok",

  "rep": "market.btcusdt.kline.1min",

  "tick": [

    {

      "amount": 1.6206,

      "count":  3,

      "id":     1494465840,

      "open":   9887.00,

      "close":  9885.00,

      "low":    9885.00,

      "high":   9887.00,

      "vol":    16021.632026

    },

    {

      "amount": 2.2124,

      "count":  6,

      "id":     1494465900,

      "open":   9885.00,

      "close":  9880.00,

      "low":    9880.00,

      "high":   9885.00,

      "vol":    21859.023500

    }

  ]

}

 

 

  SubscribeMarketDepth

  Handbook depth, according to different step aggregation, buy one, buy two, buy three, and sell one, sell two, sell three, etc. type Optional value: { step0, step1, step2, step3, step4, step5, percent10 } (combination depth 0-5); when step0, no depth is merged

 

{

  "ch": "market.btcusdt.depth.step0",

  "ts": 1489474082831,

  "tick": {

    "bids": [

    [9999.3900,0.0098], // [price, amount]

    [9992.5947,0.0560],

    // more Market Depth data here

    ]

    "asks": [

    [10010.9800,0.0099]

    [10011.3900,2.0000]

    //more data here

    ]

  }

}

 

 

  SubscribeTradeDetail

  Transaction record, including transaction price, volume, direction of transaction, etc.

 

{

  "ch": "market.btcusdt.trade.detail",

  "ts": 1489474082831,

  "tick": {

        "id": 14650745135,

        "ts": 1533265950234,

        "data": [

            {

                "amount": 0.0099,

                "ts": 1533265950234,

                "id": 146507451359183894799,

                "price": 401.74,

                "direction": "buy"

            },

            // more Trade Detail data here

        ]

    }

  

  ]

  }

}

  

  SubscribeMarketDetail

  Last 24 hours of volume, turnover, opening price, closing price, highest price, lowest price, number of transactions, etc.

 

{

  "rep": "market.btcusdt.detail",

  "status": "ok",

  "id": "id12",

  "tick": {

    "amount": 12224.2922,

    "open":   9790.52,

    "close":  10195.00,

    "high":   10300.00,

    "ts":     1494496390000,

    "id":     1494496390,

    "count":  15195,

    "low":    9657.00,

    "vol":    121906001.754751

  }

}

  

  SubscribeMarketTickers

  Information on the daily K line, the last 24 hours of trading, etc.

 

 sgcWebSockets API Binance components

From sgcWebSockets 4.1.8 BinanceWebSocket API is supported.

Binance is an international multi-language cryptocurrency exchange.

 

Properties

  Streams: contains list of streams.

 

Methods

  AddAggregateTrades

    The Aggregate Trade Streams push trade information that is aggregated for a single taker order.

{

  "e": "aggTrade",  // Event type

  "E": 123456789,   // Event time

  "s": "BNBBTC",    // Symbol

  "a": 12345,       // Aggregate trade ID

  "p": "0.001",     // Price

  "q": "100",       // Quantity

  "f": 100,         // First trade ID

  "l": 105,         // Last trade ID

  "T": 123456785,   // Trade time

  "m": true,        // Is the buyer the market maker?

  "M": true         // Ignore.

}

 

  AddTrades

    The Trade Streams push raw trade information; each trade has a unique buyer and seller.

{

  "e": "trade",     // Event type

  "E": 123456789,   // Event time

  "s": "BNBBTC",    // Symbol

  "t": 12345,       // Trade ID

  "p": "0.001",     // Price

  "q": "100",       // Quantity

  "b": 88,          // Buyer order Id

  "a": 50,          // Seller order Id

  "T": 123456785,   // Trade time

  "m": true,        // Is the buyer the market maker?

  "M": true         // Ignore.

}

 

  AddKline

    The Kline/Candlestick Stream push updates to the current klines/candlestick every second.

{

  "e": "kline",     // Event type

  "E": 123456789,   // Event time

  "s": "BNBBTC",    // Symbol

  "k": {

    "t": 123400000, // Kline start time

    "T": 123460000, // Kline close time

    "s": "BNBBTC",  // Symbol

    "i": "1m",      // Interval

    "f": 100,       // First trade ID

    "L": 200,       // Last trade ID

    "o": "0.0010",  // Open price

    "c": "0.0020",  // Close price

    "h": "0.0025",  // High price

    "l": "0.0015",  // Low price

    "v": "1000",    // Base asset volume

    "n": 100,       // Number of trades

    "x": false,     // Is this kline closed?

    "q": "1.0000",  // Quote asset volume

    "V": "500",     // Taker buy base asset volume

    "Q": "0.500",   // Taker buy quote asset volume

    "B": "123456"   // Ignore

  }

}

 

  AddTicker

    24hr Ticker statistics for a single symbol pushed every second

{

  "e": "24hrTicker",  // Event type

  "E": 123456789,     // Event time

  "s": "BNBBTC",      // Symbol

  "p": "0.0015",      // Price change

  "P": "250.00",      // Price change percent

  "w": "0.0018",      // Weighted average price

  "x": "0.0009",      // Previous day's close price

  "c": "0.0025",      // Current day's close price

  "Q": "10",          // Close trade's quantity

  "b": "0.0024",      // Best bid price

  "B": "10",          // Best bid quantity

  "a": "0.0026",      // Best ask price

  "A": "100",         // Best ask quantity

  "o": "0.0010",      // Open price

  "h": "0.0025",      // High price

  "l": "0.0010",      // Low price

  "v": "10000",       // Total traded base asset volume

  "q": "18",          // Total traded quote asset volume

  "O": 0,             // Statistics open time

  "C": 86400000,      // Statistics close time

  "F": 0,             // First trade ID

  "L": 18150,         // Last trade Id

  "n": 18151          // Total number of trades

}

 

 

  AddAllMarketTickers

    24hr Ticker statistics for all symbols in an array pushed every second

[

  {

    // Same as <symbol>@ticker payload

  }

]

 

  AddPartialBookDepth

    Top <levels> bids and asks, pushed every second. Valid <levels> are 5, 10, or 20.

{

  "lastUpdateId": 160,  // Last update ID

  "bids": [             // Bids to be updated

    [

      "0.0024",         // price level to be updated

      "10",             // quantity

      []                // ignore

    ]

  ],

  "asks": [             // Asks to be updated

    [

      "0.0026",         // price level to be updated

      "100",            // quantity

      []                // ignore

    ]

  ]

}

 

  AddDiffDepth

    Order book price and quantity depth updates used to locally manage an order book pushed every second.

{

  "e": "depthUpdate", // Event type

  "E": 123456789,     // Event time

  "s": "BNBBTC",      // Symbol

  "U": 157,           // First update ID in event

  "u": 160,           // Final update ID in event

  "b": [              // Bids to be updated

    [

      "0.0024",       // price level to be updated

      "10",

      []              // ignore

    ]

  ],

  "a": [              // Asks to be updated

    [

      "0.0026",       // price level to be updated

      "100",          // quantity

      []              // ignore

    ]

  ]

}