项目作者: c0lon

项目描述 :
Binance API Client
高级语言: Python
项目地址: git://github.com/c0lon/binance-api-python.git
创建时间: 2017-10-17T22:13:49Z
项目社区:https://github.com/c0lon/binance-api-python

开源协议:

下载


binance

Python client for the
Binance API.

Requires python 3.6 or greater.

Installation

  1. git clone https://github.com/c0lon/binance.git
  2. cd binance
  3. python setup.py install

Tests

First, enter your API key and secret into
config.yaml.
Then run the command below:

python setup.py test

Any log messages are written to tests/test.log.

To enter a pdb shell on a test failure, run

pytest --pdb

See the
pytest docs
for more information.

Enabling all tests

By default, tests that would change your account in any way,
such as placing an order or withdrawing funds, are disabled.
To enable them, edit pytest.ini by changing

  1. [pytest]
  2. testpaths = tests/test_fetchers.py

to

  1. [pytest]
  2. testpaths = tests

then follow the instructions in
tests/test_actions.py.

WARNING

Enabling these tests means that your account balances will be
changed if the tests are successful. Follow the configuration
instructions very carefully. Failing to do so could result
in the tests altering your account in a negative way.

Usage

  1. from binance import BinanceClient
  2. client = BinanceClient(apikey, apisecret)
  3. client.ping()

Storage Classes

Most client methods described below return objects that can be found
in binance/storage.py. These objects convert
values into their natives types, including:

  • decimal strings to float
  • timestamps to datetime.datetime

Each object accepts a raw API version of the object in its constructor.
These objects also have a to_json() method that returns the object
as a JSON-dumpable dictionary.

Client Methods

Methods with names ending with _async are asynchronous coroutines
that perform the same action as their synchronous counterpart.
(Read more about Python’s asynchronous features
here.)

Public Endpoint Methods

/ping
  1. def ping()
/time

Return the server time in milliseconds as an integer.

  1. def get_server_time()
/ticker

Return binance.storage.Ticker.

  1. def get_ticker(self, symbol='')
/depth

Return binance.storage.Depth.

  1. def get_depth(self, symbol)
  2. async def get_depth_async(self, symbol)
/klines

Return list of binance.storage.Candlestick.

  1. def get_candlesticks(self, symbol, interval, **kwargs)
  2. async def get_candlesticks_async(self, symbol, interval, **kwargs)

Signed Endpoint Methods

/myTrades

Return list of binance.storage.Trade.

  1. def get_trade_info(self, symbol)
/openOrders

Return list of binance.storage.Order.

  1. def get_open_orders(self, symbol)
/allOrders

Return list of binance.storage.Order.

  1. def get_all_orders(self, symbol):
/order

Return binance.storage.Order

  1. def get_order_status(self, symbol, order_id)
  2. def place_market_buy(self, symbol, quantity, **kwargs)
  3. def place_market_sell(self, symbol, quantity, **kwargs)
  4. def place_limit_buy(self, symbol, quantity, price, **kwargs)
  5. def place_limit_sell(self, symbol, quantity, price, **kwargs)

Return True if order was canceled successfully.

  1. def cancle_order(self, order_id)
/withdraw

Return True if the withdraw is successfully initiated.

  1. def withdraw(self, asset, amount, address, **kwargs)
/withdrawHistory.html

Return list of binance.storage.Withdraw.

  1. def get_withdraw_history(self, asset='', **kwargs)
/depositHistory.html

Return list of binance.storage.Deposit.

  1. def get_deposit_history(self, asset='', **kwargs)

Websocket Endpoint Methods

@depth
  1. def watch_depth(self, symbol)

See watch_depth.py for an example of how to
use the asynchronous watch_depth() method.

@kline
  1. def watch_candlesticks(self, symbol)

See watch_candlesticks.py for an
example of how to use the asynchronous watch_candlesticks() method.

Event Callback Methods

  1. def event(self, coro)

Register an asynchronous coroutine that is fired on certain client
events.

Supported Events:

  • on_depth_ready
  • on_depth_event
  • on_candlesticks_ready
  • on_candlesticks_event

See scripts/watch_depth.py and
scripts/watch_candlesticks.py
for examples.

Scripts

In order for the scripts below to work correctly, you must put your
apiKey and secretKey into the apikey and apisecret slots
in config.yaml, respectively.

watchdepth

  1. usage: watchdepth [-h] [--log-level {DEBUG,INFO,WARN,ERROR,CRITICAL}]
  2. [--version] [--debug] [-l DEPTH_LIMIT]
  3. config_uri symbol
  4. positional arguments:
  5. config_uri the config file to use.
  6. symbol watch the depth of symbol <SYMBOL>.
  7. optional arguments:
  8. -h, --help show this help message and exit
  9. --log-level {DEBUG,INFO,WARN,ERROR,CRITICAL}
  10. --version Show the package version and exit.
  11. --debug
  12. -l DEPTH_LIMIT, --depth-limit DEPTH_LIMIT
  13. show the <DEPTH> latest orders on each side.

watchcandlesticks

  1. usage: watchcandlesticks [-h] [--log-level {DEBUG,INFO,WARN,ERROR,CRITICAL}]
  2. [--version] [--debug] [-d DEPTH]
  3. config_uri symbol interval
  4. positional arguments:
  5. config_uri the config file to use.
  6. symbol watch the candlesticks of symbol <SYMBOL>.
  7. interval set the candlesticks interval.
  8. optional arguments:
  9. -h, --help show this help message and exit
  10. --log-level {DEBUG,INFO,WARN,ERROR,CRITICAL}
  11. --version Show the package version and exit.
  12. --debug
  13. -d DEPTH, --depth DEPTH
  14. display the <DEPTH> latest candlesticks.