WebSocket is a TCP-based full-duplex communication protocol. Full-duplex means that both parties can send each other messages asynchronously using the same communication channel. This section describes which messages should Exchange Plus and Client send each other. All messages should be valid JSON objects.
WebSocket API is mostly used to obtain information or do actions which are not available or not easy to do using REST API. However, some requests or actions are possible to do in both REST API and WebSocket API. Exchange Plus sends messages to Client as a response to request previously sent by Client, or as a notification about some event (without prior Client’s request).
Public API Calls
Public API rate limit is implied in order to protect the system from DDoS attacks and ensuring all Clients can have same level of stable access to Exchange Plus API endpoints. Public requests are limited by IP address from which public API requests are made. Request limits are determined from cost associated with each public API call. By default, each public request has a cost of 1 point, but for some specific requests this cost can be higher. See up-to-date request rate limit cost information in specification of each method.
Exchange Plus limits Public API calls to maximum of 100 points per minute, considering that each Public API call has its' cost (see below). If request rate limit is reached then Exchange Plus replies with error, sends disconnected event to Client and closes WS connection afterwards. Exchange Plus will continue to serve Client starting from the next calendar minute. In the following example, request counter will be reset at 11:02:00.000.
Method | Description |
GetTicker | This method is designed to obtain current information about Ticker, including data about current prices, 24h price & volume changes, last trade event etc. of certain assets. |
GetOrderBook | This method allows Client to receive current order book snapshot for specific trading pair. |
GetCandles | By using Candles method Client can receive historical OHLCV candles of different resolutions and data types. Client can indicate additional timeframe and limit filters to make response more precise to Client’s requirements. |
GetTradeHistory | This method allows Client to obtain historical data as to occurred trades upon requested trading pair. Client can supplement Trade History request with additional filter parameters, such as timeframe period, tradeIds range, side etc. to receive trades which match request parameters. |
GetServerTime | This method is used to get the current time on Exchange Plus server. It can be useful for applications that have to be synchronized with the server's time. |
GetPairsInfo | Pair Info method allows Client to receive the parameters for all supported trading pairs. |
GetCurrenciesInfo | Currencies Info method allows Client to receive the parameters for all currencies configured in Exchange Plus as well as the deposit and withdrawal availability between Exchange Plus and CEX.IO Wallet. |
GetProcessingInfo | This request allows Client to receive detailed information about available options to make deposits from external wallets and withdrawals to external wallets as to each supported cryptocurrency, including cryptocurrency name and available blockchains for deposit\withdrawals. Also, as to each supported blockchain there are indicated type of cryptocurrency on indicated blockchain, current deposit\withdrawal availability, minimum amounts for deposits\withdrawals, external withdrawal fees. Processing Information makes Client more flexible in choosing desired blockchain for receiving Deposit address and initiating external withdrawals via certain blockchain, so that Client uses more convenient way of transferring his crypto assets to or from CEX.IO Ecosystem. |
SubscribeOrderBook | Client by subscribing via WebSocket can subscribe to order book feed upon requested trading pair. In response to Order Book Subscribe request Client will receive current (initial) order book snapshot for requested pair with indicated seqId number. To track following updates to Order Book Client needs to subscribe via WebSocket to “order_book_increment“ messages, which would contain trading pair name, seqId number, Bids and Asks price levels deltas. |
UnSubscribeOrderBook | UnSubscribe from the order book channel. |
SubscribeTrade | By using the Trade Subscribe method Client can subscribe via WebSocket to live feed of trade events which occur on requested trading pair. In response to Trade Subscribe request Client will receive a unique identifier of trade subscription which should further be used for unsubscription when trade subscription is not longer needed for Client. Client should subscribe via WebSocket to “tradeHistorySnapshot” and “tradeUpdate” messages to receive initial and periodical Trade History snapshots, and live trade events for requested trading pair. |
UnSubscribeTrade | UnSubscribe from the trade channel. |
Example: get the latest ticker of BTC-USD pair
oClient := TsgcWebSocketClient.Create(nil);
oCexPlus := TsgcWSAPI_CexPlus.Create(nil);
oCexPlus.Client := oClient;
oCexPlus.OnCexPlusConnect := OnCexPlusConnectEvent;
oCexPlus.OnCexPlusMessage := OnCexPlusMessageEvent;
oClient.Active := True;
procedure OnCexPlusConnectEvent(Sender: TObject);
begin
oCexPlus.GetTicker('BTC-USD');
end;
procedure OnCexPlusMessageEvent(Sender: TObject; Event, Msg: string);
begin
ShowMessage('Ticker data: ' + Msg);
end;
Private API Calls
Exchange Plus uses API keys to allow access to Private APIs.
Client can generate, configure and manage api keys, set permission levels, whitelisted IPs for API key etc. via Exchange Plus Web Terminal in the API Keys Management Profile section.
API Keys limit: By default Client can have up to 5 API Keys.
To restrict access to certain functionality while using of API Keys there should be defined specific set of permissions for each API Key. The defined set of permissions can be edited further if necessary.
The following permission levels are available for API Keys:
Method | Description |
GetCurrentFee | This method indicates current fees at specific moment of time with consideration of Client' up-to-date 30d volume and day of week (fees can be different for e.g. on weekends). |
GetFeeStrategy | Fee Strategy returns all fee options, which could be applied for Client, considering Client’s trading volume, day of week, pairs, group of pairs etc. This method provides information about general fee strategy, which includes all possible trading fee values that can be applied for Client. To receive current trading fees, based on Client's current 30d trading volume, Client should use [Current Fee] method. To receive current 30d trading volume, Client should use [Volume] method. |
GetVolume | This request allows Client to receive his trading volume for the last 30 days in USD equivalent. |
CreateAccount | This request allows Client to create new sub-account. By default Client can have up to 5 sub-accounts, including main account. |
GetAccountStatus | By using Account Status V3 method, Client can find out current balance and it’s indicative equivalent in converted currency (by default “USD”), amounts locked in open (active) orders as to each sub-account and currency. If trading fee balance is available for Client, then response will also contain general trading fee balance data such as promo name, currency name, total balance and expiration date of this promo on Trading Fee Balance. It’s Client’s responsibility to track his sub-accounts available trading balance as current sub-account balance reduced by the balance amount locked in open (active) orders on sub-account. |
GetOrders | This request allows Client to find out info about his orders. |
NewOrder | Client can place new orders via WebSocket API by using Do My New Order Request. Along with a response to this request, Exchange Plus sends Account Event and Execution Report messages to Client if the request is successful. Response message indicates the last up-to-date status of order which is available in the system at the moment of sending the response. If the Client did not receive a Response message to Do My New Order Request - the Client can query current status of the order by using Get My Orders Request with clientOrderId parameter. When sending a request for new order, it is highly recommended to use clientOrderId parameter which corresponds to the specific new order request on the client’s side. Exchange Plus avoids multiple placing the orders with the same clientOrderId. If more than one new orders with identical clientOrderId and other order parameters are identified - Exchange Plus places only the first order and returns the status of such order to the Client in response to the second and subsequent new order requests with the same parameters. If more than one new orders with identical clientOrderId but with different other order parameters are identified - Exchange Plus processes only the first order and rejects the second and subsequent new order requests with the same clientOrderID but with different other order parameters. |
NewMarketOrder | Places a new market order. |
NewLimitOrder | Places a new limit order. |
CancelOrder | Client can cancel orders. Along with a response to this request, Exchange Plus sends Account Event and Execution Report messages to Client if this request is successful. Also, if request to cancel an order is declined, Exchange Plus sends Order Cancellation Rejection message. |
CancelAllOrders | Client can cancel all open orders via WebSocket API. Along with a response to this request Exchange Plus will start cancellation process for all open orders and send corresponding Account Event and Execution Report messages to the Client. |
GetTransactionHistory | This request allows Client to find out his financial transactions (deposits, withdrawals, internal transfers, commissions or trades). |
GetFundingHistory | This request allows Client to find his deposit and withdrawal transactions. |
InternalTransfer | Client can request to transfer money between his sub-accounts or between his main account and sub-account. Exchange Plus does not charge Client any commission for transferring funds between his accounts. Along with a response to this request, Exchange Plus sends Account Event messages to Client if this request is successful. |
GetDepositAddress | This method can be used by Client for receiving a crypto address to deposit cryptocurrency. Deposit address can be generated for main and sub-accounts. The list of available blockchains for generating deposit address can be received by Client via Get Processing Info request. |
FundsDepositFromWallet | Client can deposit funds from CEX.IO Wallet to Exchange Plus account. The system avoids processing of multiple deposit requests with the same clientTxId. If multiple deposit requests with identical clientTxId are received - the system processes only the first deposit request and rejects the second and subsequent deposit requests with the same clientTxId. |
FundsWithdrawalToWallet | Client can withdraw funds from Exchange Plus account to CEX.IO Wallet. The system avoids multiple withdrawal requests with the same clientTxId. If multiple withdrawal requests with identical clientTxId are received - the system processes only the first withdrawal request and rejects the second and subsequent withdrawal requests with the same clientTxId. |
Example: get the orders.
oClient := TsgcWebSocketClient.Create(nil);
oCexPlus := TsgcWSAPI_CexPlus.Create(nil);
oCexPlus.Client := oClient;
oCexPlus.CexPlus.ApiKey := 'your-api-key';
oCexPlus.CexPlus.ApiSecret := 'your-api-secret';
oCexPlus.OnCexPlusAuthenticated := OnCexPlusAuthenticatedEvent;
oCexPlus.OnCexPlusMessage := OnCexPlusMessageEvent;
oClient.Active := True;
procedure OnCexPlusAuthenticatedEvent(Sender: TObject);
begin
oCexPlus.GetOrders();
end;
procedure OnCexPlusMessageEvent(Sender: TObject; Event, Msg: string);
begin
ShowMessage('Orders: ' + Msg);
end;