示例#1
0
epoch = datetime(1970, 1, 1)

dict_key = {
    '1. open': 'DAILYOPEN:IBM',
    '2. high': 'DAILYHIGH:IBM',
    '3. low': 'DAILYLOW:IBM',
    '4. close': 'DAILYCLOSE:IBM',
    '5. adjusted close': 'DAILYADJCLOSE:IBM',
    '6. volume': 'DAILYVOL:IBM',
    '7. dividend amount': 'DAILYAMNT:IBM',
    '8. split coefficient': 'DAILYSPLIT:IBM',
}
dict_price = {}

for date in data['Time Series (Daily)']:
    for price_type in data['Time Series (Daily)'][date]:
        price_data = data['Time Series (Daily)'][date][price_type]
        add_price_data = (
            dict_key[price_type],
            int((datetime.strptime(str(date), dtFmt) - epoch).total_seconds() *
                1000), price_data)
        if price_type not in dict_price:
            dict_price[price_type] = [add_price_data]
        else:
            dict_price[price_type].append(add_price_data)

rts.madd(list(dict_price['1. open']))
rts.madd(list(dict_price['2. high']))
rts.madd(list(dict_price['3. low']))
rts.madd(list(dict_price['4. close']))
    newdt = datetime.utcfromtimestamp((datetime.strptime(str(rsiDateTime), dailydtFmt) - epoch).total_seconds())
    ##
    ## Creating a tuple of each time series entry.
    ## Converting regular string timestamp that was created above to integer.
    ##
    eachIntradayPrice = ( 'DAILYRSI:GS'
                        , int((datetime.strptime(str(rsiDateTime), dailydtFmt) - epoch).total_seconds()*1000)
                        , indicatorList[0][x])
    ##
    ## Add each tuple to the list
    ##
    RSIIndicatorList.append(eachIntradayPrice)
##
## Adding the list of tuples to Redis TimeSeries database using the MADD command
##
rts.madd(RSIIndicatorList)

##
## Intraday Stock Prices For Goldman Sachs Group
##
## Date for which intraday stock prices will be retrieved.
## Change it as you deem necessary
firstWkDate = datetime(2020, 11, 13)
intraDayPricesDF = get_historical_intraday("GS"
                                           , firstWkDate
                                           , output_format='pandas'
                                           , token="<Your IEX API Key>")

dtFmt = '%Y-%m-%d %H:%M:%S'
epoch = datetime(1970, 1, 1)
intradayPriceList = []
示例#3
0
        *[[x.value, parse_time(x.time)] for x in temperature])
    return temperature_time, temperature_value


#Initialize Redis Client
try:
    #rts = Client(host=os.environ.get('REDIS_HOST'),port=os.environ.get('REDIS_PORT'))
    rts = Client(host='localhost', port=6379)
except:
    logging.warning('Could not connect to redis server')
key = 'Temperature'

# Create a key if it doesnt exists
try:
    rts.create(key, retention_msecs=DAY)
except ResponseError as e:
    s = str(e)
    print(s)
    pass

while (True):
    try:
        temperature_time, temperature_value = pull()
    except ResponseError:
        logging.warning('Failed to Pull data')
    out = [(key, time, value)
           for time, value in zip(temperature_time, temperature_value)]
    t = rts.madd(out)
    logging.warning('key inserted with last timestamp: {0}'.format(t[-1]))
    sleep(60 * 2)