def get_incoming_tick_data(self, ticker): """ Stores the midpoint of incoming price data to a pandas DataFrame `df_hist`. :param ticker: The incoming tick data as a Ticker object. """ symbol = self.get_symbol(ticker.contract) dt_obj = dt_util.convert_utc_datetime(ticker.time) bid = ticker.open ask = ticker.high
def get_incoming_tick_data(self, ticker): """ Stores the midpoint of incoming price data to a pandas DataFrame `df_hist`. :param ticker: The incoming tick data as a Ticker object. """ symbol = self.get_symbol(ticker.contract) dt_obj = dt_util.convert_utc_datetime(ticker.time) bid = ticker.bid ask = ticker.ask mid = (bid + ask) / 2 self.df_hist.loc[dt_obj, symbol] = mid if len(self.df_hist) > 1: print(self.df_hist.iloc[-1])
def get_incoming_tick_data(self, ticker): """ Stores the midpoint of incoming price data to a pandas DataFrame `df_hist`. :param ticker: The incoming tick data as a Ticker object. """ symbol = self.get_symbol(ticker.contract) dt_obj = dt_util.convert_utc_datetime(ticker.time) self.lastTime = dt_obj bid = ticker.bid ask = ticker.ask mid = (bid + ask) / 2 try: self.df_hist.loc[(dt_obj, symbol)] = mid except Exception as e: print(e)
def get_historical_data_backend(self): data = pickle.load(open(self.dataDirectory, "rb" ) ) close = data.xs('CLOSE', axis = 1, level = 1) toTrade = [x for x in self.symbols] if self.exchange == 'ASX': toTrade_ = [x+ '.AX' for x in self.symbols] elif self.exchange == 'SEHK': toTrade_ = [x+ '.HK' for x in self.symbols] for index, tick in enumerate(toTrade_): if len(tick)==6: toTrade_[index] = '0'+toTrade_[index] else: toTrade_ = toTrade #Fill missing (recent) data with yahoo data price = pdr.get_data_yahoo(toTrade_) df = price['Adj Close'].dropna() df.columns = [self.assetA, self.assetB] df = df[[not x for x in df.index.duplicated()]] missingDates = df[[dx not in close.index and dx > close.index[-1] for dx in df.index ]] #Don't include the price for today missingDates = missingDates[missingDates.index<pd.Timestamp.today().normalize()] # Simply to ensure that the column order is conistent if all([x in df.columns for x in close.columns]): close = close[toTrade_] close.columns = toTrade close = pd.concat([close,missingDates], sort=True).dropna() close = close[[self.assetA, self.assetB]] else: close=missingDates close = close[[self.assetA, self.assetB]] if close is not None: self.df_hist = close del data del close self.df_hist.index = [dt_util.convert_utc_datetime(x) for x in self.df_hist.index] else: print('No Histocial Data.')