Zaif API library
Project description
zaif
REST API Client for Zaif Exchange
Zaif Exchange用のREST APIクライアント
Features
A single client to call any type of API (public, trading, futures, leveraged). 任意の種類のAPI(公開、取引、先物、レバレッジド)を呼び出す単一のクライアント。
Convenient methods for making API calls using keyword arguments - packs JSON for you! キーワード引数を使用してAPIコールを作成するための便利なメソッド - JSONをパック!
Near 100% test coverage. 100%近いテストカバレッジ。
Tab-completable methods and attributes when using IPython. IPython を使用した場合のタブで完成可能なメソッドと属性。
Supports both Python 2 and Python 3. Python 2とPython 3の両方をサポートします。
Installation (インストール)
zaif is available on PYPI. Install with pip:
$ pip install zaif
or with easy_install:
$ easy_install zaif
The library is currently tested against Python versions 2.7 and 3.4+.
API Reference (APIリファレンス)
The official documentation can be found on the Zaif API reference page. 公式のドキュメントは Zaif APIのリファレンスページ にあります。
Prerequisites (前提条件)
The first thing you need to do is to Sign Up with Zaif.
Next, you need to obtain an API Key and an API Secret. If you’re writing code for your own Zaif account, you can create API keys on Zaif API Settings page. You can create multiple API keys with different permissions for your applications.
NOTE: Make sure to enable appropriate permissions for the API key.
Getting started (始める)
Create a Client object for interacting with the API: APIと対話するための Client オブジェクトを作成します:
from zaif.client import Client
api_key = 'your api key'
api_secret = 'your api secret'
client = Client(api_key,api_secret)
Error handling (エラー処理)
All errors occurring during interaction with the API will be raised as exceptions. These exceptions will be subclasses of zaif.errors.ZaifError.
When the error involves the API server, the error raised will be a subclass of zaif.errors.APIServerError. エラーがAPIサーバに関係する場合、発生したエラーは zaif.errors.APIServerError のサブクラスになります。
When the error is associated with the response received form the API server, zaif.errors.APIResponseError will be raised. エラーがAPIサーバーから受信したレスポンスに関連付けられている場合、zaif.errors.APIResponseError が発生します。
For full details of error responses, please refer to the relevant API documentation.
Error |
HTTP Status code |
---|---|
NotFoundError |
404 |
InternalServerError |
500 |
ServiceUnavailableError |
503 |
GatewayTimeoutError |
504 |
Usage (使い方)
I’ve done my best to make the code clean, commented, and understandable; however it may not be exhaustive. For more details, please refer to the Zaif API official documentation.
In short
Use args for URI paths
Use kwargs for formData or query parameters
PUBLIC API (現物公開API)
Get available currencies, tokens, ICO etc. 通貨情報を取得します。
client.get_currencies()
client.get_currency('btc')
client.get_currency('ETH') # capital for token currencies
Get currency pairs traded on the exchange. 通貨ペア情報を取得します。
client.get_currency_pairs()
client.get_currency_pair('eth_btc')
Get current closing price for a currency pair. 現在の終値を取得します。
client.get_last_price('eth_btc')
Get ticker information for a currency pair. ティッカーを取得します。
client.get_ticker('eth_btc')
Get trades for a currency pair. 全ての取引履歴を取得します。
client.get_trades('eth_btc')
Get board information (asks, bids) for a currency pair. 板情報を取得します。
client.get_depth('eth_btc')
TRADING API (現物取引API)
Get current balance (asset and token balances), API key permissions, number of past trades, number of open orders, server timestamp. 現在の残高(余力および残高・トークン)、APIキーの権限、過去のトレード数、アクティブな注文数、サーバーのタイムスタンプを取得します。
client.get_info()
It is a lightweight version of get_info() and returns items excluding past trades. get_infoの軽量版で、過去のトレード数を除く項目を返します。
client.get_info2()
Get nickname and icon image path for your account. チャットに使用されるニックネームと画像のパスを返します。
client.get_personal_info()
Get account information such as user ID, email, etc. ユーザーIDやメールアドレスといった個人情報を取得します。
client.get_id_info()
Get trade history. ユーザー自身の取引履歴を取得します。
client.get_trade_history()
client.get_trade_history(currency_pair='eth_btc',count=10,order='ASC')
Get a list of active orders (currency pairs and tokens). 現在有効な注文一覧を取得します(未約定注文一覧)。
client.get_active_orders()
client.get_active_orders(currency_pair='eth_btc')
client.get_active_orders(is_token_both=True)
Create a new trading order. 取引注文を行います。
client.trade(currency_pair='eth_btc',
action='bid',
price=100,
amount=1.5)
client.trade(currency_pair='eth_btc',
action='bid',
price=100,
amount=1.5,
limit=120)
Convenient function to create a buy order.
client.buy(currency_pair='eth_btc',price=100,amount=1.5)
client.buy(currency_pair='eth_btc',price=100,amount=1.5,limit=120)
Convenient function to create a sell order.
client.sell(currency_pair='eth_btc',price=100,amount=1.5)
client.sell(currency_pair='eth_btc',price=100,amount=1.5,limit=120)
Cancel an open order. 注文の取消しを行います。
client.cancel_order(order_id=123)
client.cancel_order(order_id=123,currency_pair='eth_btc')
Withdraw currency to a specific address. 資金の引き出しリクエストを送信します。
client.withdraw(currency='ETH',address='0x1234abcd5678efgh',amount=1)
Get deposit payments (account funding) history for a currency. 入金履歴を取得します。
client.get_deposit_history(currency='btc')
client.get_deposit_history(currency='ETH',count=50,order='ASC')
Get history of withdrawals for a currency. 出金履歴を取得します。
client.get_withdraw_history(currency='btc')
client.get_withdraw_history(currency='ETH',count=50,sort='ASC')
FUTURES API (先物公開API)
Get information on all futures groups. 先物取引の情報を取得します。
client.get_groups()
Get information on a specific futures group
client.get_group(2)
Get current closing price of a specific futures group. 現在の終値を取得します。
client.get_group_last_price(2)
Get ticker for a futures group. ティッカーを取得します。
client.get_group_ticker(2)
Get all trades of a futures group. 全ての取引履歴を取得します。
client.get_group_trades(2)
Get board information of a futures transaction. 板情報を取得します。
client.get_group_depth(2)
LEVERAGE API (レバレッジ取引API)
Get history of your leveraged trades. レバレッジ取引のユーザー自身の取引履歴を取得します。
client.get_positions(type='futures',group_id=1)
client.get_positions(type='futures',
group_id=1,
count=10,
order='ASC',
currency_pair='eth_btc')
Get detailed history of your leveraged trades. レバレッジ取引のユーザー自身の取引履歴の明細を取得します。
client.get_position_history(type='futures',group_id=1,leverage_id=123)
Get currently valid order list of leveraged transactions. レバレッジ取引の現在有効な注文一覧を取得します(未約定注文一覧)。
client.get_active_positions(type='futures',group_id=1)
client.get_active_positions(type='futures',group_id=1,currency_pair='eth_btc')
Create a new leveraged transaction. レバレッジ取引の注文を行います。
client.create_position(type='futures',
group_id=1,
currency_pair='eth_btc',
action='ask',
price=100.0,
amount=1,
leverage=3.25)
client.create_position(type='futures',
group_id=1,
currency_pair='eth_btc',
action='ask',
price=100.0,
amount=1,
leverage=3.25,
limit=120,
stop=90)
Convenient method to create a new leveraged buy transaction.
client.create_buy_position(type='futures',
group_id=1,
currency_pair='eth_btc',
price=100.0,
amount=1,
leverage=3.25)
client.create_buy_position(type='futures',
group_id=1,
currency_pair='eth_btc',
price=100.0,
amount=1,
leverage=3.25,
limit=120,
stop=90)
Convenient method to create a new leveraged sell transaction.
client.create_sell_position(type='futures',
group_id=1,
currency_pair='eth_btc',
price=100.0,
amount=1,
leverage=3.25)
client.create_sell_position(type='futures',
group_id=1,
currency_pair='eth_btc',
price=100.0,
amount=1,
leverage=3.25,
limit=120,
stop=90)
Modify a leveraged transaction. レバレッジ取引の注文の変更を行います。
client.change_position(type='margin',group_id=1,leverage_id=123)
client.change_position(type='margin',group_id=1,leverage_id=123,limit=120)
Cancel a leveraged transaction. レバレッジ取引の注文の取消しを行います。
client.cancel_position(type='margin',group_id=1,leverage_id=123)
Testing / Contributing (テスト/寄稿)
Any contribution is welcome! The process is simple:
Fork this repo
Make your changes
Run the tests (for multiple versions: preferred)
Submit a pull request.
Testing for your current python version (現在のPythonバージョン)
Tests are run via nosetest. To run the tests, clone the repository and then:
# Install the required dependencies
$ pip install -r requirements.txt
$ pip install -r test-requirements.txt
# Run the tests
$ make tests
If you’d also like to generate an HTML coverage report (useful for figuring out which lines of code are actually being tested), make sure the requirements are installed and then run:
$ make coverage
Testing for multiple python versions (複数のPythonバージョン)
I am using tox to run the test suite against multiple versions of Python. Tox requires the appropriate Python interpreters to run the tests in different environments. I would recommend using pyenv for this.
However, the process is a little unintuitive because tox does not seem to work with multiple versions of python (installed via pyenv) when inside a pyenv virtual environment. So, first deactivate your pyenv virtual environment:
$ (zaifapi-venv) pyenv deactivate
and then install tox with pip or easy_install:
$ pip install tox # or
$ easy_install tox
Install python versions which you want to test:
$ pyenv install 2.7.14
$ pyenv install 3.5.0
$ pyenv install 3.6.0
and so forth. Now, in your project directory:
# all versions which are in tox.ini file
$ pyenv local 2.7.14 3.5.0 3.6.0
# run the tests for all the above versions
$ tox
License (ライセンス)
This project is licensed under the MIT License. See the LICENSE file for more details.
Acknowledgements (謝辞)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file zaif-1.1.1.tar.gz
.
File metadata
- Download URL: zaif-1.1.1.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 440494f869ab89ae050bfb2c3394e38e5b8f9bc145030e22355c7e4b058af66f |
|
MD5 | 0587fad4d69c84684c41ad3a46ec40f0 |
|
BLAKE2b-256 | 176639f0781e06367784187bada57017d6b427adf39a85b5edf9fecc971243b4 |