Here we have a non-official module to use the Poloniex Exchange API with python 3. Any questions about the API check out the official documentation at https://docs.poloniex.com/#introduction. Our code uses aiohttp and asyncio libraries in order to interact with the exchange server.
Poloniex provides both HTTP and websocket APIs for interacting with the exchange. Both allow read access to public market data and private read access to your account. Private write access to your account is available via the private HTTP API.
The public HTTP endpoint is accessed via GET
requests while the private endpoint is accessed via HMAC-SHA512
signed POST
requests using API keys. Both types of HTTP endpoints return results in JSON
format.
The websocket API allows push notifications about the public order books, lend books and your private account. Similarly to the HTTP API, it requires HMAC-SHA512
signed requests using API keys for requests related to your private account.
It is recommended to touch a key.py
that contains your Poloniex credentials as follows:
apikey = 'PASTE_YOUR_API_KEY_HERE'
secret = 'PASTE_YOUR_SECRET_HERE'
Importing the Poloniex class in your code:
from poloniex_api import poloniex
import key
The 'poloniex' class is the object that connects you to Poloniex's server as a client. Its initial parameters are your credentials in exchange: apikey
and secret
.
First of all make the following client assignment:
client = poloniex(key.apikey, key.secret)
Any method is called following the format:
client.NAME_OF_THE_METHOD()
From now on we have all the methods described, exemplified, and ordered as the summary:
These methods work without signature, i.e. the Poloniex credentials are NOT mandatory.
- The base endpoint is: https://poloniex.com/public
- Endpoint returns JSON object.
- All methods can return either JSON object, or array, or float.
Retrieves summary information for each symbol
listed on the exchange.
Parameter | Mandatory |
---|---|
symbol | No |
field | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. field
can be filled withid
,last
,lowestAsk
,highestBid
,percentChange
,baseVolume
,quoteVolume
,isFrozen
,high24hr
, andlow24hr
.
Example:
client.rTicker('BTC_LTC', 'last')
Returns the 24-hour volume for all markets as well as totals for primary currencies.
Parameter | Mandatory |
---|---|
symbol | No |
currency | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. currency
refers to currency or asset from a givensymbol
.
Example:
client.r24hVolume('BTC_LTC', 'LTC')
Returns the order book for a given market, as well as a sequence number used by websockets for synchronization of book updates and an indicator specifying whether the market is frozen.
Parameter | Mandatory |
---|---|
symbol | Yes |
depth | Yes |
field | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. depth
means the amount ofasks
andbids
in response. Its maximum value is 100. Note: Consider using the Websocket API over HTTP if you are looking for fresh and full order book depth.field
can be filled withasks
,bids
,isFrozen
, andseq
.symbol
anddepth
are mandatory following the API, however here the default value for both are, respectively,all
and50
.
Example:
client.rOrderBook('BTC_LTC', 4, 'asks')
Returns the past 200 trades for a given market.
Parameter | Mandatory |
---|---|
symbol | Yes |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
.
Example:
client.rMarketTradeHistory('BTC_LTC')
Returns candlestick chart data. start
and end
are given as YEAR-MONTH-DAY HOUR:MINUTES:SECONDS
.
Parameter | Mandatory |
---|---|
symbol | Yes |
start | Yes |
period | Yes |
end | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. start
of the window.end
of the window.period
refers to candlestick period in seconds. Valid values are 300, 900, 1800, 7200, 14400, and 86400.
Example:
client.rChartData('BTC_LTC', '2019-08-18 18:45:00', 300)
Returns information about currencies.
Parameter | Mandatory |
---|---|
currency | No |
field | No |
currency
refers to abbreviation of a given asset name. For instanceBTC
is the abbreviation of Bitcoin.field
can be filled withid
,name
,txFee
,minConf
,depositAddress
,disabled
,delisted
,frozen
, andisGeofenced
Example:
client.rCurrencies('BTC', 'txFee')
Returns the list of loan offers and demands for a given currency.
Parameter | Mandatory |
---|---|
currency | Yes |
field | No |
currency
refers to abbreviation of a given asset name. For instanceBTC
is the abbreviation of Bitcoin.field
can be filled withoffers
anddemands
Example:
client.rLoanOrders('BTC','offers')
These methods need signature, i.e. the Poloniex credentials are mandatory.
- The base endpoint is: https://poloniex.com/tradingApi
- Endpoint returns JSON object.
- All methods can return either JSON object, or array.
Returns all of your balances available for trade after having deducted all open orders.
Parameter | Mandatory |
---|---|
currency | No |
currency
refers to abbreviation of a given asset name. For instanceBTC
is the abbreviation of Bitcoin.
Example:
client.rBalances('BTC')
Returns all of your balances, including available balance, balance on orders, and the estimated BTC value of your balance.
Parameter | Mandatory |
---|---|
currency | No |
field | No |
currency
refers to abbreviation of a given asset name. For instanceBTC
is the abbreviation of Bitcoin.field
can be filled withavailable
,onOrders
, andbtcValue
.
Example:
client.rCompleteBalances('BTC', 'available')
Returns your open orders for a given market.
Parameter | Mandatory |
---|---|
symbol | Yes |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. Note:symbol
is mandatory following the API, however here the default value isall
.
Example:
client.rOpenOrders('BTC_LTC')
Returns your trade history for a given market. start
and end
are given as YEAR-MONTH-DAY HOUR:MINUTES:SECONDS
.
Parameter | Mandatory |
---|---|
symbol | Yes |
start | No |
end | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. Note:symbol
is mandatory following the API, however here the default value isall
. start
of time window.end
of time window.- The range between
start
andend
is limited to one day.
Example:
client.rTradeHistory('BTC_LTC')
Places a limit buy order in a given market. If successful, the method will return the order number.
Parameter | Mandatory |
---|---|
symbol | Yes |
rate | Yes |
amount | Yes |
fok | No |
ioc | No |
po | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. - The
rate
to purchase theASSET
inCURRENCY
units as definition of symbol above. - Total
amount
of theASSET
units as definition of symbol above. fok
(fill or kill) -- if this order should either fill in its entirety or be completely aborted.ioc
(immediate or cancel) -- if this order can be partially or completely filled, but any portion of the order that cannot be filled immediately will be canceled.po
(post only) -- if you want this buy order to only be placed if no portion of it fills immediately.
Example:
client.limitBuy('BTC_LTC', '0.00685070', '32.6', ioc=True)
Places a limit sell order in a given market. If successful, the method will return the order number.
Parameter | Mandatory |
---|---|
symbol | Yes |
rate | Yes |
amount | Yes |
fok | No |
ioc | No |
po | No |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. - The
rate
to purchase theASSET
inCURRENCY
units as definition of symbol above. - Total
amount
of theASSET
units as definition of symbol above. fok
(fill or kill) -- if this order should either fill in its entirety or be completely aborted.ioc
(immediate or cancel) -- if this order can be partially or completely filled, but any portion of the order that cannot be filled immediately will be canceled.po
(post only) -- if you want this buy order to only be placed if no portion of it fills immediately.
Example:
client.limitSell('BTC_LTC', '0.00685070', '12.6')
The Poloniex REST API has not market orders from default. So this method is a limit buy order which emulates a market buy order.
Parameter | Mandatory |
---|---|
symbol | Yes |
amount | Yes |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. - The
rate
to purchase theASSET
inCURRENCY
units as definition of symbol above. - Total
amount
of theASSET
units as definition of symbol above.
Example:
client.marketBuy('BTC_LTC', '23.4432')
The Poloniex REST API has not market orders from default. So this method is a limit sell order which emulates a market sell order.
Parameter | Mandatory |
---|---|
symbol | Yes |
amount | Yes |
- Each
symbol
in Poloniex is written in capital letters asCURRENCY_ASSET
. For instanceBTC_LTC
,BTC
is used as currency to buy a given asset,LTC
. - The
rate
to purchase theASSET
inCURRENCY
units as definition of symbol above. - Total
amount
of theASSET
units as definition of symbol above.
Example:
client.marketSell('BTC_LTC', '120.12334')
Cancels an order you have placed in a given market. If successful, the method will return a success of 1.
Parameter | Mandatory |
---|---|
symbol | Yes |
order_number | Yes |
symbol
of a given market written is capital letters.order_number
is the identity number of the order to be canceled.
Example:
client.cancelOrder('BTC_DASH','514845991795')
Cancels all open orders in a given market or, if no market is provided, all open orders in all markets. If successful, the method will return a success of 1 along with a json array of orderNumbers
representing the orders that were canceled. Please note that cancelAllOrders
can only be called 1 time per 2 minutes.
Parameter | Mandatory |
---|---|
symbol | No |
symbol
of a given market written in capital letters.
Example:
client.cancelAllOrders()
Immediately places a withdrawal for a given currency, with no email confirmation. In order to use this method, withdrawal privilege must be enabled for your API key.
Parameter | Mandatory |
---|---|
currency | Yes |
amount | Yes |
address | Yes |
payment_id | No |
currency_to_withdraw_as | No |
currency
refers to abbreviation of a given asset name, e.g.BTC
is the abbreviation of Bitcoin.- Total
amount
of thecurrency
units to withdraw. - Your wallet
address
. - For withdrawals which support payment IDs, (such as
XMR
) you may optionally specifypayment_id
. - For currencies where there are multiple networks to choose from you need to specify the param:
currency_to_withdraw_as
. ForUSDT
usecurrency_to_withdraw_as
=USDTTRON
orUSDTETH
. The default forUSDT
is Omni which is used ifcurrency_to_withdraw_as
is not specified.
Example:
client.withdraw('USDT', '456.54', 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', currency_to_withdraw_as='USDTTRON')
Coming soon.
Coming soon.
Coming soon.
- The base endpoint is: wss://api2.poloniex.com Coming soon.
- Bitcoin (BTC): bc1qe49xvnvgp2qey833ut3qgdv2nltg2xhnv2p6tl
- Decred (DCR): DsWrvibjbh8x8RWdH3CSnsEmD52mi6WxvR6
- DASH: XryxxDNdykosJX5MkNLw9Q5rBVPkNHjmDS