1.6 Binance_interface API 现货交易账户

Binance_interface API 现货交易账户

1. API 现货交易账户接口总览

1.1 现货账户接口

方法 解释 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

1.2 现货交易接口

方法 解释 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

2. 模型实例化

python 复制代码
from binance_interface.api import SPOT
from binance_interface.app.utils import eprint
python 复制代码
# 转发:需搭建转发服务器,可参考: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

3. 账户相关

3.1 账户信息 get_account

python 复制代码
account_result = account.get_account()
eprint(account_result)

输出:

text 复制代码
>>> {'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': ''}

3.2 账户成交历史 get_myTrades

python 复制代码
myTrades_result = account.get_myTrades(symbol='ETHUSDT')
eprint(myTrades_result)

输出:

text 复制代码
>>> {'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': ''}

3.3 查询佣金费率 account_commission_result

python 复制代码
account_commission_result = account.get_account_commission(symbol='BTCUSDT')
eprint(account_commission_result)

输出:

text 复制代码
>>> {'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': ''}

4. 交易相关

4.1 下单 set_order

4.1.1 现货限单价购买
python 复制代码
set_order_result = trade.set_order(
    symbol='MANAUSDT',
    price='0.4',
    quantity='30',
    side='BUY',
    type='LIMIT',
    timeInForce='GTC',
)
eprint(set_order_result)

输出:

text 复制代码
>>> {'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': ''}
4.1.2 现货市单价购买
python 复制代码
set_order_result = trade.set_order(
    symbol='MANAUSDT',
    quantity='15',
    side='BUY',
    type='MARKET',
)
eprint(set_order_result)

输出:

text 复制代码
>>> {'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': ''}
4.1.3 现货限单价卖出
python 复制代码
set_order_result = trade.set_order(
    symbol='MANAUSDT',
    price='0.8',
    quantity='10',
    side='SELL',
    type='LIMIT',
    timeInForce='GTC',
)
eprint(set_order_result)

输出:

text 复制代码
>>> {'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': ''}
4.1.4 现货市单价卖出
python 复制代码
set_order_result = trade.set_order(
    symbol='MANAUSDT',
    quantity='15',
    side='SELL',
    type='MARKET',
)
eprint(set_order_result)

输出:

text 复制代码
>>> {'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': ''}

4.2 当前挂单 get_openOrders

python 复制代码
openOrderList_result = trade.get_openOrders(symbol='')
eprint(openOrderList_result)

输出:

text 复制代码
>>> {'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': ''}

4.3 查询订单 get_order

python 复制代码
order_result = trade.get_order(
    symbol='MANAUSDT',
    orderId='2208870980',
)
eprint(order_result)

输出:

text 复制代码
>>> {'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': ''}

4.3 撤销订单 cancel_order

python 复制代码
cancel_order_result = trade.cancel_order(
    symbol='MANAUSDT',
    orderId='2208870980'
)
eprint(cancel_order_result)

输出:

text 复制代码
>>> {'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': ''}

4.4 撤销单一交易对的所有挂单 cancel_openOrders

python 复制代码
cancel_openOrders_result = trade.cancel_openOrders(symbol='MANAUSDT')
eprint(cancel_openOrders_result)

输出:

text 复制代码
>>> {'code': 200,
>>>  'data': [{'symbol': 'MANAUSDT',
>>>            'origClientOrderId': 'JQJOEHsnf31nxtQK7CD0QZ',
>>>            'orderId': 2208871186,
>>>            'orderListId': -1,
>>>            'clientOrderId': '4oJvZysoac8AcPk1SQ798A',
>>>            '...': '......'}],
>>>  'msg': ''}
相关推荐
SEVEN-YEARS3 分钟前
深入理解TensorFlow中的形状处理函数
人工智能·python·tensorflow
EterNity_TiMe_7 分钟前
【论文复现】(CLIP)文本也能和图像配对
python·学习·算法·性能优化·数据分析·clip
Suyuoa19 分钟前
附录2-pytorch yolov5目标检测
python·深度学习·yolo
CertiK28 分钟前
Web3.0安全开发实践:Clarity最佳实践总结
web3·区块链·clarity
加密新世界36 分钟前
Move on Sui入门 004-在sui链上发布Coin合约和Faucet Coin合约
区块链
好看资源平台1 小时前
网络爬虫——综合实战项目:多平台房源信息采集与分析系统
爬虫·python
进击的六角龙2 小时前
深入浅出:使用Python调用API实现智能天气预报
开发语言·python
檀越剑指大厂2 小时前
【Python系列】浅析 Python 中的字典更新与应用场景
开发语言·python
湫ccc2 小时前
Python简介以及解释器安装(保姆级教学)
开发语言·python
孤独且没人爱的纸鹤2 小时前
【深度学习】:从人工神经网络的基础原理到循环神经网络的先进技术,跨越智能算法的关键发展阶段及其未来趋势,探索技术进步与应用挑战
人工智能·python·深度学习·机器学习·ai