本文主要是介绍3.8 Binance_interface APP U本位合约交易-市价单开仓,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Binance_interface APP U本位合约交易-市价单开仓
- Github地址
- PyTed量化交易研究院
量化交易研究群(VX) = py_ted
目录
- Binance_interface APP U本位合约交易-市价单开仓
- 1. APP U本位合约交易-市价单开仓函数总览
- 2. 模型实例化
- 3. 同步 市价开仓
- 4. 同步 市价开仓 回调函数
- 5. 异步 市价开仓(购买)回调函数
1. APP U本位合约交易-市价单开仓函数总览
方法 | 解释 |
---|---|
open_market | 市价单开仓 |
2. 模型实例化
from binance_interface.app import BinanceUM
from pprint import pprint
# 转发:需搭建转发服务器,可参考:https://github.com/pyted/binance_resender
proxy_host = None
key = 'xxxx'
secret = 'xxxx'binanceUM = BinanceUM(key=key, secret=secret,proxy_host=proxy_host
)
trade = binanceUM.trade
3. 同步 市价开仓
open_market3 = trade.open_market(symbol='MANAUSDT', # 产品marginType='ISOLATED', # 保证金模式 ISOLATED: 逐仓 CROSSED: 全仓positionSide='LONG', # 持仓方向 LONG: 多单 SHORT: 空单leverage=1, # 杠杆openMoney=6, # 开仓金额 开仓金额openMoney和开仓数量quantity必须输入其中一个 优先级:quantity > openMoney# quantity=10, # 开仓数量newClientOrderId='', # 客户自定义订单ID
)pprint(open_market3)
输出:
>>> {'cancel_result': None,
>>> 'error_result': None,
>>> 'func_param': {'callback': None,
>>> 'cancel': True,
>>> 'delay': 0.2,
>>> 'errorback': None,
>>> 'leverage': 1,
>>> 'marginType': 'ISOLATED',
>>> 'meta': {},
>>> 'newClientOrderId': '',
>>> 'newThread': False,
>>> 'openMoney': 6,
>>> 'positionSide': 'LONG',
>>> 'quantity': None,
>>> 'symbol': 'MANAUSDT',
>>> 'timeout': 60},
>>> 'get_order_result': {'code': 200,
>>> 'data': {'avgPrice': '0.4357',
>>> 'clientOrderId': 'VEGnPtserZmP6tGb2C2cNU',
>>> 'closePosition': False,
>>> 'cumQuote': '5.6641',
>>> 'executedQty': '13',
>>> 'goodTillDate': 0,
>>> 'orderId': 10508452871,
>>> 'origQty': '13',
>>> 'origType': 'MARKET',
>>> 'positionSide': 'LONG',
>>> 'price': '0.0000',
>>> 'priceMatch': 'NONE',
>>> 'priceProtect': False,
>>> 'reduceOnly': False,
>>> 'selfTradePreventionMode': 'NONE',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'stopPrice': '0.0000',
>>> 'symbol': 'MANAUSDT',
>>> 'time': 1706119677559,
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706119677559,
>>> 'workingType': 'CONTRACT_PRICE'},
>>> 'msg': ''},
>>> 'meta': {},
>>> 'request_param': {'newClientOrderId': '',
>>> 'positionSide': 'LONG',
>>> 'quantity': '13',
>>> 'side': 'BUY',
>>> 'symbol': 'MANAUSDT',
>>> 'type': 'MARKET'},
>>> 'set_order_result': {'code': 200,
>>> 'data': {'avgPrice': '0.00',
>>> 'clientOrderId': 'VEGnPtserZmP6tGb2C2cNU',
>>> 'closePosition': False,
>>> 'cumQty': '0',
>>> 'cumQuote': '0.0000',
>>> 'executedQty': '0',
>>> 'goodTillDate': 0,
>>> 'orderId': 10508452871,
>>> 'origQty': '13',
>>> 'origType': 'MARKET',
>>> 'positionSide': 'LONG',
>>> 'price': '0.0000',
>>> 'priceMatch': 'NONE',
>>> 'priceProtect': False,
>>> 'reduceOnly': False,
>>> 'selfTradePreventionMode': 'NONE',
>>> 'side': 'BUY',
>>> 'status': 'NEW',
>>> 'stopPrice': '0.0000',
>>> 'symbol': 'MANAUSDT',
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706119677559,
>>> 'workingType': 'CONTRACT_PRICE'},
>>> 'msg': ''},
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT'}
4. 同步 市价开仓 回调函数
# 执行成功回调
def callback4(information):print('callback')pprint(information)# 执行错误回调
def errorback4(information):print('errorback')pprint(information)
# 设置callback与errorback
open_market4 = trade.open_market(symbol='MANAUSDT', # 产品marginType='ISOLATED', # 保证金模式 ISOLATED: 逐仓 CROSSED: 全仓positionSide='LONG', # 持仓方向 LONG: 多单 SHORT: 空单leverage=1, # 杠杆openMoney=6, # 开仓金额 开仓金额openMoney和开仓数量quantity必须输入其中一个 优先级:quantity > openMoney# quantity=10, # 开仓数量newClientOrderId='', # 客户自定义订单IDmeta={}, # 向回调函数中传递的参数字典callback=callback4, # 开仓成功触发的回调函数errorback=errorback4, # 开仓失败触发的回调函数
)
输出:
>>> callback
>>> {'cancel_result': None,
>>> 'error_result': None,
>>> 'func_param': {'callback': <function callback4 at 0x7ffa90d90310>,
>>> 'cancel': True,
>>> 'delay': 0.2,
>>> 'errorback': <function errorback4 at 0x7ffa90d904c0>,
>>> 'leverage': 1,
>>> 'marginType': 'ISOLATED',
>>> 'meta': {},
>>> 'newClientOrderId': '',
>>> 'newThread': False,
>>> 'openMoney': 6,
>>> 'positionSide': 'LONG',
>>> 'quantity': None,
>>> 'symbol': 'MANAUSDT',
>>> 'timeout': 60},
>>> 'get_order_result': {'code': 200,
>>> 'data': {'avgPrice': '0.4361',
>>> 'clientOrderId': 'fGe4T84DVt1YuyQwc0VwtJ',
>>> 'closePosition': False,
>>> 'cumQuote': '5.6693',
>>> 'executedQty': '13',
>>> 'goodTillDate': 0,
>>> 'orderId': 10508454794,
>>> 'origQty': '13',
>>> 'origType': 'MARKET',
>>> 'positionSide': 'LONG',
>>> 'price': '0.0000',
>>> 'priceMatch': 'NONE',
>>> 'priceProtect': False,
>>> 'reduceOnly': False,
>>> 'selfTradePreventionMode': 'NONE',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'stopPrice': '0.0000',
>>> 'symbol': 'MANAUSDT',
>>> 'time': 1706119692354,
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706119692354,
>>> 'workingType': 'CONTRACT_PRICE'},
>>> 'msg': ''},
>>> 'meta': {},
>>> 'request_param': {'newClientOrderId': '',
>>> 'positionSide': 'LONG',
>>> 'quantity': '13',
>>> 'side': 'BUY',
>>> 'symbol': 'MANAUSDT',
>>> 'type': 'MARKET'},
>>> 'set_order_result': {'code': 200,
>>> 'data': {'avgPrice': '0.00',
>>> 'clientOrderId': 'fGe4T84DVt1YuyQwc0VwtJ',
>>> 'closePosition': False,
>>> 'cumQty': '0',
>>> 'cumQuote': '0.0000',
>>> 'executedQty': '0',
>>> 'goodTillDate': 0,
>>> 'orderId': 10508454794,
>>> 'origQty': '13',
>>> 'origType': 'MARKET',
>>> 'positionSide': 'LONG',
>>> 'price': '0.0000',
>>> 'priceMatch': 'NONE',
>>> 'priceProtect': False,
>>> 'reduceOnly': False,
>>> 'selfTradePreventionMode': 'NONE',
>>> 'side': 'BUY',
>>> 'status': 'NEW',
>>> 'stopPrice': '0.0000',
>>> 'symbol': 'MANAUSDT',
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706119692354,
>>> 'workingType': 'CONTRACT_PRICE'},
>>> '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', # 产品marginType='ISOLATED', # 保证金模式 ISOLATED: 逐仓 CROSSED: 全仓positionSide='LONG', # 持仓方向 LONG: 多单 SHORT: 空单leverage=1, # 杠杆openMoney=6, # 开仓金额 开仓金额openMoney和开仓数量quantity必须输入其中一个 优先级:quantity > openMoney# quantity=10, # 开仓数量newClientOrderId='', # 客户自定义订单IDcallback=callback5, # 开仓成功触发的回调函数errorback=errorback5, # 开仓失败触发的回调函数newThread=True, # 是否开启一个新的线程维护这个订单
)print(open_market5)
print('-' * 30)
输出:
>>> <Thread(Thread-5, started 123145671073792)>
>>> ------------------------------
>>> thread callback
>>> {'cancel_result': None,
>>> 'error_result': None,
>>> 'func_param': {'callback': <function callback5 at 0x7ffa90d90160>,
>>> 'cancel': True,
>>> 'delay': 0.2,
>>> 'errorback': <function errorback5 at 0x7ffa90d90280>,
>>> 'leverage': 1,
>>> 'marginType': 'ISOLATED',
>>> 'meta': {},
>>> 'newClientOrderId': '',
>>> 'newThread': True,
>>> 'openMoney': 6,
>>> 'positionSide': 'LONG',
>>> 'quantity': None,
>>> 'symbol': 'MANAUSDT',
>>> 'timeout': 60},
>>> 'get_order_result': {'code': 200,
>>> 'data': {'avgPrice': '0.4359',
>>> 'clientOrderId': 'kD4pOQc6B8uVdHLqfMel7O',
>>> 'closePosition': False,
>>> 'cumQuote': '5.6667',
>>> 'executedQty': '13',
>>> 'goodTillDate': 0,
>>> 'orderId': 10508455394,
>>> 'origQty': '13',
>>> 'origType': 'MARKET',
>>> 'positionSide': 'LONG',
>>> 'price': '0.0000',
>>> 'priceMatch': 'NONE',
>>> 'priceProtect': False,
>>> 'reduceOnly': False,
>>> 'selfTradePreventionMode': 'NONE',
>>> 'side': 'BUY',
>>> 'status': 'FILLED',
>>> 'stopPrice': '0.0000',
>>> 'symbol': 'MANAUSDT',
>>> 'time': 1706119698669,
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706119698669,
>>> 'workingType': 'CONTRACT_PRICE'},
>>> 'msg': ''},
>>> 'meta': {},
>>> 'request_param': {'newClientOrderId': '',
>>> 'positionSide': 'LONG',
>>> 'quantity': '13',
>>> 'side': 'BUY',
>>> 'symbol': 'MANAUSDT',
>>> 'type': 'MARKET'},
>>> 'set_order_result': {'code': 200,
>>> 'data': {'avgPrice': '0.00',
>>> 'clientOrderId': 'kD4pOQc6B8uVdHLqfMel7O',
>>> 'closePosition': False,
>>> 'cumQty': '0',
>>> 'cumQuote': '0.0000',
>>> 'executedQty': '0',
>>> 'goodTillDate': 0,
>>> 'orderId': 10508455394,
>>> 'origQty': '13',
>>> 'origType': 'MARKET',
>>> 'positionSide': 'LONG',
>>> 'price': '0.0000',
>>> 'priceMatch': 'NONE',
>>> 'priceProtect': False,
>>> 'reduceOnly': False,
>>> 'selfTradePreventionMode': 'NONE',
>>> 'side': 'BUY',
>>> 'status': 'NEW',
>>> 'stopPrice': '0.0000',
>>> 'symbol': 'MANAUSDT',
>>> 'timeInForce': 'GTC',
>>> 'type': 'MARKET',
>>> 'updateTime': 1706119698669,
>>> 'workingType': 'CONTRACT_PRICE'},
>>> 'msg': ''},
>>> 'status': 'FILLED',
>>> 'symbol': 'MANAUSDT'}
这篇关于3.8 Binance_interface APP U本位合约交易-市价单开仓的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!