def parse_response_content(self, response_content): response = super(FutureBriefsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] brief_data = [] if self.data and isinstance(self.data, list): for item in self.data: item_values = {} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = BRIEF_FIELD_MAPPINGS[ key] if key in BRIEF_FIELD_MAPPINGS else key item_values[tag] = value brief_data.append([item_values.get(tag) for tag in COLUMNS]) elif isinstance(self.data, dict): item_values = {} for key, value in self.data.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = BRIEF_FIELD_MAPPINGS[ key] if key in BRIEF_FIELD_MAPPINGS else key item_values[tag] = value brief_data.append([item_values.get(tag) for tag in COLUMNS]) self.briefs = pd.DataFrame(brief_data, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(MarketStatusResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): for item in self.data: market, status, open_time, trading_status = None, None, None, None for key, value in item.items(): if value is None: continue if key == 'market': market = get_string(value) elif key == 'marketStatus': status = get_string(value) elif key == 'openTime': if value.endswith(' EDT') or value.endswith(' EST'): value = value[0:len(value) - 4] open_time = dateparser.parse(value) elif key == 'status': trading_status = get_string(value) if open_time and market: if market == 'US': open_time = eastern.localize(open_time) elif market == 'HK': open_time = hongkong.localize(open_time) elif market == 'CN': open_time = china.localize(open_time) market_status = MarketStatus(market, status, open_time, trading_status) self.markets.append(market_status)
def parse_response_content(self, response_content): response = super(StockIndustryResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: for item in self.data: industry = dict(industry_level=item.get('industryLevel'), id=item.get('id'), name_cn=get_string(item.get('nameCN')), name_en=get_string(item.get('nameEN'))) self.stock_industry.append(industry)
def parse_response_content(self, response_content): response = super(SymbolNamesResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): self.symbol_names = [(get_string(item['symbol']), get_string(item['name'])) for item in self.data if len(item) == 2]
def parse_response_content(self, response_content): response = super(IndustryStocksResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: for item in self.data: industry_list = list() industries = item.get('industryDetailDTOList', []) for ind in industries: industry_list.append(dict(industry_level=ind.get('industryLevel'), id=ind.get('id'), name_cn=get_string(ind.get('nameCN')), name_en=get_string(ind.get('nameEN')))) company = dict(symbol=item.get('symbol'), company_name=item.get('companyName'), market=item.get('market'), industry_list=industry_list) self.industry_stocks.append(company)
def parse_response_content(self, response_content): response = super(OptionChainsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): chain_data = [] for item in self.data: symbol = item.get('symbol') expiry = item.get('expiry') items = item.get('items') if symbol and items: for chain_item in items: for call_put_item in chain_item.values(): item_values = {'symbol': symbol, 'expiry': expiry} for key, value in call_put_item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key == 'right': value = value.upper() tag = CHAIN_FIELD_MAPPINGS[ key] if key in CHAIN_FIELD_MAPPINGS else key item_values[tag] = value chain_data.append( [item_values.get(tag) for tag in COLUMNS]) self.chain = pd.DataFrame(chain_data, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(FutureQuoteBarResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): bar_items = [] for symbol_item in self.data: identifier = symbol_item.get('contractCode') if 'items' in symbol_item: for item in symbol_item['items']: item_values = {'identifier': identifier} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = BAR_FIELD_MAPPINGS[ key] if key in BAR_FIELD_MAPPINGS else key item_values[tag] = value bar_items.append( [item_values.get(tag) for tag in COLUMNS]) self.bars = pd.DataFrame(bar_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(OptionBriefsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): brief_data = [] for item in self.data: item_values = {} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key == 'right': value = value.upper() tag = BRIEF_FIELD_MAPPINGS[key] if key in BRIEF_FIELD_MAPPINGS else key item_values[tag] = value if 'identifier' not in item_values: underlying_symbol = item_values.get('symbol') expiry = item_values.get('expiry') strike = float(item_values.get('strike')) put_call = item_values.get('right') expiry = pd.Timestamp(expiry, unit='ms', tzinfo=eastern).date().strftime("%Y%m%d") item_values['identifier'] = get_option_identifier(underlying_symbol, expiry, put_call, strike) brief_data.append([item_values.get(tag) for tag in COLUMNS]) self.briefs = pd.DataFrame(brief_data, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(ContractsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'items' in data_json: for item in data_json['items']: contract_fields = {} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = CONTRACT_FIELD_MAPPINGS[key] if key in CONTRACT_FIELD_MAPPINGS else key if tag in CONTRACT_FIELDS: contract_fields[tag] = value contract_id = contract_fields.get('contract_id') symbol = contract_fields.get('symbol') currency = contract_fields.get('currency') sec_type = contract_fields.get('sec_type') exchange = contract_fields.get('exchange') origin_symbol = contract_fields.get('origin_symbol') local_symbol = contract_fields.get('local_symbol') expiry = contract_fields.get('expiry') strike = contract_fields.get('strike') right = contract_fields.get('right') multiplier = contract_fields.get('multiplier') contract = Contract(symbol, currency, contract_id=contract_id, sec_type=sec_type, exchange=exchange, origin_symbol=origin_symbol, local_symbol=local_symbol, expiry=expiry, strike=strike, right=right, multiplier=multiplier) self.contracts.append(contract)
def parse_order(item): contract_fields = {} order_fields = {} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = ORDER_FIELD_MAPPINGS[key] if key in ORDER_FIELD_MAPPINGS else key if tag in CONTRACT_FIELDS: contract_fields[tag] = value else: order_fields[tag] = value contract_id = contract_fields.get('contract_id') symbol = contract_fields.get('symbol') currency = contract_fields.get('currency') sec_type = contract_fields.get('sec_type') exchange = contract_fields.get('exchange') origin_symbol = contract_fields.get('origin_symbol') local_symbol = contract_fields.get('local_symbol') expiry = contract_fields.get('expiry') strike = contract_fields.get('strike') put_call = contract_fields.get('right') multiplier = contract_fields.get('multiplier') contract = Contract(symbol, currency, contract_id=contract_id, sec_type=sec_type, exchange=exchange, origin_symbol=origin_symbol, local_symbol=local_symbol, expiry=expiry, strike=strike, put_call=put_call, multiplier=multiplier) account = order_fields.get('account') action = order_fields.get('action') order_type = order_fields.get('order_type') quantity = order_fields.get('quantity') limit_price = order_fields.get('limit_price') aux_price = order_fields.get('aux_price') trail_stop_price = order_fields.get('trail_stop_price') trailing_percent = order_fields.get('trailing_percent') percent_offset = order_fields.get('percent_offset') time_in_force = order_fields.get('time_in_force') outside_rth = order_fields.get('outside_rth') filled = order_fields.get('filled') avg_fill_price = order_fields.get('avg_fill_price') commission = order_fields.get('commission') realized_pnl = order_fields.get('realized_pnl') id = order_fields.get('id') order_id = order_fields.get('order_id') parent_id = order_fields.get('parent_id') status = OrdersResponse.get_status(order_fields.get('status')) order = Order(account, contract, action, order_type, quantity, limit_price=limit_price, aux_price=aux_price, trail_stop_price=trail_stop_price, trailing_percent=trailing_percent, percent_offset=percent_offset, time_in_force=time_in_force, outside_rth=outside_rth, filled=filled, avg_fill_price=avg_fill_price, commission=commission, realized_pnl=realized_pnl, id=id, order_id=order_id, parent_id=parent_id) if 'order_time' in order_fields: order.order_time = order_fields.get('order_time') if 'trade_time' in order_fields: order.trade_time = order_fields.get('trade_time') order.status = status return order
def parse_response_content(self, response_content): response = super(TradeTickResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): tick_items = [] for symbol_item in self.data: symbol = symbol_item.get('symbol') if 'items' in symbol_item: index = symbol_item.get('beginIndex') for item in symbol_item['items']: item_values = {'symbol': symbol} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key == 'type': item_values['direction'] = value else: item_values[key] = value if index is not None: item_values['index'] = index index += 1 tick_items.append( [item_values.get(tag) for tag in COLUMNS]) self.trade_ticks = pd.DataFrame(tick_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(ShortInterestResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): short_interest_items = [] for symbol_item in self.data: symbol = symbol_item.get('symbol') items = symbol_item.get('items') for item in items: item_values = {'symbol': symbol} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = SHORT_INTEREST_FIELD_MAPPINGS[ key] if key in SHORT_INTEREST_FIELD_MAPPINGS else key item_values[tag] = value short_interest_items.append( [item_values.get(tag) for tag in COLUMNS]) self.short_interests = pd.DataFrame(short_interest_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(QuoteHourTradingTimelineResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) pre_close = data_json.get('preClose') if 'detail' in data_json: detail = data_json['detail'] hour_trading = HourTrading() if 'timestamp' in response: hour_trading.latest_time = response['timestamp'] for key, value in detail.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key == 'tag': if value == '盘前': hour_trading.trading_session = TradingSession.PreMarket elif value == '盘后': hour_trading.trading_session = TradingSession.AfterHours else: tag = BRIEF_FIELD_MAPPINGS[ key] if key in BRIEF_FIELD_MAPPINGS else key if hasattr(hour_trading, tag): setattr(hour_trading, tag, value) self.hour_trading = hour_trading if 'items' in data_json: timeline_items = [] for item in data_json['items']: item_values = {'pre_close': pre_close} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = TIMELINE_FIELD_MAPPINGS[ key] if key in TIMELINE_FIELD_MAPPINGS else key item_values[tag] = value timeline_items.append( [item_values.get(tag) for tag in COLUMNS]) self.timelines = pd.DataFrame(timeline_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(SymbolsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): self.symbols = [ get_string(symbol) for symbol in self.data if symbol ]
def parse_contract(item): item_values = dict() for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = CONTRACT_FIELD_MAPPINGS[ key] if key in CONTRACT_FIELD_MAPPINGS else key item_values[tag] = value return item_values
def parse_response_content(self, response_content): response = super(QuoteHourTradingTimelineResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'detail' in data_json: detail = data_json['detail'] hour_trading = HourTrading() if 'timestamp' in response: hour_trading.latest_time = response['timestamp'] for key, value in detail.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key == 'tag': if value == '盘前': hour_trading.trading_session = TradingSession.PreMarket elif value == '盘后': hour_trading.trading_session = TradingSession.AfterHours else: tag = BRIEF_FIELD_MAPPINGS[key] if key in BRIEF_FIELD_MAPPINGS else key if hasattr(hour_trading, tag): setattr(hour_trading, tag, value) self.hour_trading = hour_trading if 'items' in data_json: for item in data_json['items']: timeline = Timeline() for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = TIMELINE_FIELD_MAPPINGS[key] if key in TIMELINE_FIELD_MAPPINGS else key if hasattr(timeline, tag): setattr(timeline, tag, value) self.timelines.append(timeline)
def parse_response_content(self, response_content): response = super(QuoteBriefResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'items' in data_json: for item in data_json['items']: brief = QuoteBrief() for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key == 'hourTrading': hour_trading = HourTrading() for sub_key, sub_value in value.items(): if isinstance(sub_value, six.string_types): sub_value = get_string(sub_value) if sub_key == 'tag': if sub_value == '盘前': hour_trading.trading_session = TradingSession.PreMarket elif sub_value == '盘后': hour_trading.trading_session = TradingSession.AfterHours else: sub_tag = BRIEF_FIELD_MAPPINGS[ sub_key] if sub_key in BRIEF_FIELD_MAPPINGS else sub_key if hasattr(hour_trading, sub_tag): setattr(hour_trading, sub_tag, sub_value) brief.hour_trading = hour_trading else: tag = BRIEF_FIELD_MAPPINGS[ key] if key in BRIEF_FIELD_MAPPINGS else key if hasattr(brief, tag): setattr(brief, tag, value) self.briefs.append(brief)
def parse_response_content(self, response_content): response = super(SymbolsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'items' in data_json: self.symbols = [ get_string(symbol) for symbol in data_json['items'] if symbol ]
def parse_response_content(self, response_content): response = super(FutureExchangeResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): items = [] for item in self.data: code, name, zone = None, None, None for key, value in item.items(): if value is None: continue if key == 'code': code = get_string(value) elif key == 'name': name = get_string(value) elif key == 'zoneId': zone = get_string(value) items.append([code, name, zone]) self.exchanges = pd.DataFrame(items, columns=['code', 'name', 'zone'])
def parse_response_content(self, response_content): response = super(ProfilesResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'items' in data_json: for item in data_json['items']: account, capability, status = None, None, None for key, value in item.items(): if value is None: continue if key == 'account': account = get_string(value) elif key == 'capability': capability = get_string(value) elif key == 'status': status = get_string(value) profile = AccountProfile(account, capability, status) self.profiles.append(profile)
def parse_contract(item): item_values = dict() for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) if key in ('lastBiddingCloseTime', 'firstNoticeDate') and (value == 0 or value == ''): continue tag = CONTRACT_FIELD_MAPPINGS[key] if key in CONTRACT_FIELD_MAPPINGS else key item_values[tag] = value return item_values
def parse_response_content(self, response_content): response = super(PositionsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'items' in data_json: for item in data_json['items']: contract_fields = {} position_fields = {} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = POSITION_FIELD_MAPPINGS[key] if key in POSITION_FIELD_MAPPINGS else key if tag in CONTRACT_FIELDS: contract_fields[tag] = value else: position_fields[tag] = value contract_id = contract_fields.get('contract_id') symbol = contract_fields.get('symbol') currency = contract_fields.get('currency') sec_type = contract_fields.get('sec_type') exchange = contract_fields.get('exchange') origin_symbol = contract_fields.get('origin_symbol') local_symbol = contract_fields.get('local_symbol') expiry = contract_fields.get('expiry') strike = contract_fields.get('strike') right = contract_fields.get('right') multiplier = contract_fields.get('multiplier') contract = Contract(symbol, currency, contract_id=contract_id, sec_type=sec_type, exchange=exchange, origin_symbol=origin_symbol, local_symbol=local_symbol, expiry=expiry, strike=strike, right=right, multiplier=multiplier) account = position_fields.get('account') quantity = position_fields.get('quantity') average_cost = position_fields.get('average_cost') market_price = position_fields.get('market_price') market_value = position_fields.get('market_value') realized_pnl = position_fields.get('realized_pnl') unrealized_pnl = position_fields.get('unrealized_pnl') position = Position(account, contract, quantity, average_cost=average_cost, market_price=market_price, market_value=market_value, realized_pnl=realized_pnl, unrealized_pnl=unrealized_pnl) self.positions.append(position)
def parse_timeline(item, symbol, pre_close, trading_session): item_values = { 'symbol': symbol, 'pre_close': pre_close, 'trading_session': trading_session } for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = TIMELINE_FIELD_MAPPINGS[ key] if key in TIMELINE_FIELD_MAPPINGS else key item_values[tag] = value return item_values
def parse_response_content(self, response_content): response = super(FinancialDailyResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): items = list() for item in self.data: item_values = dict() for key, value in item.items(): if isinstance(value, six.string_types): value = get_string(value) item_values[key] = value items.append(item_values) self.financial_daily = pd.DataFrame(items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(OptionQuoteBarResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): bar_items = [] for symbol_item in self.data: identifier = symbol_item.get('identifier') underlying_symbol = symbol_item.get('symbol') expiry = symbol_item.get('expiry') strike = float(symbol_item.get('strike')) put_call = symbol_item.get('right') if put_call: put_call = put_call.upper() if not identifier: expiration = pd.Timestamp( expiry, unit='ms', tzinfo=eastern).date().strftime("%Y%m%d") identifier = get_option_identifier(underlying_symbol, expiration, put_call, strike) if 'items' in symbol_item: for item in symbol_item['items']: item_values = { 'identifier': identifier, 'symbol': underlying_symbol, 'expiry': expiry, 'put_call': put_call, 'strike': strike } for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = BAR_FIELD_MAPPINGS[ key] if key in BAR_FIELD_MAPPINGS else key item_values[tag] = value bar_items.append( [item_values.get(tag) for tag in COLUMNS]) self.bars = pd.DataFrame(bar_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(FinancialReportResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): items = list() for item in self.data: item_values = dict() for key, value in item.items(): if isinstance(value, six.string_types): value = get_string(value) item_values[key] = value items.append(item_values) self.financial_report = pd.DataFrame(items).rename( columns=REPORT_FIELD_MAPPINGS)[COLUMNS]
def parse_response_content(self, response_content): response = super(ContractsResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = self.data if isinstance(self.data, dict) else json.loads(self.data) if 'items' in data_json: for item in data_json['items']: contract_fields = {} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = CONTRACT_FIELD_MAPPINGS[key] if key in CONTRACT_FIELD_MAPPINGS else key if tag in CONTRACT_FIELDS: contract_fields[tag] = value contract_id = contract_fields.get('contract_id') symbol = contract_fields.get('symbol') currency = contract_fields.get('currency') sec_type = contract_fields.get('sec_type') exchange = contract_fields.get('exchange') origin_symbol = contract_fields.get('origin_symbol') local_symbol = contract_fields.get('local_symbol') expiry = contract_fields.get('expiry') strike = contract_fields.get('strike') put_call = contract_fields.get('right') multiplier = contract_fields.get('multiplier') name = contract_fields.get('name') short_margin = contract_fields.get('short_margin') short_fee_rate = contract_fields.get('short_fee_rate') shortable = contract_fields.get('shortable') long_initial_margin = contract_fields.get('long_initial_margin') long_maintenance_margin = contract_fields.get('long_maintenance_margin') contract_month = contract_fields.get('contract_month') identifier = contract_fields.get('identifier') contract = Contract(symbol, currency, contract_id=contract_id, sec_type=sec_type, exchange=exchange, origin_symbol=origin_symbol, local_symbol=local_symbol, expiry=expiry, strike=strike, put_call=put_call, multiplier=multiplier, name=name, short_margin=short_margin, short_fee_rate=short_fee_rate, shortable=shortable, long_initial_margin=long_initial_margin, contract_month=contract_month, long_maintenance_margin=long_maintenance_margin, identifier=identifier) self.contracts.append(contract)
def parse_response_content(self, response_content): response = super(OptionTradeTickResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): tick_items = [] for symbol_item in self.data: if 'items' in symbol_item and len(symbol_item['items']) > 0: underlying_symbol = symbol_item.get('symbol') put_call = symbol_item.get('right').upper() expiry = symbol_item.get('expiry') strike = float(symbol_item.get('strike')) identifier = symbol_item.get('identifier') if not identifier: expiration = pd.Timestamp( expiry, unit='ms', tzinfo=eastern).date().strftime("%Y%m%d") identifier = get_option_identifier( underlying_symbol, expiration, put_call, strike) for item in symbol_item['items']: item_values = { 'identifier': identifier, 'symbol': underlying_symbol, 'expiry': expiry, 'put_call': put_call, 'strike': strike } for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) # if 'time' == key: # value = pd.Timestamp(value, unit='ms', tzinfo=eastern) item_values[key] = value tick_items.append( [item_values.get(tag) for tag in COLUMNS]) self.trade_ticks = pd.DataFrame(tick_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(FutureTradeTickResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data and isinstance(self.data, list): tick_items = [] for symbol_item in self.data: identifier = symbol_item.get('contractCode') if 'items' in symbol_item: for item in symbol_item['items'][::-1]: item_values = {'identifier': identifier} for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) item_values[key] = value tick_items.append([item_values.get(tag) for tag in COLUMNS]) self.trade_ticks = pd.DataFrame(tick_items, columns=COLUMNS)
def parse_response_content(self, response_content): response = super(QuoteBarResponse, self).parse_response_content(response_content) if 'is_success' in response: self._is_success = response['is_success'] if self.data: data_json = json.loads(self.data) if 'items' in data_json: for item in data_json['items']: bar = Bar() for key, value in item.items(): if value is None: continue if isinstance(value, six.string_types): value = get_string(value) tag = BAR_FIELD_MAPPINGS[ key] if key in BAR_FIELD_MAPPINGS else key if hasattr(bar, tag): setattr(bar, tag, value) self.bars.append(bar)