def json_parse(json_wrapper):
     ch = json_wrapper.get_string("topic")
     parse = ChannelParser(ch)
     order_update_event = OrderUpdateEvent()
     order_update_event.symbol = parse.symbol
     order_update_event.timestamp = convert_cst_in_millisecond_to_utc(
         json_wrapper.get_int("ts"))
     data = json_wrapper.get_object("data")
     order = Order()
     order.order_id = data.get_int("order-id")
     order.symbol = parse.symbol
     order.account_type = account_info_map.get_account_by_id(
         self.__api_key, data.get_int("account-id")).account_type
     order.amount = data.get_float("order-amount")
     order.price = data.get_float("order-price")
     order.created_timestamp = convert_cst_in_millisecond_to_utc(
         data.get_int("created-at"))
     order.order_type = data.get_string("order-type")
     order.filled_amount = data.get_float("filled-amount")
     order.filled_cash_amount = data.get_float("filled-cash-amount")
     order.filled_fees = data.get_float("filled-fees")
     order.state = data.get_string("order-state")
     order.source = data.get_string("order-source")
     order_update_event.data = order
     return order_update_event
Пример #2
0
 def parse(json_wrapper):
     order_list = list()
     data_array = json_wrapper.get_array("data")
     for item in data_array.get_items():
         order = Order()
         order.account_type = account_info_map.get_account_by_id(
             self.__api_key, item.get_int("account-id")).account_type
         order.amount = item.get_float("amount")
         order.canceled_timestamp = convert_cst_in_millisecond_to_utc(
             item.get_int_or_default("canceled-at", 0))
         order.finished_timestamp = convert_cst_in_millisecond_to_utc(
             item.get_int_or_default("finished-at", 0))
         order.order_id = item.get_int("id")
         order.symbol = item.get_string("symbol")
         order.price = item.get_float("price")
         order.created_timestamp = convert_cst_in_millisecond_to_utc(
             item.get_int("created-at"))
         order.order_type = item.get_string("type")
         order.filled_amount = item.get_float("field-amount")
         order.filled_cash_amount = item.get_float("field-cash-amount")
         order.filled_fees = item.get_float("field-fees")
         order.source = item.get_string("source")
         order.state = item.get_string("state")
         order_list.append(order)
     return order_list
 def get_account_type_map(json_wrapper):
     #get account type mapping
     account_id_type_map = {}
     data = json_wrapper.get_object("data")
     account_id = data.get_int("account-id")
     account_type = account_info_map.get_account_by_id(
         self.__api_key, account_id).account_type
     account_id_type_map[account_id] = account_type
     return account_id_type_map
    def format_order(self, json_data):
        account_type = account_info_map.get_account_by_id(
            self.__api_key, json_data.get_int("account-id")).account_type
        # 检查是否有canceled-at and finished-at
        if "finished-at" not in json_data.json_object:
            json_data.json_object["finished-at"] = 0
        if "canceled-at" not in json_data.json_object:
            json_data.json_object["canceled-at"] = 0
        order = Order.json_parse(json_data, account_type)

        return order
 def get_account_type_map(json_wrapper):
     #get account type mapping
     account_id_type_map = {}
     error_code = json_wrapper.get_int("err-code")
     if error_code == 0:
         order_list_json = json_wrapper.get_array("data")
         for order_json in order_list_json.get_items():
             account_id = order_json.get_int("account-id")
             account_type = account_info_map.get_account_by_id(
                 self.__api_key, account_id).account_type
             account_id_type_map[account_id] = account_type
     return account_id_type_map
Пример #6
0
 def json_parse(json_wrapper):
     account_event = AccountEvent()
     account_event.timestamp = json_wrapper.get_int("ts")
     data = json_wrapper.get_object("data")
     account_event.change_type = data.get_string("event")
     list_array = data.get_array("list")
     account_change_list = list()
     for item in list_array.get_items():
         account_change = AccountChange()
         account_change.account_type = account_info_map.get_account_by_id(
             self.__api_key, item.get_int("account-id")).account_type
         account_change.currency = item.get_string("currency")
         account_change.balance = item.get_float("balance")
         account_change.balance_type = item.get_string("type")
         account_change_list.append(account_change)
     account_event.account_change_list = account_change_list
     return account_event
