Exemple #1
0
    async def create_order(self,
                           pair: Pair,
                           side: enums.OrderSide,
                           type: enums.OrderType,
                           amount: str,
                           price: str = None,
                           stop_price: str = None,
                           time_in_force: enums.TimeInForce = None,
                           client_id: str = None,
                           expire_time: datetime.datetime = None,
                           strict_validate: bool = None,
                           post_only: bool = None) -> dict:
        data = {
            "symbol": map_pair(pair),
            "side": side.value,
            "type": type.value,
            "quantity": amount,
            "price": price,
            "stopPrice": stop_price,
            "clientOrderId": client_id,
            "strictValidate": strict_validate,
            "postOnly": post_only
        }

        if time_in_force is not None:
            data['timeInForce'] = time_in_force.value

        if expire_time:
            data["expireTime"] = expire_time.astimezone(pytz.utc).isoformat()

        return await self._create_post("order", data=data, signed=True)
    def to_json(self):
        id = HitbtcSubscription.generate_new_external_id()

        ret = {
            "method": "newOrder",
            "params": {
                "symbol": map_pair(self.pair),
                "side": self.side.value,
                "type": self.type.value,
                "quantity": self.amount,
                'clientOrderId': self.client_id
            },
            "id": id
        }

        if self.price is not None:
            ret['params']['price'] = self.price

        if self.stop_price is not None:
            ret['params']['stopPrice'] = self.stop_price

        if self.strict_validate is not None:
            ret['params']['strictValidate'] = self.strict_validate

        if self.post_only is not None:
            ret['params']['postOnly'] = self.post_only

        if self.time_in_force is not None:
            ret['params']['timeInForce'] = self.time_in_force.value

        if self.expire_time:
            ret['parms']["expireTime"] = self.expire_time.astimezone(pytz.utc).isoformat()

        return ret
 def get_subscription_message(self, **kwargs) -> dict:
     return {
         "method": "subscribeTicker",
         "params": {
             "symbol": map_pair(self.pair),
         },
         "id": self.external_id
     }
Exemple #4
0
    async def get_order_books(self,
                              limit: int = None,
                              pairs: List[Pair] = None) -> dict:
        params = self._clean_request_params({"limit": limit})

        if pairs is not None:
            params['symbols'] = ','.join(map_pair(pair) for pair in pairs)

        return await self._create_get("public/orderbook", params=params)
    def get_subscription_message(self, **kwargs) -> dict:
        params = {
            "method": "subscribeTrades",
            "params": {
                "symbol": map_pair(self.pair),
            },
            "id": self.external_id
        }

        if self.limit is not None:
            params['params']['limit'] = self.limit

        return params
Exemple #6
0
    async def get_tickers(self, pairs: List[Pair] = None) -> dict:
        params = {}
        if pairs is not None:
            params['symbols'] = ','.join(map_pair(pair) for pair in pairs)

        return await self._create_get("public/ticker", params=params)
Exemple #7
0
    async def cancel_orders(self, pair: Pair = None) -> dict:
        params = {}
        if pair is not None:
            params['symbol'] = map_pair(pair)

        return await self._create_delete(f"order", params=params, signed=True)