Poloniex api help
poloniex-api-node is a elementary knot.js wrapper for Poloniex REST and WebSocket API.
REST API supports both Callback and Promise.
WebSocket API supports both the WAMP protocol (v1) and the fresh WebSocket API (v2).
The legacy WAMP shove API (v1) is presently the WebSocket API officially documented. Lately, it is not stable and Poloniex servers are not treating the API decently due high blast.
The fresh WebSocket API (v2) is not yet officially documented, however its functionality is much swifter and reliable. WebSocket API (v2) is also internally used by Poloniex.
- Quick examples
- REST API
- WebSocket API (version 1 and version Two)
See extra examples in examples folder
When calling the REST API methods, Callback is always the last parameter. When callback parameter is not present, the method will comeback a Promise.
Example 1 (REST API using Callback):
Example Two (REST API using Callback):
Example Trio (REST API using Promise):
Example Four (set socketTimeout to 15 seconds):
Example (WebSocket API):
To access the private Poloniex API methods you must supply your API key id and key secret as the very first two arguments. If you are only accessing the public API endpoints you can leave these two arguments out.
- socketTimeout – the number of milliseconds to wait for the server to send the response before aborting the request
- keepAlive – keep open and reuse the underlying TCP connection
For details about the API endpoints see total documentation at https://poloniex.com/support/api/
Significant: When calling an API method with optional parameters, the parameters, when not dreamed, need to be passed as null .
Both Callback and Promise are supported.
Callback is always the last parameter. When callback parameter is not present the method will come back a Promise.
The arguments passed to the callback function for each method are:
- An error or null if no error occurred.
- An object containing the data returned by the Poloniex API.
Parameter depth is not documented in the official Poloniex API documentation. The parameter can be set to null or an integer value.
Parameter limit is not documented in the official Poloniex API documentation. The parameter can be set to null or an integer value.
This module implements both the legacy WAMP thrust API (v1) and the fresh WebSocket API (v2).
Albeit the module facilitates the usage of v1 and v2 in a similar way, Poloniex implementation is downright different.
The legacy WAMP thrust API (v1) is presently the WebSocket API officially documented. Lately, it is not stable and Poloniex servers are not treating the API decently due high fountain.
The fresh WebSocket API (v2) is not yet officially documented, however its functionality is much quicker and reliable. WebSocket API (v2) is also internally used by Poloniex.
A listener is registered using the Poloniex.on() method (since Poloniex class inherits the EventEmitter ) and the listener will be invoked every time the named event is emitted.
The following events can be emitted:
Emitted when WebSocket connection is established.
Emitted when an update on a subscribed channel is received. See method subscribe for details on data received and its format.
Emitted when WebSocket connection is closed. See method closeWebSocket for details on data received and its format.
Emitted when an error occurs.
Significant: You have to set error listener otherwise your app will throw an Error and exit if error event will occur (see: Knot.js Error events)
Emitted if there is no update for more than 60 seconds
Opens WebSocket connection to Poloniex server. If WebSocket connection is already open and openWebSocket is called again, the existing connection is closed and a fresh one is opened (equivalent to a total reset of the WebSocket connection).
Event ‘open’ is emitted when connection is established.
To use the fresh WebSocket API (v2), pass parameter option as
In order to receive updates over WebSocket, subscribe to following channels:
When an update on the subscribed channel is received Poloniex object emits the event ‘message’ .
You can subscribe to a channel either before or after the WebSocket connection is opened with openWebSocket . If WebSocket connection is already open, the subscription is activated instantly. If WebSocket connection is not open yet, the subscribe is registering the subscription, all registered connections will be activated when openWebSocket is issued.
Provides ticker updates.
Ticker updates will be in following format:
Provides order book and trade updates. Subscribe to the desired currencyPair, e.g. ‘BTC_ETC’ , to receive order book and trade updates.
There are four types of messages (described below)
Provides a snapshot of the order book for the subscribed currency pair. The message is emited imediatelly after subscription to the currency pair is activated.
The data for orderBook snapshot is provided in the following format:
This message type is only valid for the fresh WebSocket API (v2). When WAMP API (v1) is used, the orderBook snapshot has to be retrieved using REST API method returnOrderBook .
There are two types of order book updates orderBookModify and orderBookRemove , provided in the following formats:
Updates of type orderBookModify can be either additions to the order book or switches to existing entries. The value of amount indicates the fresh total amount on the books at the given rate — in other words, it substitutes any previous value, rather than indicates an adjustment to a previous value.
Each message event will pass the parameter seq , indicating the a sequence number. In order to keep your order book consistent, you will need to ensure that messages are applied in the order of their sequence numbers, even if they arrive out of order.
Several order book and trade history updates will often arrive in a single message. Be sure to loop through the entire array, otherwise you will miss some updates.
Trade history updates are provided in the following format:
Significant: Several order book and trade history updates will often arrive in a single message. Be sure to loop through the entire array, otherwise you will miss some updates.
Provides other info updates.
The updates will be in following format:
Channel ‘footer’ is not documented in the official Poloniex API documentation.
Unsubscribes a previously established channel subscription. Once unsubscribed there will be no more channel updates received.
Closes WebSocket connection previously opened. Event ‘close’ is emitted when connection closes.