Exemplo n.º 1
0
def getTickerPriceDates2Db(ticker,bucket,org,date1,date2,url,token):

    #stock = yf.Ticker(ticker)
    #stock_history=stock.history(period="max")
    stock_history=yf.download(ticker,start=date1, end=date2)
    if stock_history.empty:
            return

    print("=============")
    print("ticker:",ticker)
    print(stock_history)
    num_records = len(stock_history)
    print("length:",num_records)

    for i in range(num_records):
        print("record:",i)
        dictionary_stock_history = stock_history.to_dict('records')
        field_string=dictionary_stock_history[i]
        time_string=str(stock_history.index.values[i])
        time_string=time_string[:-3]
        #print(time_string)
        utc_time = datetime.strptime(time_string,"%Y-%m-%dT%H:%M:%S.%f")
        utc_time=int(utc_time.timestamp())
        open = float(field_string['Open'])
        high = float(field_string['High'])
        low = float(field_string['Low'])
        close = float(field_string["Close"])
        volume = float(field_string['Volume'])

        q = influxdb_client.Point("price").tag("ticker",ticker).field("close",close).field("high",high).field("low",low).field("open",open).field("volume",volume).time(time_string)
        writePriceToDb(q,bucket,org,url,token)
Exemplo n.º 2
0
choices = {'Pionero':'CFIPIONERO.SN','Moneda Latinoamérica Deuda Local (Serie A)':'CFIMLDL.SN','Moneda Renta CLP':'CFIMRCLP.SN'}

#print(new_table)
#print(d.items())
midnight = datetime.combine(datetime.today(), time.min)
yesterday=midnight-timedelta(days=1)
#print("yesterday:",yesterday)
#insertdate = yesterday
#print(midnight)
for i in range(row_marker):
    fund_name=new_table[0][i].strip()
    test_string=new_table[1][i].strip()
    currency=test_string[0:3]
    value=float((test_string[3:].replace(".","")).strip().replace(",","."))
    print("Fondo:",fund_name,"; Moneda:",currency,";Valor Cuota:",value)
    ticker=choices.get(fund_name,0)
##DEBUG
#    print(new_table)
##DEBUG
#    exit()
    if ticker != 0:
        print("yes:",value,insertdate,currency)
        q = influxdb_client.Point("price").tag("ticker",ticker).tag("name",fund_name).tag("currency",currency).field("nav",value).time(insertdate)
        writePriceToDb(q,bucket,org,config.url,config.token)
        if currency == "USD" and is_number(usd_obs):
            value=value*usd_obs
            print("value clp:",value,"date:",insertdate)
            q = influxdb_client.Point("price").tag("ticker",ticker).tag("name",fund_name).tag("currency","CLP").field("nav",value).time(insertdate)
            writePriceToDb(q,bucket,org,config.url,config.token)