当前位置: 首页 > article >正文

1.6 Binance_interface API 现货交易账户

Binance_interface API 现货交易账户

  • Github地址
  • PyTed量化交易研究院

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_ocoOCO下单/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. 模型实例化

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

3. 账户相关

3.1 账户信息 get_account

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': ''}

3.2 账户成交历史 get_myTrades

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': ''}

3.3 查询佣金费率 account_commission_result

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': ''}

4. 交易相关

4.1 下单 set_order

4.1.1 现货限单价购买
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': ''}
4.1.2 现货市单价购买
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': ''}
4.1.3 现货限单价卖出
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': ''}
4.1.4 现货市单价卖出
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': ''}

4.2 当前挂单 get_openOrders

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': ''}

4.3 查询订单 get_order

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': ''}

4.3 撤销订单 cancel_order

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': ''}

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

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': ''}

http://www.kler.cn/a/233953.html

相关文章:

  • python中os.path.isdir()问题
  • 论文阅读 - 《Large Language Models Are Zero-Shot Time Series Forecasters》
  • Educational Codeforces Round 173 (Rated for Div. 2)
  • Idea导入Springboot项目,无法正确加载yml文件,且不为绿色图标的解决办法
  • nlp新词发现——浅析 TF·IDF
  • f(f(x))=x^2 -11x+36, 求f(6)的值,
  • QT+OSG/osgEarth编译之八十二:osgdb_obj+Qt编译(一套代码、一套框架,跨平台编译,版本:OSG-3.6.5插件库osgdb_obj)
  • Mockito测试框架中的方法详解
  • JUnit实践教程——Java的单元测试框架
  • 程序设计语言的组成
  • SAP-PP-01-005工作中心
  • Swift Combine 使用 dataTaskPublisher 发起网络请求 从入门到精通十
  • 2024年腾讯云4核8G12M服务器性能测评,适合哪些使用场景?
  • 【Make编译控制 08】CMake动静态库
  • MySQL进阶查询篇(7)-触发器的创建和使用
  • 【leetcode热题100】 格雷编码
  • 从信息隐藏到功能隐藏
  • 动态水印怎么加 怎么去除动态水印 视频剪辑软件 会声会影安激活序列号 会声会影怎么剪辑视频
  • spring boot(2.4.x之前版本)和spring cloud项目中配置文件的作用
  • Movie review —— The Imitation Game
  • 生成树技术华为ICT网络赛道
  • 滑块识别验证
  • 2、卷积和ReLU激活函数
  • Rust基础拾遗--进阶
  • Linux 命令行的世界 :3.探索操作系统
  • 【心得】关于STM32中RTC的校准方法