Allcoin API¶
client module¶
-
class
allcoin.client.
Client
(api_key, api_secret, requests_params=None)[source]¶ Bases:
object
-
API_URL
= 'https://api.allcoin.com/api'¶
-
API_VERSION
= 'v1'¶
-
ORDER_STATUS_UNFILLED
= 0¶
-
ORDER_STATUS_PARTIALLY_FILLED
= 1¶
-
ORDER_STATUS_FILLED
= 2¶
-
ORDER_STATUS_CANCELLED
= 10¶
-
__init__
(api_key, api_secret, requests_params=None)[source]¶ Allcoin API Client constructor
Parameters: - api_key (str.) – Api Key
- api_secret (str.) – Api Secret
- requests_params (dict.) – optional - Dictionary of requests params to use for all calls
-
get_ticker
(symbol)[source]¶ Get the Ticker for the market
Parameters: symbol (str) – required ticker = client.get_ticker('eth_btc')
Returns: API response { "date":"1410431279", "ticker":{ "buy":"33.15", "high":"34.15", "last":"33.15", "low":"32.05", "sell":"33.16", "vol":"10532696.39199642" } }
Raises: AllcoinResponseException, BinanceAPIException
-
get_order_book
(symbol, size=None, merge=None)[source]¶ Get the Order Book for the market
Parameters: - symbol (str) – required
- size (int) – Default 100; max 100
- merge (int) – merge depth Default 1; max 100
# default book = client.get_order_book('eth_btc') # optional params book = client.get_order_book('eth_btc', size=5, merge=5)
Returns: API response { "asks": [ [792, 5], [789.68, 0.018], [788.99, 0.042], [788.43, 0.036], [787.27, 0.02] ], "bids": [ [787.1, 0.35], [787, 12.071], [786.5, 0.014], [786.2, 0.38], [786, 3.217], [785.3, 5.322], [785.04, 5.04] ] }
Raises: AllcoinResponseException, BinanceAPIException
-
get_trades
(symbol, since=None)[source]¶ Get the last 600 trades with optional since transaction id parameter
Parameters: - symbol (str) – required
- since (int) – Transaction id (inclusive)
# default trades = client.get_trades('eth_btc') # default trades = client.get_trades('eth_btc', since=230433)
Returns: API response [ { "date": "1367130137", "date_ms": "1367130137000", "price": 787.71, "amount": 0.003, "tid": "230433", "type": "sell" }, { "date": "1367130137", "date_ms": "1367130137000", "price": 787.65, "amount": 0.001, "tid": "230434", "type": "sell" }, { "date": "1367130137", "date_ms": "1367130137000", "price": 787.5, "amount": 0.091, "tid": "230435", "type": "sell" } ]
Raises: AllcoinResponseException, BinanceAPIException
-
get_trade_history
(symbol, since=None)[source]¶ Get trade history - requires api key
Parameters: - symbol (str) – required
- since (int) – Transaction id (inclusive)
# default trades = client.get_trade_history('eth_btc') # default trades = client.get_trade_history('eth_btc', since=230433)
Returns: API response [ { "date": 1367130137, "date_ms": 1367130137000, "price": 787.71, "amount": 0.003, "tid": "230433", "type": "sell" }, { "date": 1367130137, "date_ms": 1367130137000, "price": 787.65, "amount": 0.001, "tid": "230434", "type": "sell" }, { "date": 1367130137, "date_ms": 1367130137000, "price": 787.5, "amount": 0.091, "tid": "230435", "type": "sell" } ]
Raises: AllcoinResponseException, BinanceAPIException
-
get_klines
(symbol, kline_type, size=None, since=None)[source]¶ Get klines for a symbol
Parameters: - symbol (str) – required
- kline_type (str) – type of candlestick (1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 12hour, 1day, 3day, 1week)
- size (int) – number of klines to return
- since (int) – timestamp in ms to return from
# default klines = client.get_klines('eth_btc', '1min') # optional params klines = client.get_klines('eth_btc', '1hour', size=20, since=1417449600000)
Returns: API response [ [ 1417449600000, # timestamp 2339.11, # open 2383.15, # high 2322, # low 2369.85, # close 83850.06 # volume ], [ 1417536000000, 2370.16, 2380, 2352, 2367.37, 17259.83 ] ]
Raises: AllcoinResponseException, BinanceAPIException
-
get_userinfo
()[source]¶ Get account info
# default info = client.get_userinfo()
Returns: API response { "info": { "funds": { "free": { "btc": "0", "usd": "0", "ltc": "0" }, "freezed": { "btc": "0", "usd": "0", "ltc": "0" } } }, "result": true }
Raises: AllcoinResponseException, BinanceAPIException
-
create_order
(symbol, side, price, amount)[source]¶ Create an order
Parameters: - symbol (str) – required
- side (str) – order side buy/sell
- price (str) – order price
- amount (str) – order quantity
# default order = client.create_order('eth_btc', 'buy', '0.2348', '100')
Returns: API response { "order_id": "123456", "result": true }
Raises: AllcoinResponseException, BinanceAPIException
-
create_buy_order
(symbol, price, amount)[source]¶ Create a buy order
Parameters: - symbol (str) – required
- price (str) – order price
- amount (str) – order quantity
# default order = client.create_buy_order('eth_btc', '0.2348', '100')
Returns: API response { "order_id": "123456", "result": true }
Raises: AllcoinResponseException, BinanceAPIException
-
create_sell_order
(symbol, price, amount)[source]¶ Create a sell order
Parameters: - symbol (str) – required
- price (str) – order price
- amount (str) – order quantity
# default order = client.create_buy_order('eth_btc', '0.2348', '100')
Returns: API response { "order_id": "123456", "result": true }
Raises: AllcoinResponseException, BinanceAPIException
-
batch_orders
(symbol, order_data, order_type=None)[source]¶ Create an order
Parameters: - symbol (str) – required
- order_data (list of dicts) – list of dictionaries of price, amount and type
- order_type (str) – optional buy/sell default used if type not set in order_data dict
order_data = [ { "price": "0.0123", "amount": "120", "type": "sell" }, { "price": "0.0112", "amount": "110" } ] order = client.create_order('eth_btc', order_data, type='buy')
Returns: API response { "order_info":[ {"order_id":41724206}, {"error_code":10011,"order_id":-1}, {"error_code":10014,"order_id":-1} ], "result":true }
Raises: AllcoinResponseException, BinanceAPIException
-
cancel_order
(symbol, order_id)[source]¶ Cancel an order or up to 3 orders
Parameters: - symbol (str) – required
- order_id (str) – order ID (multiple orders are separated by a comma ‘,’, 3 orders at most are allowed per request)
# single order order = client.cancel_order('eth_btc', '123456') # multiple orders order = client.cancel_order('eth_btc', '123456,123457,123557')
Returns: API response # single order id { "order_id": "123456", "result": true } # multiple order ids { "success":"123456,123457", "error":"123458" }
Raises: AllcoinResponseException, BinanceAPIException
-
get_order
(symbol, order_id)[source]¶ Get info about a particular order
Parameters: - symbol (str) – required
- order_id (str) – order ID to fetch
order = client.get_order('eth_btc', '123456')
Returns: API response { "result": true, "orders": [ { "amount": 0.1, "avg_price": 0, # average transaction price "create_date": 1418008467000, # order time "deal_amount": 0, # filled quantity "order_id": 10000591, # order id "price": 500, # entrustment price "status": 0, # 0 = unfilled, 1 = partially filled, 2 = fully filled, 10 = cancelled "symbol": "btc_usd", "type": "sell" }, { "amount": 0.2, "avg_price": 0, "create_date": 1417417957000, "deal_amount": 0, "order_id": 10000724, "price": 0.1, "status": 0, "symbol": "btc_usd", "type": "buy" } ] }
Raises: AllcoinResponseException, BinanceAPIException
-
get_open_orders
(symbol)[source]¶ Get info about all open orders
Parameters: symbol (str) – required order = client.get_open_orders('eth_btc')
Returns: API response { "result": true, "orders": [ { "amount": 0.1, "avg_price": 0, # average transaction price "create_date": 1418008467000, # order time "deal_amount": 0, # filled quantity "order_id": 10000591, # order id "price": 500, # entrustment price "status": 0, # 0 = unfilled, 1 = partially filled, 2 = fully filled, 10 = cancelled "symbol": "btc_usd", "type": "sell" }, { "amount": 0.2, "avg_price": 0, "create_date": 1417417957000, "deal_amount": 0, "order_id": 10000724, "price": 0.1, "status": 0, "symbol": "btc_usd", "type": "buy" } ] }
Raises: AllcoinResponseException, BinanceAPIException
-
get_orders
(symbol, order_status, order_ids)[source]¶ Get info about multiple orders
Parameters: - symbol (str) – required
- order_status (int) – 0 for unfilled orders; 1 for filled orders
- order_ids (str) – order IDs to fetch (multiple orders are separated by ‘,’, 50 orders at most are allowed per request)
order = client.get_orders('eth_btc', 1)
Returns: API response { "result": true, "orders": [ { "amount": 0.1, "avg_price": 0, # average transaction price "create_date": 1418008467000, # order time "deal_amount": 0, # filled quantity "order_id": 10000591, # order id "price": 500, # entrustment price "status": 0, # 0 = unfilled, 1 = partially filled, 2 = fully filled, 10 = cancelled "symbol": "btc_usd", "type": "sell" }, { "amount": 0.2, "avg_price": 0, "create_date": 1417417957000, "deal_amount": 0, "order_id": 10000724, "price": 0.1, "status": 0, "symbol": "btc_usd", "type": "buy" } ] }
Raises: AllcoinResponseException, BinanceAPIException
-
get_order_history
(symbol, order_status, page=1, limit=200)[source]¶ Get history of orders for a symbol
Parameters: - symbol (str) – required
- order_status (int) – 0 for unfilled orders; 1 for filled orders
- page (int) – page to fetch
- limit (int) – amount on each page
order = client.get_order_history('eth_btc', 1)
Returns: API response [ { "current_page": 1, "orders": [ { "amount": 0, "avg_price": 0, "create_date": 1405562100000, "deal_amount": 0, "order_id": 0, "price": 0, "status": 2, "symbol": "btc_usd", "type": "sell” } ], "page_length": 1, "result": true, "total": 3 } ]
Raises: AllcoinResponseException, BinanceAPIException
-
exceptions module¶
-
exception
allcoin.exceptions.
AllcoinAPIException
(response)[source]¶ Bases:
exceptions.Exception
-
CODES
= {'10006': "User doesn't exist", '10007': 'Signature does not match', '10000': 'Required field, can not be null', '10001': 'Request too frequently', '10002': 'System error', '10008': 'Illegal parameter', '10009': 'Order does not exist', '10028': 'The order has been completed and cannot be cancelled', '10029': 'Users are not authorized to do the operation', '10026': 'Fail to get the info of the trading zone', '10027': 'Your order is revoked, please do not repeat the operation', '10025': 'Wrong order number', '10022': 'Trading zone is closed', '10023': 'Order quantity is out of the time limit', '10031': 'The price has exceeded the daily limitation.', '10030': 'System is under maintaince', '10032': 'The currency purchase has been suspended.', '10019': 'Blacklist user', '10018': 'Out of the valid trading time', '10013': 'Order price is out of range', '10012': 'Only support https request', '10010': 'Insufficient funds', '10017': 'The specified currency does not exist', '10016': 'Failed to get latest transaction price', '10033': 'The currency sale has been suspended.', '10014': 'Insufficient coins quantity', '10034': 'Pass KYC level 1 to continue'}¶
-