Skip to content
s4w3d0ff edited this page Jun 29, 2017 · 7 revisions

An instance of the poloniex.Poloniex class is used to make api calls to poloniex.com and return the decoded json message. 99.99% of known api commands are 'mapped' into the Poloniex object (with the exception of the public returnTradeHistory which is named marketTradeHist).

The Poloniex class has the following parameters (all parameters are optional):

poloniex.Poloniex(key='', secret='', timeout=None, coach=True, jsonNums=False)

  • key: str, api key supplied by poloniex.com [optional if making public api calls]
  • secret: str, corresponding Key secret hash [optional if making public api calls]
  • timeout: int, time in seconds to wait for a response from poloniex before raising requests.exceptions.Timeout [default: None, waits forever]
  • coach: obj or bool, a call limiter that restricts calls to 6 calls per second. [default: True, internal coach is used]
  • jsonNums: obj, data type to use for parsing floats and ints [default:str]

Example Uses:

Using the defaults:

By default, the Poloniex object has no key or secret defined (so it can be used for only public commands).

import poloniex
poloniex.Poloniex().returnTicker() # returns ticker
poloniex.Poloniex().returnBalances() # PoloniexError: "A Key and Secret needed!"
poloniex.Poloniex(key='my-api-key', secret='superlongsecrethashforyourkey').returnBalances() # returns balances

NOTE: Using the wrapper in this way will, for the most part, render the internal coach useless.

Using the Coach:

Each instance of the Poloniex class will have a poloniex.Coach created on init. If you wish to create multiple Poloniex objects that are using the same Coach instance, you can pass an instance of Coach as an argument, and the Poloniex object will use that coach.

from poloniex import Poloniex, Coach
myCoach = Coach(timeFrame=1.0, callLimit=6) # create a coach
polo1 = Poloniex(coach=myCoach) # pass myCoach to each
polo2 = Poloniex(coach=myCoach) 
# now both 'polo1' and 'polo2' will use 'myCoach' to restrict api calls

Auto retry:

The Poloniex class has a built-in retry method that will capture requests.exceptions.RequestsExceptions, including requests.exceptions.Timeout (if a timeout has been set), and attempt to make the api call again. Between each retry the method waits a few seconds. The wait pattern is: 0, 2, 5, 30 seconds. If the exception is still being raised after the retry wait list is exhausted, the wrapper stops trying the call and raises an PoloniexError.