|
1 | | -[](https://github.com/s4w3d0ff/python-poloniex/blob/master/LICENSE) [](https://github.com/s4w3d0ff/python-poloniex/releases) |
| 1 | +[](https://github.com/s4w3d0ff/python-poloniex/blob/master/LICENSE) [](https://github.com/s4w3d0ff/python-poloniex/releases) |
2 | 2 | [](https://github.com/s4w3d0ff/python-poloniex/tree/master) [](https://github.com/s4w3d0ff/python-poloniex/tree/dev) |
3 | 3 | Inspired by [this](http://pastebin.com/8fBVpjaj) wrapper written by 'oipminer' |
4 | | -> I (s4w3d0ff) am not affiliated with, nor paid by [Poloniex](https://poloniex.com). I have been an active trader there since 2014 and love python. I found the linked python wrapper on the poloniex support page to be incomplete and buggy so I decided to write this wrapper and create this git repository. If you wish to contribute to this repository please read [CONTRIBUTING.md](https://github.com/s4w3d0ff/python-poloniex/blob/master/CONTRIBUTING.md). All and any help is appreciated. |
5 | | -## Install latest release: |
6 | | -Python 2: |
7 | | -``` |
8 | | -pip install https://github.com/s4w3d0ff/python-poloniex/archive/v0.4.7.zip |
9 | | -``` |
| 4 | +> I (s4w3d0ff) am not affiliated with, nor paid by [Poloniex](https://poloniex.com). I found the linked python wrapper on the poloniex support page to be incomplete and buggy so I decided to write this wrapper and create a git repository. If you wish to contribute to the repository please read [CONTRIBUTING.md](https://github.com/s4w3d0ff/python-poloniex/blob/master/CONTRIBUTING.md). All and any help is appreciated. |
| 5 | +#### Features: |
| 6 | +- [x] Python 2.7 and 3.5+ |
| 7 | +- [x] Pypi |
| 8 | +- [x] Travis |
| 9 | +- [x] Websocket api support |
| 10 | +- [x] Minimal amount of dependencies |
| 11 | +- [x] Internal checks to reduce external api errors |
| 12 | +- [x] Rate limiter to keep from going over call limits |
| 13 | +- [x] Retries failed api calls during connection issues |
10 | 14 |
|
11 | | -Python 3: |
| 15 | +### Install: |
12 | 16 | ``` |
13 | | -pip3 install https://github.com/s4w3d0ff/python-poloniex/archive/v0.4.7.zip |
| 17 | +pip install --upgrade poloniexapi |
14 | 18 | ``` |
15 | 19 |
|
16 | | -## Usage: |
| 20 | +### Usage: |
17 | 21 | See the [wiki](https://github.com/s4w3d0ff/python-poloniex/wiki) or `help(poloniex)` for more. |
18 | | -#### Basic Public Setup (no api Key/Secret): |
| 22 | + |
| 23 | +All api calls are done through an instance of `poloniex.Poloniex`. You can use the instance as follows: |
19 | 24 | ```python |
| 25 | +# import this package |
20 | 26 | from poloniex import Poloniex |
| 27 | +# make an instance of poloniex.Poloniex |
21 | 28 | polo = Poloniex() |
| 29 | +# show the ticker |
| 30 | +print(polo('returnTicker')) |
22 | 31 | ``` |
23 | | -Ticker |
| 32 | +Using the instances `__call__` method (shown above) you can pass the command string as the first argument to make an api call. The `poloniex.Poloniex` class also has 'helper' methods for each command that will help 'sanitize' the commands arguments. For example, `Poloniex.returnChartData('USDT_BTC', period=777)` will raise `PoloniexError("777 invalid candle period")`. |
| 33 | + |
24 | 34 | ```python |
25 | | -print(polo('returnTicker')['BTC_ETH']) |
26 | | -# or |
27 | | -print(polo.returnTicker()['BTC_ETH']) |
28 | | -``` |
29 | | -**Public** trade history: |
30 | | -```python |
31 | | -print(polo.marketTradeHist('BTC_ETH')) |
| 35 | +# using a 'helper' method |
| 36 | +print(polo.returnChartData(currencyPair='BTC_LTC', period=900)) |
| 37 | +# bypassing 'helper' |
| 38 | +print(polo(command='returnChartData', args={'currencyPair': 'BTC_LTC', |
| 39 | + 'period': 900})) |
32 | 40 | ``` |
| 41 | +Almost every api command can be called this way. This wrapper also checks that the command you pass to the `command` arg is a valid command to send to poloniex, this helps reduce api errors due to typos. |
| 42 | + |
| 43 | +#### Private Commands: |
| 44 | +To use the private api commands you first need an api key and secret (supplied by poloniex). When creating the instance of `poloniex.Poloniex` you can pass your api key and secret to the object like so: |
33 | 45 |
|
34 | | -#### Basic Private Setup (Api key/secret required): |
35 | 46 | ```python |
36 | 47 | import poloniex |
37 | | -polo = poloniex.Poloniex('your-Api-Key-Here-xxxx','yourSecretKeyHere123456789') |
38 | | -# or |
| 48 | +polo = poloniex.Poloniex(key='your-Api-Key-Here-xxxx', secret='yourSecretKeyHere123456789') |
| 49 | +# or this works |
39 | 50 | polo.key = 'your-Api-Key-Here-xxxx' |
40 | 51 | polo.secret = 'yourSecretKeyHere123456789' |
41 | | -``` |
42 | | -Get all your balances |
43 | | -```python |
| 52 | +# get your balances |
44 | 53 | balance = polo.returnBalances() |
45 | 54 | print("I have %s ETH!" % balance['ETH']) |
46 | 55 | # or |
47 | 56 | balance = polo('returnBalances') |
48 | 57 | print("I have %s BTC!" % balance['BTC']) |
49 | 58 | ``` |
| 59 | +#### Trade History: |
| 60 | +Poloniex has two api commands with the same name `returnTradeHistory`. To work around this without splitting up the commands or having to specify 'public' or 'private' we use the helper method `Poloniex.marketTradeHist` for public trade history and `Poloniex.returnTradeHistory` for private trades. If you try to bypass the helper method using `Poloniex.__call__`, it will call the private command. |
| 61 | + |
| 62 | +**Public** trade history: |
| 63 | +```python |
| 64 | +print(polo.marketTradeHist('BTC_ETH')) |
| 65 | +``` |
50 | 66 | **Private** trade history: |
51 | 67 | ```python |
52 | 68 | print(polo.returnTradeHistory('BTC_ETH')) |
53 | 69 | ``` |
54 | | -**Examples of WAMP applications using the websocket push API can be found [here](https://github.com/s4w3d0ff/python-poloniex/tree/master/examples).** |
| 70 | + |
| 71 | +#### Websocket Usage: |
| 72 | +Right now, the easiest way to use the websocket api is making a child class like so: |
| 73 | +```python |
| 74 | +import logging |
| 75 | + |
| 76 | +logging.basicConfig() |
| 77 | + |
| 78 | +class MySocket(poloniex.Poloniex): |
| 79 | + |
| 80 | + def on_heartbeat(self, msg): |
| 81 | + """ |
| 82 | + Triggers whenever we get a heartbeat message |
| 83 | + """ |
| 84 | + print(msg) |
| 85 | + |
| 86 | + def on_volume(self, msg): |
| 87 | + """ |
| 88 | + Triggers whenever we get a ticker message |
| 89 | + """ |
| 90 | + print(msg) |
| 91 | + |
| 92 | + def on_ticker(self, msg): |
| 93 | + """ |
| 94 | + Triggers whenever we get a 24hvolume message |
| 95 | + """ |
| 96 | + print(msg) |
| 97 | + |
| 98 | + def on_market(self, msg): |
| 99 | + """ |
| 100 | + Triggers whenever we get a market ('currencyPair') message |
| 101 | + """ |
| 102 | + print(msg) |
| 103 | + |
| 104 | + def on_account(self, msg): |
| 105 | + """ |
| 106 | + Triggers whenever we get an account message |
| 107 | + """ |
| 108 | + print(msg) |
| 109 | + |
| 110 | +sock = MySocket() |
| 111 | +# helps show what is going on |
| 112 | +sock.logger.setLevel(logging.DEBUG) |
| 113 | +# start the websocket thread and subsribe to '24hvolume' |
| 114 | +sock.startws(subscribe=['24hvolume']) |
| 115 | +``` |
| 116 | + |
| 117 | +**More examples of how to use websocket push API can be found [here](https://github.com/s4w3d0ff/python-poloniex/tree/master/examples).** |
0 commit comments