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': ''}
相关推荐
千澜空2 分钟前
celery在django项目中实现并发任务和定时任务
python·django·celery·定时任务·异步任务
斯凯利.瑞恩9 分钟前
Python决策树、随机森林、朴素贝叶斯、KNN(K-最近邻居)分类分析银行拉新活动挖掘潜在贷款客户附数据代码
python·决策树·随机森林
yannan2019031331 分钟前
【算法】(Python)动态规划
python·算法·动态规划
蒙娜丽宁41 分钟前
《Python OpenCV从菜鸟到高手》——零基础进阶,开启图像处理与计算机视觉的大门!
python·opencv·计算机视觉
光芒再现dev42 分钟前
已解决,部署GPTSoVITS报错‘AsyncRequest‘ object has no attribute ‘_json_response_data‘
运维·python·gpt·语言模型·自然语言处理
好喜欢吃红柚子1 小时前
万字长文解读空间、通道注意力机制机制和超详细代码逐行分析(SE,CBAM,SGE,CA,ECA,TA)
人工智能·pytorch·python·计算机视觉·cnn
小馒头学python1 小时前
机器学习是什么?AIGC又是什么?机器学习与AIGC未来科技的双引擎
人工智能·python·机器学习
神奇夜光杯1 小时前
Python酷库之旅-第三方库Pandas(202)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
千天夜1 小时前
使用UDP协议传输视频流!(分片、缓存)
python·网络协议·udp·视频流
测试界的酸菜鱼1 小时前
Python 大数据展示屏实例
大数据·开发语言·python