def transfer(self, symbol, from_account, to_account, currency, amount):
        check_symbol(symbol)
        check_should_not_none(from_account, "from_account")
        check_should_not_none(to_account, "to_account")
        check_should_not_none(currency, "currency")
        check_should_not_none(amount, "amount")
        if from_account == AccountType.SPOT and to_account == AccountType.MARGIN:
            address = "/v1/dw/transfer-in/margin"
        elif from_account == AccountType.MARGIN and AccountType.SPOT:
            address = "/v1/dw/transfer-out/margin"
        else:
            raise HuobiApiException(HuobiApiException.INPUT_ERROR,
                                    "[Input] incorrect transfer type")
        builder = UrlParamsBuilder()
        builder.put_post("currency", currency)
        builder.put_post("symbol", symbol)
        builder.put_post("amount", amount)
        request = self.__create_request_by_post_with_signature(
            address, builder)

        def parse(json_wrapper):
            if json_wrapper.get_string("status") == "ok":
                return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
    def cancel_client_order(self, client_order_id):
        check_should_not_none(client_order_id, "client-order-id")
        path = "/v1/order/orders/submitCancelClientOrder"
        builder = UrlParamsBuilder()
        builder.put_post("client-order-id", client_order_id)
        request = self.__create_request_by_post_with_signature(path, builder)

        def parse(json_wrapper):
            return

        request.json_parser = parse
        return request
    def repay_loan(self, load_id, amount):
        check_should_not_none(load_id, "load_id")
        check_should_not_none(amount, "amount")
        builder = UrlParamsBuilder()
        builder.put_post("amount", amount)
        path = "/v1/margin/orders/{}/repay"
        path = path.format(load_id)
        request = self.__create_request_by_post_with_signature(path, builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
    def apply_loan(self, symbol, currency, amount):
        check_symbol(symbol)
        check_should_not_none(currency, "currency")
        check_should_not_none(amount, "amount")
        builder = UrlParamsBuilder()
        builder.put_post("currency", currency)
        builder.put_post("symbol", symbol)
        builder.put_post("amount", amount)
        request = self.__create_request_by_post_with_signature("/v1/margin/orders", builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
    def cancel_orders(self, symbol, order_id_list):
        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))
        builder = UrlParamsBuilder()
        builder.put_post("order-ids", string_list)
        request = self.__create_request_by_post_with_signature("/v1/order/orders/batchcancel", builder)

        def parse(json_wrapper):
            return

        request.json_parser = parse
        return request
    def etf_swap(self, etf_symbol, amount, swap_type):
        check_symbol(etf_symbol)
        check_should_not_none(amount, "amount")
        check_should_not_none(swap_type, "swap_type")
        builder = UrlParamsBuilder()
        builder.put_post("etf_name", etf_symbol)
        builder.put_post("amount", amount)
        if swap_type == EtfSwapType.IN:
            request = self.__create_request_by_post_with_signature("/etf/swap/in", builder)
        else:
            request = self.__create_request_by_post_with_signature("/etf/swap/out", builder)

        def parse():
            return

        request.json_parser = parse
        return request
