def cancel_order(self, order_id: str, pair: str, price: Wad, amount: Wad, is_sell: bool) -> bool: assert (isinstance(order_id, str)) assert (isinstance(pair, str)) assert (isinstance(is_sell, bool)) assert (isinstance(price, Wad)) assert (isinstance(amount, Wad)) self.logger.info(f"Cancelling order #{order_id}...") currency = pair.split('-')[0] is_ask = 1 if is_sell is True else 0 data = { "order_id": order_id, "currency": currency, "price": str(round(Wad.__float__(price), 2)), # quote token is always krw "qty": str(round(Wad.__float__(amount), 2)), "is_ask": is_ask } result = self._http_authenticated_request("POST", f"/v2/order/cancel", data) return True if result["result"] == "success" else False
def place_order(self, pair: str, is_sell: bool, price: Wad, amount: Wad) -> str: assert (isinstance(pair, str)) assert (isinstance(is_sell, bool)) assert (isinstance(price, Wad)) assert (isinstance(amount, Wad)) side = "limit_buy" if is_sell is False else "limit_sell" currency = pair.split('-')[0] # Coinone krw price precision must be specified based upon a given range float_price = Wad.__float__(price) price_prec = self._calc_price_precision(float_price) price = round(round(float_price / price_prec, 0) * price_prec, 0) data = { "currency": currency, "price": str(price), "qty": str(round(Wad.__float__(amount), 2)) } self.logger.info( f"Placing order ({side}, amount {data['qty']} of {pair}," f" price {data['price']})...") response = self._http_authenticated_request("POST", f"/v2/order/{side}", data) order_id = "" if response['result'] == 'success': order_id = response['orderId'] self.logger.info(f"Placed order (#{order_id})") return order_id