Пример #7
0
 def parse(json_wrapper):
     data = json_wrapper.get_object("data")
     order = Order()
     order.order_id = data.get_int("id")
     order.symbol = data.get_string("symbol")
     order.price = data.get_float("price")
     order.amount = data.get_float("amount")
     order.account_type = account_info_map.get_account_by_id(self.__api_key,
                                                             data.get_int("account-id")).account_type
     order.created_timestamp = convert_cst_in_millisecond_to_utc(data.get_int("created-at"))
     order.canceled_timestamp = convert_cst_in_millisecond_to_utc(data.get_int("canceled-at"))
     order.finished_timestamp = convert_cst_in_millisecond_to_utc(data.get_int("finished-at"))
     order.order_type = data.get_string("type")
     order.filled_amount = data.get_float("field-amount")
     order.filled_cash_amount = data.get_float("field-cash-amount")
     order.filled_fees = data.get_float("field-fees")
     order.source = data.get_string("source")
     order.state = data.get_string("state")
     return order
Пример #8
0
 def parse(json_wrapper):
     loan_list = list()
     data_array = json_wrapper.get_array("data")
     for item in data_array.get_items():
         loan = Loan()
         loan.loan_balance = item.get_float("loan-balance")
         loan.interest_balance = item.get_float("interest-balance")
         loan.interest_rate = item.get_float("interest-rate")
         loan.loan_amount = item.get_float("loan-amount")
         loan.interest_amount = item.get_float("interest-amount")
         loan.symbol = item.get_string("symbol")
         loan.currency = item.get_string("currency")
         loan.id = item.get_int("id")
         loan.state = item.get_string("state")
         loan.account_type = account_info_map.get_account_by_id(self.__api_key,
                                                                item.get_int("account-id")).account_type
         loan.user_id = item.get_int("user-id")
         loan.accrued_timestamp = convert_cst_in_millisecond_to_utc(item.get_int("accrued-at"))
         loan.created_timestamp = convert_cst_in_millisecond_to_utc(item.get_int("created-at"))
         loan_list.append(loan)
     return loan_list
Пример #9
0
 def format_order(self, json_data):
     order = Order()
     order.order_id = json_data.get_int("id")
     order.symbol = json_data.get_string("symbol")
     order.price = json_data.get_float("price")
     order.amount = json_data.get_float("amount")
     order.created_timestamp = convert_cst_in_millisecond_to_utc(
         json_data.get_int("created-at"))
     order.canceled_timestamp = convert_cst_in_millisecond_to_utc(
         json_data.get_int("canceled-at"))
     order.finished_timestamp = convert_cst_in_millisecond_to_utc(
         json_data.get_int("finished-at"))
     order.order_type = json_data.get_string("type")
     order.filled_amount = json_data.get_float("field-amount")
     order.filled_cash_amount = json_data.get_float("field-cash-amount")
     order.filled_fees = json_data.get_float("field-fees")
     order.account_type = account_info_map.get_account_by_id(
         self.__api_key, json_data.get_int("account-id")).account_type
     order.source = json_data.get_string("source")
     order.state = json_data.get_string("state")
     order.stop_price = json_data.get_float_or_default("stop-price", 0.0)
     order.operator = json_data.get_string_or_default("operator", "")
     order.next_time = json_data.get_string_or_default("next-time", "")
     return order
Пример #10
0
    def format_order(self, json_data):
        account_type = account_info_map.get_account_by_id(
            self.__api_key, json_data.get_int("account-id")).account_type
        order = Order.json_parse(json_data, account_type)

        return order