def sell(self, amount, price=None, market=bhc.BtccHttpClient.MarketParams.BTC_CNY): """ 挂卖单 :param amount: 卖出量 :param price: 卖出价格, None 为市价卖出 :param market: 卖出货币类型, btcc_http_client.BtccHttpClient.MarketParams :return: Order,如果挂单后获取挂单信息失败,则 Order 只有 Order id """ if price is None: # sell market price resp, status = self.__hc.sell_market(amount=amount, market=market) else: # sell limit price resp, status = self.__hc.sell_limit(price=price, amount=amount, market=market) if status: # 卖单报单成功, 获取挂单状态,初始化order time.sleep(1) order_id = resp resp, status = self.__hc.get_order(order_id=resp) if status: return bm.Order(**resp['order']) else: return bm.Order(id=order_id) else: raise Exception('买单挂单失败')
def get_orders(self, market=bhc.BtccHttpClient.MarketParams.BTC_CNY, open_only=False): resp, status = self.__hc.get_orders(market=market, open_only=open_only) if status: return [bm.Order(**order) for order in resp['order']] else: raise Exception('获取订单信息失败')
def on_order(self, *args): # 接收到订单状态更新 # TODO: self.__queue.put((BtccWebsocketClient.Event.ON_ORDER_BOOK_UPDATE, bm.Order(**args[0])))
def get_order(self, order_id): resp, status = self.__hc.get_order(order_id=order_id) if status: return bm.Order(**resp['order']) else: return bm.Order(id=order_id)