本文主要是介绍2.8 Binance_interface APP 现货交易-市价单开仓,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Binance_interface APP 现货交易-市价单开仓
- Github地址
- PyTed量化交易研究院
目录
- Binance_interface APP 现货交易-市价单开仓
- 1. APP 现货交易-市价单开仓函数总览
- 2. 模型实例化
- 3. 同步 市价开仓(购买)
- 4. 同步 市价开仓(购买) 回调函数
- 5. 异步 市价开仓(购买)回调函数
1. APP 现货交易-市价单开仓函数总览
方法 | 解释 |
---|---|
open_market | 市价单购买 |
2. 模型实例化
from binance_interface.app import BinanceSPOT
from pprint import pprint
# 转发:需搭建转发服务器,可参考:https://github.com/pyted/binance_resender
proxy_host = None
key = 'xxxx'
secret = 'xxxx'binanceSPOT = BinanceSPOT(key=key, secret=secret,proxy_host=proxy_host
)
trade = binanceSPOT.trade
3. 同步 市价开仓(购买)
open_market3 = trade.open_market(symbol='MANAUSDT', # 产品openMoney=6, # 开仓金额 开仓金额openMoney和开仓数量quantity必须输入其中一个 优先级:quantity > openMoney# quantity=10, # 开仓数量meta={}, # 向回调函数中传递的参数字典
)pprint(open_market3)
输出:
>>> {'cancel_result': None,
>>> 'error_result': None,
>>> 'func_param': {'callback': None,
>>> 'cancel': True,
>>> 'delay': 0.2,
>>> 'errorback': None,
>>> 'meta': {},
>>> 'newClientOrderId': '',
>>> 'newThread': False,
>>> 'openMoney': 6,
>>> 'quantity': None,
>>> 'symbol': 'MANAUSDT',
>>> 'timeout': 60},
>>> 'get_order_result': {'code': 200,
>>> 'data': {'clientOrderId': 'lXNgXG3z9VrOpDz0SvO9Pj',
>>> 'cummulativeQuoteQty': '5.66410000',
>>> 'executedQty': '13.00000000',
>>> 'icebergQty': '0.00000000',
>>> 'isWorking': True,
>>> 'orderId': 2207177037,
>>> 'orderListId': -1,
>>> 'origQty': '13.00000000',
>>> 'origQuoteOrderQty': '0.00000000',
>>> 'price': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'stopPrice': '0.00000000',
>>> 'symbol': 'MANAUSDT',
>>> 'time': 1706105326869,
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706105326869,
>>> 'workingTime': 1706105326869},
>>> 'msg': ''},
>>> 'meta': {},
>>> 'request_param': {'newClientOrderId': '',
>>> 'quantity': '13',
>>> 'side': 'BUY',
>>> 'symbol': 'MANAUSDT',
>>> 'type': 'MARKET'},
>>> 'set_order_result': {'code': 200,
>>> 'data': {'clientOrderId': 'lXNgXG3z9VrOpDz0SvO9Pj',
>>> 'cummulativeQuoteQty': '5.66410000',
>>> 'executedQty': '13.00000000',
>>> 'fills': [{'commission': '0.01300000',
>>> 'commissionAsset': 'MANA',
>>> 'price': '0.43570000',
>>> 'qty': '13.00000000',
>>> 'tradeId': 199517066}],
>>> 'orderId': 2207177037,
>>> 'orderListId': -1,
>>> 'origQty': '13.00000000',
>>> 'price': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT',
>>> 'timeInForce': 'GTC',
>>> 'transactTime': 1706105326869,
>>> 'type': 'MARKET',
>>> 'workingTime': 1706105326869},
>>> 'msg': ''},
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT'}
4. 同步 市价开仓(购买) 回调函数
# 执行成功回调
def callback4(information):print('callback')pprint(information)# 执行错误回调
def errorback4(information):print('errorback')pprint(information)
open_market4 = trade.open_market(symbol='MANAUSDT', # 产品openMoney=6, # 开仓金额 开仓金额openMoney和开仓数量quantity必须输入其中一个 优先级:quantity > openMoney# quantity=10, # 开仓数量meta={}, # 向回调函数中传递的参数字典callback=callback4, # 开仓成功触发的回调函数errorback=errorback4, # 开仓失败触发的回调函数
)
输出:
>>> callback
>>> {'cancel_result': None,
>>> 'error_result': None,
>>> 'func_param': {'callback': <function callback4 at 0x7fc479839820>,
>>> 'cancel': True,
>>> 'delay': 0.2,
>>> 'errorback': <function errorback4 at 0x7fc4798398b0>,
>>> 'meta': {},
>>> 'newClientOrderId': '',
>>> 'newThread': False,
>>> 'openMoney': 6,
>>> 'quantity': None,
>>> 'symbol': 'MANAUSDT',
>>> 'timeout': 60},
>>> 'get_order_result': {'code': 200,
>>> 'data': {'clientOrderId': 'da4TEnGdjUMIdFtpay6Nw6',
>>> 'cummulativeQuoteQty': '5.66670000',
>>> 'executedQty': '13.00000000',
>>> 'icebergQty': '0.00000000',
>>> 'isWorking': True,
>>> 'orderId': 2207177902,
>>> 'orderListId': -1,
>>> 'origQty': '13.00000000',
>>> 'origQuoteOrderQty': '0.00000000',
>>> 'price': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'stopPrice': '0.00000000',
>>> 'symbol': 'MANAUSDT',
>>> 'time': 1706105352138,
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706105352138,
>>> 'workingTime': 1706105352138},
>>> 'msg': ''},
>>> 'meta': {},
>>> 'request_param': {'newClientOrderId': '',
>>> 'quantity': '13',
>>> 'side': 'BUY',
>>> 'symbol': 'MANAUSDT',
>>> 'type': 'MARKET'},
>>> 'set_order_result': {'code': 200,
>>> 'data': {'clientOrderId': 'da4TEnGdjUMIdFtpay6Nw6',
>>> 'cummulativeQuoteQty': '5.66670000',
>>> 'executedQty': '13.00000000',
>>> 'fills': [{'commission': '0.01300000',
>>> 'commissionAsset': 'MANA',
>>> 'price': '0.43590000',
>>> 'qty': '13.00000000',
>>> 'tradeId': 199517089}],
>>> 'orderId': 2207177902,
>>> 'orderListId': -1,
>>> 'origQty': '13.00000000',
>>> 'price': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT',
>>> 'timeInForce': 'GTC',
>>> 'transactTime': 1706105352138,
>>> 'type': 'MARKET',
>>> 'workingTime': 1706105352138},
>>> 'msg': ''},
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT'}
5. 异步 市价开仓(购买)回调函数
# 执行成功回调
def callback5(information):print('thread callback')pprint(information)# 执行错误回调
def errorback5(information):print('thread errorback')pprint(information)
# 设置newThread=True
open_market5 = trade.open_market(symbol='MANAUSDT', # 产品# openMoney=6, # 开仓金额 开仓金额openMoney和开仓数量quantity必须输入其中一个 优先级:quantity > openMoneyquantity=15, # 开仓数量callback=callback5, # 开仓成功触发的回调函数errorback=errorback5, # 开仓失败触发的回调函数meta={}, # 向回调函数中传递的参数字典newThread=True, # 是否开启一个新的线程维护这个订单
)print(open_market5)
print('-' * 30)
输出:
>>> <Thread(Thread-5, started 123145550364672)>
>>> ------------------------------
>>> thread callback
>>> {'cancel_result': None,
>>> 'error_result': None,
>>> 'func_param': {'callback': <function callback5 at 0x7ff8f0e3e940>,
>>> 'cancel': True,
>>> 'delay': 0.2,
>>> 'errorback': <function errorback5 at 0x7ff8f0e58430>,
>>> 'meta': {},
>>> 'newClientOrderId': '',
>>> 'newThread': True,
>>> 'openMoney': None,
>>> 'quantity': 15,
>>> 'symbol': 'MANAUSDT',
>>> 'timeout': 60},
>>> 'get_order_result': {'code': 200,
>>> 'data': {'clientOrderId': 'Eud32WLIJbpkrBBLdgnPPf',
>>> 'cummulativeQuoteQty': '6.53250000',
>>> 'executedQty': '15.00000000',
>>> 'icebergQty': '0.00000000',
>>> 'isWorking': True,
>>> 'orderId': 2207180344,
>>> 'orderListId': -1,
>>> 'origQty': '15.00000000',
>>> 'origQuoteOrderQty': '0.00000000',
>>> 'price': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'stopPrice': '0.00000000',
>>> 'symbol': 'MANAUSDT',
>>> 'time': 1706105471010,
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706105471010,
>>> 'workingTime': 1706105471010},
>>> 'msg': ''},
>>> 'meta': {},
>>> 'request_param': {'newClientOrderId': '',
>>> 'quantity': '15',
>>> 'side': 'BUY',
>>> 'symbol': 'MANAUSDT',
>>> 'type': 'MARKET'},
>>> 'set_order_result': {'code': 200,
>>> 'data': {'clientOrderId': 'Eud32WLIJbpkrBBLdgnPPf',
>>> 'cummulativeQuoteQty': '6.53250000',
>>> 'executedQty': '15.00000000',
>>> 'fills': [{'commission': '0.01500000',
>>> 'commissionAsset': 'MANA',
>>> 'price': '0.43550000',
>>> 'qty': '15.00000000',
>>> 'tradeId': 199517126}],
>>> 'orderId': 2207180344,
>>> 'orderListId': -1,
>>> 'origQty': '15.00000000',
>>> 'price': '0.00000000',
>>> 'selfTradePreventionMode': 'EXPIRE_MAKER',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT',
>>> 'timeInForce': 'GTC',
>>> 'transactTime': 1706105471010,
>>> 'type': 'MARKET',
>>> 'workingTime': 1706105471010},
>>> 'msg': ''},
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT'}
这篇关于2.8 Binance_interface APP 现货交易-市价单开仓的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!