def make_order(self, my_order_info): logger.info( u'\n-------------------------------------------spot order------------------------------------------------' ) try: result = self.API.send_order(self.ACCOUNT_ID, my_order_info.amount, my_order_info.symbol, my_order_info.orderType, my_order_info.price, my_order_info.offset) except Exception as e: logger.error("***send_order:{}".format(e, traceback.format_exc())) send_msg("%s:send_order failed:%s" % (my_order_info.symbol, e)) exit() result = self.check_order_list(my_order_info) if result is not None and result.get('status') == 'ok': logger_join("OrderId", result['data'], my_order_info.symbol, my_order_info.orderType, my_order_info.price, my_order_info.amount, " ", from_time_stamp()) return result['data'] else: logger_join("order failed!", my_order_info.symbol, my_order_info.orderType, my_order_info.price, my_order_info.amount) return "-1"
def send_order(acct_id, amount, symbol, _type, price=0, offset="close"): """ :param acct_id: :param amount: :param symbol: :param _type: 可选值 {buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖} :param price: :param offset: :return: """ # 合约下单 order_price_type = "limit" direction = _type.split("-")[0] contract_code = contract_info.get_contract_code(symbol) contract_symbol = symbol.split("_")[0].upper() contract_type = global_type # sell_offset = "open" if price > 4 else "close" # buy_offset = "close" if price > 4 else "open" # offset = sell_offset if direction == "sell" else buy_offset lever_rate = TRADE_LEVEL def send_contract_order(symbol, contract_type, contract_code, client_order_id, price, volume, direction, offset, lever_rate, order_price_type): """ :symbol: "BTC","ETH".. :contract_type: "this_week", "next_week", "next_quarter" :contract_code: "BTC181228" :client_order_id: 客户自己填写和维护,这次一定要大于上一次 :price 必填 价格 :volume 必填 委托数量(张) :direction 必填 "buy" "sell" :offset 必填 "open", "close" :lever_rate 必填 杠杆倍数 :order_price_type 必填 "limit"限价, "opponent" 对手价 备注:如果contract_code填了值,那就按照contract_code去下单,如果contract_code没有填值,则按照symbol+contract_type去下单。 : """ params = { "price": price, "volume": volume, "direction": direction, "offset": offset, "lever_rate": lever_rate, "order_price_type": order_price_type } if symbol: params["symbol"] = symbol if contract_type: params['contract_type'] = contract_type if contract_code: params['contract_code'] = contract_code if client_order_id: params['client_order_id'] = client_order_id request_path = '/api/v1/contract_order' return api_key_post(params, request_path, CONTRACT_URL) # amount = math.ceil(amount * price / 10) amount = math.ceil(amount) if math.ceil(security.get_volume()) <= TRADE_LIMIT: result = send_contract_order(contract_symbol, contract_type, contract_code, "", price, amount, direction, offset, lever_rate, order_price_type) logger.info(result) order_symbol[str(result["data"]["order_id"])] = contract_symbol if "ok" == result["status"]: if direction == "buy": security.open(amount) else: security.close(amount) # order_ts[result["data"]["order_id"]] = result["ts"] return { "data": str(result["data"]["order_id"]), "status": result["status"] } else: from module.Notification import send_msg send_msg("amount:{} volume:{} limit:{}".format(amount, security.get_volume(), TRADE_LIMIT)) exit() return {"data": [], "status": "ok"}