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': ''}
相关推荐
Kai HVZ1 小时前
python爬虫----爬取视频实战
爬虫·python·音视频
古希腊掌管学习的神1 小时前
[LeetCode-Python版]相向双指针——611. 有效三角形的个数
开发语言·python·leetcode
m0_748244831 小时前
StarRocks 排查单副本表
大数据·数据库·python
B站计算机毕业设计超人1 小时前
计算机毕业设计PySpark+Hadoop中国城市交通分析与预测 Python交通预测 Python交通可视化 客流量预测 交通大数据 机器学习 深度学习
大数据·人工智能·爬虫·python·机器学习·课程设计·数据可视化
路人甲ing..1 小时前
jupyter切换内核方法配置问题总结
chrome·python·jupyter
游客5201 小时前
opencv中的常用的100个API
图像处理·人工智能·python·opencv·计算机视觉
每天都要学信号2 小时前
Python(第一天)
开发语言·python
凡人的AI工具箱2 小时前
每天40分玩转Django:Django国际化
数据库·人工智能·后端·python·django·sqlite
咸鱼桨2 小时前
《庐山派从入门到...》PWM板载蜂鸣器
人工智能·windows·python·k230·庐山派
北京_宏哥2 小时前
python接口自动化(四十)- logger 日志 - 下(超详解)
python·前端框架·自动化运维