Poloniex – API Documentation
Knot.js example of how to connect to the thrust API (requires autobahn): http://pastebin.com/dMX7mZE0
The best way to get public data updates on markets is via the shove API, which shoves live ticker, order book, trade, and Trollbox updates over WebSockets using the WAMP protocol. In order to use the shove API, connect to wss://api.poloniex.com and subscribe to the desired feed.
In order to receive ticker updates, subscribe to “ticker”. Updates will be in the following format:
Adequate labels for these data are, in order: currencyPair, last, lowestAsk, highestBid, percentChange, baseVolume, quoteVolume, isFrozen, 24hrHigh, 24hrLow
Order Book and Trades
To receive order book and trade updates, subscribe to the desired currencyPair, e.g. “BTC_XMR”. There are two types of order book updates:
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 &mdash, in other words, it substitutes any previous value, rather than indicates an adjustment to a previous value.
Trade history updates are provided in the following format:
The dictionary portion of each market message (“kwargs” in the Knot.js example) will contain a sequence number with the key “seq”. 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. In some markets, if there is no update for more than 1 2nd, a heartbeat message consisting of an empty argument list and the latest sequence number will be sent. These will go out once per 2nd, but if there is no update for more than 60 seconds, the heartbeat interval will be diminished to 8 seconds until the next update.
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.
In order to receive fresh Trollbox messages, subscribe to “trollbox”. Messages will be given in the following format:
Adequate labels for these data are, in order: type, messageNumber, username, message, reputation
Public API Methods
Please note that making more than 6 calls per 2nd to the public API, or repeatedly and needlessly fetching excessive amounts of data, can result in your IP being banned.
There are six public methods, all of which take HTTP GET requests and come back output in JSON format:
Comes back the ticker for all markets. Sample output:
Comebacks the 24-hour volume for all markets, plus totals for primary currencies. Sample output:
Comes back the order book for a given market, as well as a sequence number for use with the Thrust API and an indicator specifying whether the market is frozen. You may set currencyPair to ",all", to get the order books of all markets. Sample output:
Or, for all markets:
Comebacks the past 200 trades for a given market, or up to 50,000 trades inbetween a range specified in UNIX timestamps by the ",begin", and ",end", GET parameters. Sample output:
Comes back candlestick chart data. Required GET parameters are “currencyPair”, “period” (candlestick period in seconds, valid values are 300, 900, 1800, 7200, 14400, and 86400), “embark”, and “end”. “Commence” and “end” are given in UNIX timestamp format and used to specify the date range for the data returned. Sample output:
Comebacks information about currencies. Sample output:
Comebacks the list of loan offers and requests for a given currency, specified by the “currency” GET parameter. Sample output:
Trading API Methods
To use the trading API, you will need to create an API key.
Please note that there is a default limit of 6 calls per 2nd. If you require more than this, please consider optimizing your application using the thrust API, the “moveOrder” directive, or the “all” parameter where adequate. If this is still insufficient, please contact support to discuss a limit raise.
All calls to the trading API are sent via HTTP POST to https://poloniex.com/tradingApi and must contain the following headers:
- Key – Your API key.
- Sign – The query’s POST data signed by your key’s “secret” according to the HMAC-SHA512 method.
Additionally, all queries must include a “nonce” POST parameter. The nonce parameter is an integer which must always be greater than the previous nonce used.
All responses from the trading API are in JSON format. In the event of an error, the response will always be of the following format:
There are several methods accepted by the trading API, each of which is specified by the “guideline” POST parameter:
Comes back all of your available balances. Sample output:
Comes back all of your balances, including available balance, balance on orders, and the estimated BTC value of your balance. By default, this call is limited to your exchange account, set the “account” POST parameter to “all” to include your margin and lending accounts. Sample output:
Comes back all of your deposit addresses. Sample output:
Generates a fresh deposit address for the currency specified by the “currency” POST parameter. Sample output:
Only one address per currency per day may be generated, and a fresh address may not be generated before the previously-generated one has been used.
Comes back your deposit and withdrawal history within a range, specified by the “begin” and “end” POST parameters, both of which should be given as UNIX timestamps. Sample output:
Comes back your open orders for a given market, specified by the “currencyPair” POST parameter, e.g. “BTC_XCP”. Set “currencyPair” to “all” to come back open orders for all markets. Sample output for single market:
Or, for all markets:
Comebacks your trade history for a given market, specified by the “currencyPair” POST parameter. You may specify “all” as the currencyPair to receive your trade history for all markets. You may optionally specify a range via “embark” and/or “end” POST parameters, given in UNIX timestamp format, if you do not specify a range, it will be limited to one day. You may optionally limit the number of entries returned using the “limit” parameter, up to a maximum of Ten,000. If the “limit” parameter is not specified, no more than 500 entries will be returned. Sample output:
Or, for all markets:
Comebacks all trades involving a given order, specified by the “orderNumber” POST parameter. If no trades for the order have occurred or you specify an order that does not belong to you, you will receive an error. Sample output:
Places a limit buy order in a given market. Required POST parameters are “currencyPair”, “rate”, and “amount”. If successful, the method will come back the order number. Sample output:
You may optionally set “fillOrKill”, “immediateOrCancel”, “postOnly” to 1. A fill-or-kill order will either pack in its entirety or be entirely aborted. An immediate-or-cancel order can be partially or entirely packed, but any portion of the order that cannot be packed instantaneously will be canceled rather than left on the order book. A post-only order will only be placed if no portion of it fills instantly, this assures you will never pay the taker fee on any part of the order that fills.
Places a sell order in a given market. Parameters and output are the same as for the buy method.
Cancels an order you have placed in a given market. Required POST parameter is “orderNumber”. If successful, the method will comeback:
Cancels an order and places a fresh one of the same type in a single atomic transaction, meaning either both operations will succeed or both will fail. Required POST parameters are “orderNumber” and “rate”, you may optionally specify “amount” if you wish to switch the amount of the fresh order. “postOnly” or “immediateOrCancel” may be specified for exchange orders, but will have no effect on margin orders. Sample output:
Instantaneously places a withdrawal for a given currency, with no email confirmation. In order to use this method, the withdrawal privilege must be enabled for your API key. Required POST parameters are “currency”, “amount”, and “address”. For XMR withdrawals, you may optionally specify “paymentId”. Sample output:
If you are enrolled in the maker-taker fee schedule, comebacks your current trading fees and trailing 30-day volume in BTC. This information is updated once every 24 hours.
Comes back your balances sorted by account. You may optionally specify the “account” POST parameter if you wish to fetch only the balances of one account. Please note that balances in your margin account may not be accessible if you have any open margin positions or orders. Sample output:
Comebacks your current tradable balances for each currency in each market for which margin trading is enabled. Please note that these balances may vary continually with market conditions. Sample output:
Transfers funds from one account to another (e.g. from your exchange account to your margin account). Required POST parameters are “currency”, “amount”, “fromAccount”, and “toAccount”. Sample output:
Comes back a summary of your entire margin account. This is the same information you will find in the Margin Account section of the Margin Trading page, under the Markets list. Sample output:
Places a margin buy order in a given market. Required POST parameters are “currencyPair”, “rate”, and “amount”. You may optionally specify a maximum lending rate using the “lendingRate” parameter. If successful, the method will comeback the order number and any trades instantaneously resulting from your order. Sample output:
Places a margin sell order in a given market. Parameters and output are the same as for the marginBuy method.
Comebacks information about your margin position in a given market, specified by the “currencyPair” POST parameter. You may set “currencyPair” to “all” if you wish to fetch all of your margin positions at once. If you have no margin position in the specified market, “type” will be set to “none”. “liquidationPrice” is an estimate, and does not necessarily represent the price at which an actual compelled liquidation will occur. If you have no liquidation price, the value will be -1. Sample output:
Closes your margin position in a given market (specified by the “currencyPair” POST parameter) using a market order. This call will also come back success if you do not have an open position in the specified market. Sample output:
Creates a loan suggest for a given currency. Required POST parameters are “currency”, “amount”, “duration”, “autoRenew” (0 or 1), and “lendingRate”. Sample output:
Cancels a loan suggest specified by the “orderNumber” POST parameter. Sample output:
Comes back your open loan offers for each currency. Sample output:
Comes back your active loans for each currency. Sample output:
Comes back your lending history within a time range specified by the “commence” and “end” POST parameters as UNIX timestamps. “limit” may also be specified to limit the number of rows returned. Sample output:
Toggles the autoRenew setting on an active loan, specified by the “orderNumber” POST parameter. If successful, “message” will indicate the fresh autoRenew setting. Sample output:
©, Poloniex, Inc. 2017 – Wilmington, DE, USA