OneToken is a application to fetch tick and play with orders. OTS is a friendly python wrapper for ws API and restful API which will be introduce here, users can use API directly as they like
Users can:
- Streaming contract tick(via Quote).
- Place, amend, cancel orders(via Account).
- bitmex
- okex
- binance
- bithumb
- huobi.pro
- bitfinex
- bitstar
- bittrex
- poloniex
- gate
- exx
- coinegg
Currently the support of other exchanges is still under development.
python 3.6
git clone https://github.com/qbtrade/onetoken
cd onetoken
pip install .
OR
pip install onetoken -U
Then use onetoken with import onetoken
in python script.
Try Quote and Account class, the code is in './example'
$ cd onetoken/
if you don't want to install this package, set the PYTHONPATH
$ export PYTHONPATH=.
To try Quote:
$ python example/quote.py
To try Account, prepare your api_key and api_secret, then:
$ python example/account.py
api_key and api_secret will be required in the console.
time, price, volume, bids, asks, contract, source, exchange_time, amount
some property function:
last, bid1, ask1, weighted_middle
parse to or from other forms:
init_with_dict(dct)
to_dict()
from_dct(dct)
to_mongo_dict()
to_short_list()
from_short_list()
from_dict()
to_ws_str()
To subscribe contract tick.
-
async def subscribe_tick(self, contract, on_update=None)
contract
: str, contract name. e.g.ltc.btc:xtc.okex
on_update
: func, callback function, accept bothasync
andnon-async
function.to subscribe a tick stream of contract, on_update will be called once new tick reach.
-
async def get_last_tick(self, contract)
contract
: str, contract name. e.g.ltc.btc:xtc.okex
to get the last tick of specific contract.
To perform account actions.
-
def __init__(self, symbol: str, api_key, api_secret, loop=None, host=None)
symbol
: str, symbolapi_key
: str, api_keyapi_secret
: str, api_secretloop
:host
: default tohttps://1token.trade/api/v1/trade
initialize an account for specific symbol with api_key and api_secret
-
async def get_pending_list(self)
get the list of orders on pending status
-
async def cancel_use_client_oid(self, oid)
oid
: str, client_oidcancel orders with
oid
-
async def cancel_use_exchange_oid(self, oid)
oid
: str, exchange_oidcancel orders with
oid
-
async def cancel_all(self)
cancel all orders
-
async def get_info(self, timeout=15)
get account info
return (info, err)
-
def get_total_amount(self, pos_symbol)
pos_symbol
: str, symbolreturn position of symbol if symbol in position else 0.0
-
async def place_and_cancel(self, con, price, bs, amount, sleep, options=None)
con
: str, contractprice
: number, wanted pricebs
: str,'b'
or's'
, 'b' for buy, 's' for sellamount
: number, wanted amountsleep
: int, seconds between place and canceloptions
:place a order and cancel it after
sleep
seconds -
async def get_status(self)
get status
-
async def get_order_use_client_oid(self, client_oid)
async def get_order_use_exchange_oid(self, exchange_oid)
get order with client_oid or exchange_oid
-
async def amend_order_use_client_oid(self, client_oid, price, amount)
async def amend_order_use_exchange_oid(self, exchange_oid, price, amount)
client_oid
|exchange_oid
: str, oidprice
: number, wanted priceamount
: number, wanted amountamend specific order with new price and amount
-
async def place_order(self, con, price, bs, amount, client_oid=None, tags=None, options=None)
con
: str, contractprice
: number, wanted pricebs
: str,'b'|'s'
, to buy or to sellamount
: number, wanted amountclient_oid
: str(len == 32), client_oid is used to locate orders which will be generated randomly if not providedtags
: dict, tagsoptions
:place order
return (res, err)
Connect your websocket client to wss://1token.trade/api/v1/quote/ws
A basic command is sent in the following format:
{
'uri': '<command>',
'args': {'arg1':'value1', 'arg2':'value2', ...}
}
The following commands are available without authentication:
subscribe-single-tick-verbose
subscribe a real-time ticker info of a given contract
Subscribe ticker
//request
{
'uri': 'subscribe-single-tick-verbose',
'args': {'contract': '<contract>'}
}
//webSocket Client request
{
'uri': 'ping'
}
//webSocket Server response
{
'uri': 'pong'
}
Restful host is https://1token.trade/api/v1/trade
API Explorer(https://1token.trade/r/swagger)
rule | example | explaination | |
---|---|---|---|
contract | {exchange}/{tpa}.{tpb} | okex/btc.usdt | tpa/tpb means "trading pair a/b"; use latter in the trading pair to buy and sell the former in exchange; the example means it uses usdt to sell and buy btc in okex |
account | {exchange}/{specific_id} | okex/demo1 | putting the exchange in account makes it more readable and recognizable |