方法 | 解释 | Path |
---|---|---|
get_account | 账户信息 | /api/v3/account |
get_myTrades | 账户成交历史 | /api/v3/myTrades |
get_rateLimit_order | 查询目前下单数 | /api/v3/rateLimit/order |
get_myPreventedMatches | 获取 Prevented Matches | /api/v3/myPreventedMatches |
get_myAllocations | 查询分配结果 | /api/v3/myAllocations |
get_account_commission | 查询佣金费率 | /api/v3/account/commission |
方法 | 解释 | Path |
---|---|---|
set_order_test | 测试下单 | /api/v3/order/test |
set_order | 下单 | /api/v3/order |
cancel_order | 撤销订单 | /api/v3/order |
cancel_openOrders | 撤销单一交易对的所有挂单 | /api/v3/openOrders |
set_order_cancelReplace | 撤消挂单再下单 | /api/v3/order/cancelReplace |
get_order | 查询订单 | /api/v3/order |
get_openOrders | 当前挂单 | /api/v3/openOrders |
get_allOrders | 查询所有订单 | /api/v3/allOrders |
set_order_oco | OCO下单 | /api/v3/order/oco |
cancel_orderList | 取消 OCO 订单 | /api/v3/orderList |
get_orderList | 查询 OCO | /api/v3/orderList |
get_allOrderList | 查询所有 OCO | /api/v3/allOrderList |
get_openOrderList | 查询 OCO 挂单 | /api/v3/openOrderList |
set_sor_order | 下 SOR 订单 | /api/v3/sor/order |
set_sor_order_test | 测试 SOR 下单接口 (TRADE) | /api/v3/sor/order/test |
from binance_interface.api import SPOT
from binance_interface.app.utils import eprint
# 转发:需搭建转发服务器,可参考:https://github.com/pyted/binance_resender
proxy_host = None
key = 'xxxx'
secret = 'xxxx'
spot = SPOT(
key=key, secret=secret,
proxy_host=proxy_host
)
account = spot.account
trade = spot.trade
account_result = account.get_account()
eprint(account_result)
输出:
>>> {'code': 200,
>>> 'data': {'makerCommission': 10,
>>> 'takerCommission': 10,
>>> 'buyerCommission': 0,
>>> 'sellerCommission': 0,
>>> 'commissionRates': {'maker': '0.00100000',
>>> 'taker': '0.00100000',
>>> 'buyer': '0.00000000',
>>> 'seller': '0.00000000'},
>>> 'canTrade': True,
>>> 'canWithdraw': True,
>>> 'canDeposit': True,
>>> 'brokered': False,
>>> 'requireSelfTradePrevention': False,
>>> 'preventSor': False,
>>> 'updateTime': 1706192452814,
>>> 'accountType': 'SPOT',
>>> 'balances': [{'asset': 'BTC', 'free': '0.00000000', 'locked': '0.00000000'},
>>> {'asset': 'LTC', 'free': '0.00000000', 'locked': '0.00000000'},
>>> {'asset': 'ETH', 'free': '0.00439560', 'locked': '0.00000000'},
>>> {'asset': 'NEO', 'free': '0.00000000', 'locked': '0.00000000'},
>>> {'asset': 'BNB', 'free': '0.00000000', 'locked': '0.00000000'},
>>> '......'],
>>> 'permissions': ['SPOT'],
>>> 'uid': 459188049},
>>> 'msg': ''}
myTrades_result = account.get_myTrades(symbol='ETHUSDT')
eprint(myTrades_result)
输出:
>>> {'code': 200,
>>> 'data': [{'symbol': 'ETHUSDT',
>>> 'id': 1244422993,
>>> 'orderId': 14965084948,
>>> 'orderListId': -1,
>>> 'price': '2256.00000000',
>>> '...': '......'},
>>> {'symbol': 'ETHUSDT',
>>> 'id': 1259771011,
>>> 'orderId': 15231603125,
>>> 'orderListId': -1,
>>> 'price': '2283.70000000',
>>> '...': '......'},
>>> {'symbol': 'ETHUSDT',
>>> 'id': 1259845830,
>>> 'orderId': 15232742712,
>>> 'orderListId': -1,
>>> 'price': '2288.69000000',
>>> '...': '......'},
>>> {'symbol': 'ETHUSDT',
>>> 'id': 1289453065,
>>> 'orderId': 15715801574,
>>> 'orderListId': -1,
>>> 'price': '2230.99000000',
>>> '...': '......'}],
>>> 'msg': ''}
account_commission_result = account.get_account_commission(symbol='BTCUSDT')
eprint(account_commission_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'BTCUSDT',
>>> 'standardCommission': {'maker': '0.00100000',
>>> 'taker': '0.00100000',
>>> 'buyer': '0.00000000',
>>> 'seller': '0.00000000'},
>>> 'taxCommission': {'maker': '0.00000000',
>>> 'taker': '0.00000000',
>>> 'buyer': '0.00000000',
>>> 'seller': '0.00000000'},
>>> 'discount': {'enabledForAccount': True,
>>> 'enabledForSymbol': True,
>>> 'discountAsset': 'BNB',
>>> 'discount': '0.75000000'}},
>>> 'msg': ''}
set_order_result = trade.set_order(
symbol='MANAUSDT',
price='0.4',
quantity='30',
side='BUY',
type='LIMIT',
timeInForce='GTC',
)
eprint(set_order_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'MANAUSDT',
>>> 'orderId': 2208870980,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'HfMnOen9rke3toOsAxZRg3',
>>> 'transactTime': 1706245628583,
>>> 'price': '0.40000000',
>>> 'origQty': '30.00000000',
>>> 'executedQty': '0.00000000',
>>> 'cummulativeQuoteQty': '0.00000000',
>>> 'status': 'NEW',
>>> 'timeInForce': 'GTC',
>>> 'type': 'LIMIT',
>>> 'side': 'BUY',
>>> 'workingTime': 1706245628583,
>>> 'fills': [],
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>> 'msg': ''}
set_order_result = trade.set_order(
symbol='MANAUSDT',
quantity='15',
side='BUY',
type='MARKET',
)
eprint(set_order_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'MANAUSDT',
>>> 'orderId': 2208871142,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'cMVlAFyHDAS4BcqpxacOxx',
>>> 'transactTime': 1706245648192,
>>> 'price': '0.00000000',
>>> 'origQty': '15.00000000',
>>> 'executedQty': '15.00000000',
>>> 'cummulativeQuoteQty': '6.58200000',
>>> 'status': 'FILLED',
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'side': 'BUY',
>>> 'workingTime': 1706245648192,
>>> 'fills': [{'price': '0.43880000',
>>> 'qty': '15.00000000',
>>> 'commission': '0.01500000',
>>> 'commissionAsset': 'MANA',
>>> 'tradeId': 199546482}],
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>> 'msg': ''}
set_order_result = trade.set_order(
symbol='MANAUSDT',
price='0.8',
quantity='10',
side='SELL',
type='LIMIT',
timeInForce='GTC',
)
eprint(set_order_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'MANAUSDT',
>>> 'orderId': 2208871186,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'JQJOEHsnf31nxtQK7CD0QZ',
>>> 'transactTime': 1706245662898,
>>> 'price': '0.80000000',
>>> 'origQty': '10.00000000',
>>> 'executedQty': '0.00000000',
>>> 'cummulativeQuoteQty': '0.00000000',
>>> 'status': 'NEW',
>>> 'timeInForce': 'GTC',
>>> 'type': 'LIMIT',
>>> 'side': 'SELL',
>>> 'workingTime': 1706245662898,
>>> 'fills': [],
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>> 'msg': ''}
set_order_result = trade.set_order(
symbol='MANAUSDT',
quantity='15',
side='SELL',
type='MARKET',
)
eprint(set_order_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'MANAUSDT',
>>> 'orderId': 2208871525,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'OF0MJsZIR8skLw8mpo09xv',
>>> 'transactTime': 1706245720662,
>>> 'price': '0.00000000',
>>> 'origQty': '15.00000000',
>>> 'executedQty': '15.00000000',
>>> 'cummulativeQuoteQty': '6.57300000',
>>> 'status': 'FILLED',
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'side': 'SELL',
>>> 'workingTime': 1706245720662,
>>> 'fills': [{'price': '0.43820000',
>>> 'qty': '15.00000000',
>>> 'commission': '0.00657300',
>>> 'commissionAsset': 'USDT',
>>> 'tradeId': 199546484}],
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>> 'msg': ''}
openOrderList_result = trade.get_openOrders(symbol='')
eprint(openOrderList_result)
输出:
>>> {'code': 200,
>>> 'data': [{'symbol': 'MANAUSDT',
>>> 'orderId': 2208870980,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'HfMnOen9rke3toOsAxZRg3',
>>> 'price': '0.40000000',
>>> '...': '......'},
>>> {'symbol': 'MANAUSDT',
>>> 'orderId': 2208871186,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'JQJOEHsnf31nxtQK7CD0QZ',
>>> 'price': '0.80000000',
>>> '...': '......'}],
>>> 'msg': ''}
order_result = trade.get_order(
symbol='MANAUSDT',
orderId='2208870980',
)
eprint(order_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'MANAUSDT',
>>> 'orderId': 2208870980,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'HfMnOen9rke3toOsAxZRg3',
>>> 'price': '0.40000000',
>>> 'origQty': '30.00000000',
>>> 'executedQty': '0.00000000',
>>> 'cummulativeQuoteQty': '0.00000000',
>>> 'status': 'NEW',
>>> 'timeInForce': 'GTC',
>>> 'type': 'LIMIT',
>>> 'side': 'BUY',
>>> 'stopPrice': '0.00000000',
>>> 'icebergQty': '0.00000000',
>>> 'time': 1706245628583,
>>> 'updateTime': 1706245628583,
>>> 'isWorking': True,
>>> 'workingTime': 1706245628583,
>>> 'origQuoteOrderQty': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>> 'msg': ''}
cancel_order_result = trade.cancel_order(
symbol='MANAUSDT',
orderId='2208870980'
)
eprint(cancel_order_result)
输出:
>>> {'code': 200,
>>> 'data': {'symbol': 'MANAUSDT',
>>> 'origClientOrderId': 'HfMnOen9rke3toOsAxZRg3',
>>> 'orderId': 2208870980,
>>> 'orderListId': -1,
>>> 'clientOrderId': 'C7v6cEUWrVAOsvgJ85vAln',
>>> 'transactTime': 1706245758514,
>>> 'price': '0.40000000',
>>> 'origQty': '30.00000000',
>>> 'executedQty': '0.00000000',
>>> 'cummulativeQuoteQty': '0.00000000',
>>> 'status': 'CANCELED',
>>> 'timeInForce': 'GTC',
>>> 'type': 'LIMIT',
>>> 'side': 'BUY',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER'},
>>> 'msg': ''}
cancel_openOrders_result = trade.cancel_openOrders(symbol='MANAUSDT')
eprint(cancel_openOrders_result)
输出:
>>> {'code': 200,
>>> 'data': [{'symbol': 'MANAUSDT',
>>> 'origClientOrderId': 'JQJOEHsnf31nxtQK7CD0QZ',
>>> 'orderId': 2208871186,
>>> 'orderListId': -1,
>>> 'clientOrderId': '4oJvZysoac8AcPk1SQ798A',
>>> '...': '......'}],
>>> 'msg': ''}