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 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
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
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 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): 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