Ejemplo n.º 1
0
    def post_create_withdraw(self,
                             address: 'str',
                             amount: 'float',
                             currency: 'str',
                             fee: 'float',
                             chain: 'str' = None,
                             address_tag: 'str' = None) -> int:
        """
        Submit a request to withdraw some asset from an account.

        :param address: The destination address of this withdraw. (mandatory)
        :param amount: The amount of currency to withdraw. (mandatory)
        :param currency: The crypto currency to withdraw. (mandatory)
        :param fee: The fee to pay with this withdraw. (mandatory)
        :param address_tag: A tag specified for this address. (optional)
        :param chain: set as "usdt" to withdraw USDT to OMNI, set as "trc20usdt" to withdraw USDT to TRX. (optional)
        :return: Withdraw id
        """
        check_symbol(currency)
        check_should_not_none(address, "address")
        check_should_not_none(amount, "amount")
        check_should_not_none(fee, "fee")

        params = {
            "currency": currency,
            "address": address,
            "amount": amount,
            "fee": fee,
            "chain": chain,
            "addr-tag": address_tag
        }
        channel = "/v1/dw/withdraw/api/create"

        return self.rest_api_sync_client.request_process(
            HttpMethod.POST_SIGN, channel, params)
Ejemplo n.º 2
0
    def create_order_param_check(symbol: str, account_id: int, order_type: OrderType, amount: float,
                                 price: float, source: str, client_order_id=None, stop_price=None, operator=None):
        check_symbol(symbol)
        check_should_not_none(account_id, "account_id")
        check_should_not_none(order_type, "order_type")
        check_should_not_none(amount, "amount")
        check_should_not_none(source, "source")

        if order_type == OrderType.SELL_LIMIT \
                or order_type == OrderType.BUY_LIMIT \
                or order_type == OrderType.BUY_LIMIT_MAKER \
                or order_type == OrderType.SELL_LIMIT_MAKER:
            check_should_not_none(price, "price")
        if order_type in [OrderType.SELL_MARKET, OrderType.BUY_MARKET]:
            price = None

        params = {
            "account-id": account_id,
            "amount": amount,
            "price": price,
            "symbol": symbol,
            "type": order_type,
            "source": source,
            "client-order-id": client_order_id,
            "stop-price": stop_price,
            "operator": operator
        }

        return params
Ejemplo n.º 3
0
    def get_match_result(self, symbol: str, order_type: OrderSide = None, start_date: str = None,
                         end_date: str = None,
                         size: 'int' = None,
                         from_id: 'int' = None,
                         direct: str = None):
        """
        Search for the trade records of an account.

        :param direct:  direct
        :param symbol: The symbol, like "btcusdt" (mandatory).
        :param order_type: The types of order to include in the search (optional).
        :param start_date: Search starts date in format yyyy-mm-dd. (optional).
        :param end_date: Search ends date in format yyyy-mm-dd. (optional).
        :param size: The number of orders to return, range [1-100]. (optional).
        :param from_id: Search order id to begin with. (optional).
        :return:
        """

        check_symbol(symbol)
        start_date = format_date(start_date, "start_date")
        end_date = format_date(end_date, "end_date")
        check_range(size, 1, 100, "size")

        params = {
            "symbol": symbol,
            "start-date": start_date,
            "end-date": end_date,
            "types": order_type,
            "size": size,
            "from": from_id,
            "direct": direct
        }
        channel = "/v1/order/matchresults"

        return self.trade_client.request_process(HttpMethod.GET_SIGN, channel, params)
Ejemplo n.º 4
0
    def get_open_orders(self, symbol: str, account_id: 'int', side: 'OrderSide' = None,
                        size: 'int' = None, from_id=None, direct=None) -> list:
        """
        The request of get open orders.

        :param symbol: The symbol, like "btcusdt". (mandatory)
        :param account_id: account id (mandatory)
        :param side: The order side, buy or sell. If no side defined, will return all open orders of the account.
                    (optional)
        :param size: The number of orders to return. Range is [1, 500]. (optional)
        :param direct: 1:prev  order by ID asc from from_id, 2:next order by ID desc from from_id
        :param from_id: start ID for search
        :return: The orders information.
        """
        check_symbol(symbol)
        check_range(size, 1, 500, "size")
        check_should_not_none(account_id, "account_id")
        params = {
            "symbol": symbol,
            "account-id": account_id,
            "side": side,
            "size": size,
            "from": from_id,
            "direct": direct
        }
        channel = "/v1/order/openOrders"

        return self.trade_client.request_process(HttpMethod.GET_SIGN, channel, params)
Ejemplo n.º 5
0
    def cancel_order(self, symbol, order_id):
        check_symbol(symbol)
        check_should_not_none(order_id, "order_id")

        params = {
            "order_id": order_id
        }
        order_id = params["order_id"]

        def get_channel():
            path = "/v1/order/orders/{}/submitcancel"
            return path.format(order_id)

        return self.trade_client.request_process(HttpMethod.POST_SIGN, get_channel(), params)
