十三、区块量化 gate.io 合约操作文件续
def create_order(symbol='EOS_USDT', quantity='1', message=''):
"""
全仓合约市价下单
@param symbol:交易对
@param quantity:委托数量 正数为买入,负数为卖出
@param message: 判断依据
@return:
"""
quantitys = float(quantity)
order = FuturesOrder(contract=symbol, size=quantitys, price="0", tif='ioc', iceberg=0, stp_act='-')
order_response = futures_api.create_futures_order(settle='usdt', futures_order=order)
weixin.senddata('@all', 'Gate.io 市价下单成功,\n 订单ID:' + str(
order_response.id) + '\n 交易对:' + order_response.contract + '\n 委托数量:' + str(quantity) + '\n 判断依据:' + message)
return order_response
def close_positions(symbol='EOS_USDT', message=''):
"""
平仓
@param symbol:交易对
@return:
"""
order = FuturesOrder(contract=symbol, size='0', price="0", tif='ioc', iceberg=0, stp_act='-',close= True)
order_response = futures_api.create_futures_order(settle='usdt', futures_order=order)
weixin.senddata('@all', 'Gate.io 平仓成功,\n 订单ID:' + str(
order_response.id) + '\n 交易对:' + order_response.contract + '\n 判断依据:' + message)
return order_response
def up_cross_order(symbol, message=''):
"""
平空做多
@param symbol:交易对
@param message: 消息处理
@return:
"""
print('可做多的交易对:' + symbol)
# 获取标的可平多仓
long_position = get_long_positions(symbol=symbol)
print('可平多仓:' + str(long_position))
# 获取标的可平空仓
short_position = get_short_positions(symbol=symbol)
print('可平空仓:' + str(short_position))
if (long_position + short_position) > 5:
print('持仓数最多5个')
return
free_money = get_available_cash('USDT')
print('可用USDT:' + str(free_money))
if free_money > 0:
# 如果当时持有空仓,则先平仓,再开多仓;
if short_position != 0:
print('Gate.io 如果当时持有空仓,则先平仓,再开多仓;' + symbol)
close_positions(symbol=symbol