示例#7
0
    def get_contract_openorders(self
                         , symbol: 'str'
                         , page_index: 'int'
                         , page_size: 'int'
                         ) -> int:
        """
        :param symbol	true	string	品种代码		"BTC","ETH"...
        :param page_index	false	int	页码,不填默认第1页	1
        :param page_size	false	int			不填默认20,不得多于50
        :return:
            <list>(属性名称: data)
                symbol	true	string	品种代码
                contract_type	true	string	合约类型	当周:"this_week", 次周:"next_week", 季度:"quarter"
                contract_code	true	string	合约代码	"BTC180914" ...
                volume	true	decimal	委托数量
                price	true	decimal	委托价格
                order_price_type	true	string	订单报价类型 "limit":限价 "opponent":对手价 "post_only":只做maker单,post only下单只受用户持仓数量限制
                direction	true	string	"buy":买 "sell":卖
                offset	true	string	"open":开 "close":平
                lever_rate	true	int	杠杆倍数	1\5\10\20
                order_id	true	long	订单ID
                client_order_id	true	long	客户订单ID
                created_at	true	long	订单创建时间
                trade_volume	true	decimal	成交数量
                trade_turnover	true	decimal	成交总金额
                fee	true	decimal	手续费
                trade_avg_price	true	decimal	成交均价
                margin_frozen	true	decimal	冻结保证金
                profit	true	decimal	收益
                status	true	int	订单状态	(3未成交 4部分成交 5部分成交已撤单 6全部成交 7已撤单)
                order_source	true	string	订单来源
            </list>
            total_page	true	int	总页数
            current_page	true	int	当前页
            total_size	true	int	总条数
        """
        builder = UrlParamsBuilder()
        builder.put_post("symbol",symbol)
        builder.put_post("type",type)
        request = self.__create_request_by_post_with_signature("/api/v1/contract_openorders", builder)

        def parse(json_wrapper):
            return json_wrapper.get_object("data").__dict__['json_object']

        request.json_parser = parse
        return request
    def withdraw(self, address, amount, currency, fee=None, address_tag=None):
        check_symbol(currency)
        check_should_not_none(address, "address")
        check_should_not_none(amount, "amount")
        builder = UrlParamsBuilder()
        builder.put_post("address", address)
        builder.put_post("amount", amount)
        builder.put_post("currency", currency)
        builder.put_post("fee", fee)
        builder.put_post("addr-tag", address_tag)

        request = self.__create_request_by_post_with_signature("/v1/dw/withdraw/api/create", builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
示例#9
0
    def cancel_contract_all(self
                            , symbol
                            , contract_code
                            , contract_type
                            ) -> int:
        check_symbol(symbol)

        builder = UrlParamsBuilder()
        builder.put_post("symbol",symbol)
        builder.put_post("contract_code",contract_code)
        builder.put_post("contract_type",contract_type)
        request = self.__create_request_by_post_with_signature("/api/v1/contract_cancelall", builder)

        def parse(json_wrapper):
            return json_wrapper.get_array("data")

        request.json_parser = parse
        return request
示例#10
0
    def transfer_between_parent_and_sub(self, sub_uid, currency, amount, transfer_type):
        check_currency(currency)
        check_should_not_none(sub_uid, "sub_uid")
        check_should_not_none(amount, "amount")
        check_should_not_none(transfer_type, "transfer_type")
        builder = UrlParamsBuilder()
        builder.put_post("sub-uid", sub_uid)
        builder.put_post("amount", amount)
        builder.put_post("currency", currency)
        builder.put_post("type", transfer_type)
        request = self.__create_request_by_post_with_signature("/v1/subuser/transfer", builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
    def transfer_between_futures_and_pro(self, currency, amount,
                                         transfer_type):
        check_currency(currency)
        check_should_not_none(currency, "currency")
        check_should_not_none(amount, "amount")
        check_should_not_none(transfer_type, "transfer_type")
        builder = UrlParamsBuilder()
        builder.put_post("amount", amount)
        builder.put_post("currency", currency)
        builder.put_post("type", transfer_type)
        request = self.__create_request_by_post_with_signature(
            "/v1/futures/transfer", builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")  # transfer ID

        request.json_parser = parse
        return request
示例#12
0
    def get_contract_orders(self
                            , order_id
                            , client_order_id
                            , symbol: 'str'
                            ) -> int:
        check_symbol(symbol)

        builder = UrlParamsBuilder()
        builder.put_post("order_id",order_id)
        builder.put_post("client_order_id",client_order_id)
        builder.put_post("symbol",symbol)

        request = self.__create_request_by_post_with_signature("/api/v1/contract_order_info", builder)

        def parse(json_wrapper):
            return json_wrapper.get_array("data")

        request.json_parser = parse
        return request
示例#13
0
    def cancel_open_orders(self, symbol, account_type, side=None, size=None):
        check_symbol(symbol)
        check_should_not_none(account_type, "account_type")
        global account_info_map
        user = account_info_map.get_user(self.__api_key)
        account = user.get_account_by_type(account_type)
        builder = UrlParamsBuilder()
        builder.put_post("account-id", account.id)
        builder.put_post("symbol", symbol)
        builder.put_post("side", side)
        builder.put_post("size", size)
        request = self.__create_request_by_post_with_signature("/v1/order/orders/batchCancelOpenOrders", builder)

        def parse(json_wrapper):
            data = json_wrapper.get_object("data")
            batch_cancel_result = BatchCancelResult()
            batch_cancel_result.success_count = data.get_int("success-count")
            batch_cancel_result.failed_count = data.get_int("failed-count")
            return batch_cancel_result

        request.json_parser = parse
        return request
    def create_order(self,
                     symbol,
                     account_type,
                     order_type,
                     amount,
                     price,
                     client_order_id=None,
                     stop_price=None,
                     operator=None):
        check_symbol(symbol)
        check_should_not_none(account_type, "account_type")
        check_should_not_none(order_type, "order_type")
        check_should_not_none(amount, "amount")
        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 == OrderType.SELL_MARKET or order_type == OrderType.BUY_MARKET:
            check_should_none(price, "price")
        global account_info_map
        user = account_info_map.get_user(self.__api_key)
        account = user.get_account_by_type(account_type)
        source = RestApiRequestImpl.order_source_desc(account_type)
        builder = UrlParamsBuilder()
        builder.put_post("account-id", account.id)
        builder.put_post("amount", amount)
        builder.put_post("price", price)
        builder.put_post("symbol", symbol)
        builder.put_post("type", order_type)
        builder.put_post("source", source)
        builder.put_post("client-order-id", client_order_id)
        builder.put_post("stop-price", stop_price)
        builder.put_post("operator", operator)

        request = self.__create_request_by_post_with_signature(
            "/v1/order/orders/place", builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
示例#15
0
    def create_order(self, symbol, account_type, order_type, amount, price):
        check_symbol(symbol)
        check_should_not_none(account_type, "account_type")
        check_should_not_none(order_type, "order_type")
        check_should_not_none(amount, "amount")
        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 == OrderType.SELL_MARKET or order_type == OrderType.BUY_MARKET:
            check_should_none(price, "price")
        global account_info_map
        user = account_info_map.get_user(self.__api_key)
        account = user.get_account_by_type(account_type)
        source = "api"
        if account_type == AccountType.MARGIN:
            source = "margin-api"
        builder = UrlParamsBuilder()
        builder.put_post("account-id", account.id)
        builder.put_post("amount", amount)
        builder.put_post("price", price)
        builder.put_post("symbol", symbol)
        builder.put_post("type", order_type)
        builder.put_post("source", source)
        request = self.__create_request_by_post_with_signature(
            "/v1/order/orders/place", builder)

        def parse(json_wrapper):
            return json_wrapper.get_int("data")

        request.json_parser = parse
        return request
示例#16
0
    def create_contract_order(self
                              , symbol: 'str'
                              , contract_type: 'ContractType'
                              , contract_code: 'str'
                              , client_order_id: 'str'
                              , price: 'float'
                              , volume: 'long'
                              , direction: 'TradeDirection'
                              , offset: 'TradeOffset'
                              , lever_rate: 'str'
                              , order_price_type: 'str'
                              ) -> int:
        check_symbol(symbol)
        check_should_not_none(contract_type, "contract_type")
        check_should_not_none(price, "price")
        check_should_not_none(volume, "volume")
        check_should_not_none(direction, "direction")
        check_should_not_none(offset, "offset")
        check_should_not_none(lever_rate, "lever_rate")
        check_should_not_none(order_price_type, "order_price_type")

        # user = account_info_map.get_user(self.__api_key)
        # account = user.get_account_by_type(AccountType.SPOT)
        source = "api"

        builder = UrlParamsBuilder()
        builder.put_post("symbol",symbol)
        builder.put_post("contract_type",contract_type)
        builder.put_post("contract_code",contract_code)
        builder.put_post("client_order_id",client_order_id)
        builder.put_post("price",price)
        builder.put_post("volume",volume)
        builder.put_post("direction",direction)
        builder.put_post("offset",offset)
        builder.put_post("lever_rate",lever_rate)
        builder.put_post("order_price_type",order_price_type)
        builder.put_post("source", source)
        request = self.__create_request_by_post_with_signature("/api/v1/contract_order", builder)

        def parse(json_wrapper):
            return json_wrapper.get_object("data").get_int("order_id")

        request.json_parser = parse
        return request