Exemplo n.º 1
0
                        data_btc['volume'], data_btc['price'],
                        data_btc['trade_volume'], data_btc['trade_avg_price'],
                        data_btc['profit'], data_btc['fee'], data_btc['status']
                    ]  # 交易数据表头
                    trade_change_number = data_btc['trade_volume']
                    # 合约 杠杆 委托时间 交易 类型 委托类型 委托量(张) 委托价(USD) 成交量(张) 成交均价(USD)
                    # 收益均价(BTC) 手续费(BTC) 状态
                    with open('%s.csv' % (LogCsvFile), 'a',
                              newline='') as f:  # newline=" "是为了避免写入之后有空行
                        ff = csv.writer(f)
                        ff.writerow(head)
                        f.close()
                        # (1准备提交 2准备提交 3已提交 4部分成交 5部分成交已撤单 6全部成交 7已撤单 11撤单中)
                    print(data_btc['status'], type(data_btc['status']))
                    if data_btc['status'] != 6:
                        Order1 = dm.cancel_contract_order(
                            symbol=symbol_type, order_id=trade_number)
                        if len(Order1['data']['errors']) > 0:
                            for order_error in Order1['data']['errors']:
                                logger.error("撤单失败:%s" % order_error)
                                print("撤单失败:", order_error)
                            continue
                        elif Order1['data']['successes'] == trade_number:

                            BTC_Trade = False
                            logger.error("撤单成功:%s" % trade_number)
                            print("撤单成功:", trade_number)
                            continue
                    elif data_btc['status'] == 4 or data_btc[
                            'status'] == 5 or data_btc['status'] == 7:
                        Already_Judged = False
                        logger.error("下单成功全部成交:%s" % trade_number)
print (u' 合约批量下单 ')
orders_data = {'orders_data': [
               {'symbol': 'BTC', 'contract_type': 'quarter',  
                'contract_code':'BTC181228',  'client_order_id':'', 
                'price':10000, 'volume':1, 'direction':'sell', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'},
               {'symbol': 'BTC','contract_type': 'quarter', 
                'contract_code':'BTC181228', 'client_order_id':'', 
                'price':20000, 'volume':2, 'direction':'sell', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'}]}
pprint(dm.send_contract_batchorder(orders_data))


print (u' 撤销订单 ')
pprint(dm.cancel_contract_order(symbol='BTC', order_id='42652161'))

print (u' 全部撤单 ')
pprint(dm.cancel_all_contract_order(symbol='BTC'))

print (u' 获取合约订单信息 ')
pprint(dm.get_contract_order_info(symbol='BTC', order_id='42652161'))

print (u' 获取合约订单明细信息 ')
pprint(dm.get_contract_order_detail(symbol='BTC', order_id='42652161', order_type=1, created_at=1542097630215))

print (u' 获取合约当前未成交委托 ')
pprint(dm.get_contract_open_orders(symbol='BTC'))

print (u' 获取合约历史委托 ')
pprint (dm.get_contract_history_orders(symbol='BTC', trade_type=0, type=1, status=0, create_date=7))
Exemplo n.º 3
0
print (u' 合约批量下单 ')
orders_data = {'orders_data': [
               {'symbol': 'BTC', 'contract_type': 'quarter',  
                'contract_code':'BTC181228',  'client_order_id':'', 
                'price':1, 'volume':1, 'direction':'buy', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'},
               {'symbol': 'BTC','contract_type': 'quarter', 
                'contract_code':'BTC181228', 'client_order_id':'', 
                'price':2, 'volume':2, 'direction':'buy', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'}]}
pprint(dm.send_contract_batchorder(orders_data))


print (u' 撤销订单 ')
pprint(dm.cancel_contract_order(symbol='BTC', order_id='42652161'))

print (u' 全部撤单 ')
pprint(dm.cancel_all_contract_order(symbol='BTC'))

print (u' 获取合约订单信息 ')
pprint(dm.get_contract_order_info(symbol='BTC', order_id='42652161'))

print (u' 获取合约订单明细信息 ')
pprint(dm.get_contract_order_detail(symbol='BTC', order_id='42652161'))

print (u' 获取合约当前未成交委托 ')
pprint(dm.get_contract_open_orders(symbol='BTC'))

print (u' 获取合约历史委托 ')
pprint (dm.get_contract_history_orders(symbol='BTC', trade_type=0, type=1, status=0, create_date=7))