Skip to content

Latest commit

 

History

History
80 lines (71 loc) · 2.96 KB

README.md

File metadata and controls

80 lines (71 loc) · 2.96 KB

An API wrapper for Poloniex.com written in Python

Tested on Python 2.7.12 & 3.5.2

Inspired by this wrapper written by 'oipminer'

Features:

  • The first 2 args in the poloniex.Poloniex object (Key and Secret) are optional when used for public api commands.
  • Api commands have been 'mapped' into methods within the Poloniex class for your convenience.
  • Raises poloniex.PoloniexError if the command supplied does not exist, if the api keys are not defined and attempting to access a private api command, or if Poloniex.com returns an api error.
  • The poloniex.Poloniex(timeout=1) attribute/arg adjusts the number of seconds to wait for a response from poloniex, else requests.exceptions.Timeout is raised.
  • If a requests exception is raised (including Timeouts), signaling that the api call did not go through, the wrapper will attempt to try the call again. The wait pattern between retrys are as follows (in seconds): (0, 2, 5, 30). Once the retry delay list is exausted and the call still throws an error, the list of captured exceptions is raised.
  • A call restrictor (coach) is enabled by default, limiting the api wrapper to 6 calls per second. If you wish, you can deactivate the coach using Poloniex(coach=False) or use an 'external' coach.
  • By default, json floats are parsed as strings (ints are ints), you can define Poloniex(jsonNums=float) to have all numbers (floats and ints) parsed as floats (or import and use decimal.Decimal).
  • poloniex.coach, poloniex.retry, and poloniex have self named loggers.

Install:

Python 2:

pip install git+https://github.com/s4w3d0ff/python-poloniex.git

Python 3:

pip3 install git+https://github.com/s4w3d0ff/python-poloniex.git

Uninstall:

Python 2:

pip uninstall poloniex

Python 3:

pip3 uninstall poloniex

Usage:

Basic Public Setup (no ApiKey/Secret):

from poloniex import Poloniex
polo = Poloniex()

Ticker

print(polo('returnTicker')['BTC_ETH'])
# or
print(polo.returnTicker()['BTC_ETH'])

Public trade history:

print(polo.marketTradeHist('BTC_ETH'))

Basic Private Setup (ApiKey/Secret required):

import poloniex
polo = poloniex.Poloniex('your-Api-Key-Here-xxxx','yourSecretKeyHere123456789')
# or
polo.Key = 'your-Api-Key-Here-xxxx'
polo.Secret = 'yourSecretKeyHere123456789'

Get all your balances

balance = polo.returnBalances()
print("I have %s ETH!" % balance['ETH'])
# or
balance = polo('returnBalances')
print("I have %s BTC!" % balance['BTC'])

Custom/external coach example:

from poloniex import Poloniex, Coach
myCoach = Coach()

public = Poloniex(coach=myCoach)
private = Poloniex(Key, Secret, coach=myCoach)
# now make calls using both 'private' and 'public' and myCoach will handle both

Examples of WAMP applications using the websocket push API can be found here.