def create_market_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_long_positions(symbol='EOS_USDT'):
"""
平多仓
@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)
return order_response
def close_short_positions(symbol='EOS_USDT'):
"""
平空仓
@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)
return order_response
def up_cross_order(symbol, message=''):
"""
市价开多仓
@param symbol:交易对
@param message: 消息处理
@return:
"""
print('可做多的交易对:' + symbol)
# 获取标的可平多仓
long_closeable_amount = get_long_positions(symbol=symbol)
print('可平多仓:' + str(long_closeable_amount))
# 获取标的可平空仓
short_closeable_amount = get_short_positions(symbol=symbol)
print('可平空仓:' + str(short_closeable_amount))
available_cash = get_available_cash()
print('可用USDT:' + str(available_cash))
if available_cash > 0:
# 如果没有持仓,则直接开多仓;
if (short_closeable_amount == 0) and (long_closeable_amount == 0):
print('Gate.io 市价开多仓: ' + symbol)
create_market_order(symbol=symbol, quantity='1', message=message)
def down_cross_order(symbol, message=''):
"""
市价开空仓
@param symbol:交易对
@param message: 消息处理
@return:
"""
print('可做空的交易对:' + symbol)
# 获取标的可平多仓
long_closeable_amount = get_long_positions(symbol=symbol)
print('可平多仓:' + str(long_closeable_amount))
# 获取标的可平空仓
short_closeable_amount = get_short_positions(symbol=symbol)
print('可平空仓:' + str(short_closeable_amount))
available_cash = get_available_cash()
print('可用USDT:' + str(available_cash))
if available_cash > 0:
# 如果没有持仓,则直接开多仓;
if (short_closeable_amount == 0) and (long_closeable_amount == 0):
print('Gate.io 市价开空仓: ' + symbol)
create_market_order(symbol=symbol, quantity='-1', message=message)