Ejemplo n.º 1
0
 def cancel_order(self, trading_pair, order_id, exchange_order_id,
                  get_resp):
     if MOCK_API_ENABLED:
         resp = FixtureOKEx.ORDER_CANCEL.copy()
         resp["data"][0]["ordId"] = exchange_order_id
         resp["data"][0]["clOrdId"] = order_id
         self.web_app.update_response("post",
                                      API_BASE_URL,
                                      '/' + OKEX_ORDER_CANCEL,
                                      resp,
                                      params={"ordId": exchange_order_id})
     self.market.cancel(trading_pair, order_id)
     if MOCK_API_ENABLED:
         resp = get_resp.copy()
         resp["data"][0]["ordId"] = exchange_order_id
         resp["data"][0]["clOrdId"] = order_id
         self.web_app.update_response(
             "get", API_BASE_URL, '/' + OKEX_ORDER_DETAILS_URL.format(
                 ordId=exchange_order_id, trading_pair="ETH-USDT"), resp)
Ejemplo n.º 2
0
 def place_order(self,
                 is_buy,
                 trading_pair,
                 amount,
                 order_type,
                 price,
                 nonce,
                 get_resp,
                 market_connector=None):
     global EXCHANGE_ORDER_ID
     order_id, exch_order_id = None, None
     if MOCK_API_ENABLED:
         exch_order_id = f"OKEX_{EXCHANGE_ORDER_ID}"
         EXCHANGE_ORDER_ID += 1
         self._t_nonce_mock.return_value = nonce
         resp = FixtureOKEx.ORDER_PLACE.copy()
         resp["order_id"] = exch_order_id
         # resp = exch_order_id
         side = 'buy' if is_buy else 'sell'
         order_id = f"{side}-{trading_pair}-{nonce}"
         self.web_app.update_response("post", API_BASE_URL,
                                      "/" + OKEX_PLACE_ORDER, resp)
     market = self.market if market_connector is None else market_connector
     if is_buy:
         order_id = market.buy(trading_pair, amount, order_type, price)
     else:
         order_id = market.sell(trading_pair, amount, order_type, price)
     if MOCK_API_ENABLED:
         resp = get_resp.copy()
         # resp is the response passed by parameter
         resp["id"] = exch_order_id
         resp["client_oid"] = order_id
         self.web_app.update_response(
             "get", API_BASE_URL, '/' +
             OKEX_ORDER_DETAILS_URL.format(exchange_order_id=exch_order_id),
             resp)
     return order_id, exch_order_id