Ejemplo n.º 6
0
    def get_etf_swap_config(self, etf_name: 'str'):
        """
        Get the basic information of ETF creation and redemption, as well as ETF constituents,
        including max amount of creation, min amount of creation, max amount of redemption, min amount
        of redemption, creation fee rate, redemption fee rate, eft create/redeem status.

        :param etf_name: The symbol, currently only support hb10. (mandatory)
        :return: The etf configuration information.
        """
        check_symbol(etf_name)
        params = {"etf_name": etf_name}
        channel = "/etf/swap/config"
        return self.rest_api_sync_client.request_process(
            HttpMethod.GET, channel, params)
Ejemplo n.º 7
0
    def get_transact_fee_rate(self, symbols: str) -> list:
        """
        The request of get transact fee rate list.

        :param symbols: The symbol, like "btcusdt,htusdt". (mandatory)
        :return: The transact fee rate list.
        """
        check_symbol(symbols)

        params = {
            "symbols": symbols
        }
        channel = "/v2/reference/transact-fee-rate"

        return self.trade_client.request_process(HttpMethod.GET_SIGN, channel, params)
Ejemplo n.º 8
0
    def post_etf_swap_in(self, etf_name: 'str', amount: 'int') -> None:
        """
        Order creation or redemption of ETF.

        :param etf_name: The symbol, currently only support hb10. (mandatory)
        :param amount: The amount to create or redemption. (mandatory)
        :return: No return
        """
        check_symbol(etf_name)
        check_should_not_none(amount, "amount")

        params = {"etf_name": etf_name, "amount": amount}
        channel = "/etf/swap/in"
        return self.rest_api_sync_client.request_process(
            HttpMethod.POST_SIGN, channel, params)
Ejemplo n.º 9
0
    def get_etf_swap_list(self, etf_name: 'str', offset: 'int',
                          size: 'int') -> list:
        """
        Get past creation and redemption.(up to 100 records)

        :param etf_name: The symbol, currently only support hb10. (mandatory)
        :param offset: The offset of the records, set to 0 for the latest records. (mandatory)
        :param size: The number of records to return, the range is [1, 100]. (mandatory)
        :return: The swap history.
        """
        check_symbol(etf_name)
        params = {"etf_name": etf_name, "offset": offset, "limit": size}
        channel = "/etf/swap/list"
        return self.rest_api_sync_client.request_process(
            HttpMethod.GET_SIGN, channel, params)
Ejemplo n.º 10
0
    def get_fee_rate(self, symbols: str) -> list:
        """
        Get the candlestick/kline for the specified symbol. The data number is 150 as default.

        :param symbols: The symbol, like "btcusdt". To query hb10, put "hb10" at here. (mandatory)
        : interval: The candlestick/kline interval, MIN1, MIN5, DAY1 etc. (mandatory)
        : size: The start time of of requested candlestick/kline data. (optional)
        : start_time: The start time of of requested candlestick/kline data. (optional)
        : end_time: The end time of of requested candlestick/kline data. (optional)
        :return: The list of candlestick/kline data.
        """
        channel = "/v1/fee/fee-rate/get"
        check_symbol(symbols)

        params = {
            "symbols": symbols
        }
        return self.trade_client.request_process(HttpMethod.GET_SIGN, channel, params)
Ejemplo n.º 11
0
    def cancel_orders(self, symbol, order_id_list):
        """
        Submit cancel request for cancelling multiple orders.

        :param symbol: The symbol, like "btcusdt". (mandatory)
        :param order_id_list: The list of order id. the max size is 50. (mandatory)
        :return: No return
        """
        check_symbol(symbol)
        check_should_not_none(order_id_list, "order_id_list")
        check_list(order_id_list, 1, 50, "order_id_list")

        string_list = list()
        for order_id in order_id_list:
            string_list.append(str(order_id))

        params = {
            "order-ids": string_list
        }
        channel = "/v1/order/orders/batchcancel"
        return self.trade_client.request_process(HttpMethod.POST_SIGN, channel, params)
Ejemplo n.º 12
0
    def get_orders(self, symbol: str, order_state: OrderState, order_type: OrderType = None,
                   start_date: str = None, end_date: str = None, start_id: 'int' = None,
                   size: 'int' = None, direct=None) -> list:
        check_symbol(symbol)
        check_should_not_none(order_state, "order_state")
        start_date = format_date(start_date, "start_date")
        end_date = format_date(end_date, "end_date")

        params = {
            "symbol": symbol,
            "types": order_type,
            "start-date": start_date,
            "end-date": end_date,
            "from": start_id,
            "states": order_state,
            "size": size,
            "direct": direct
        }
        channel = "/v1/order/orders"

        return self.trade_client.request_process(HttpMethod.GET_SIGN, channel, params)