Exemple #1
0
def main():
    log.info("Started...")

    conn = connect(config_database_connect)
    cur = conn.cursor(cursor_factory=DictCursor)
    sql = "select * from accounts_types where download=true"
    cur.execute(sql)
    banks = cur.fetchall()
    for bank in banks:
        try:
            log.info("Downloading: " + " " + bank['description'])
            GlobalConfig = OfxConfig()
            a = GlobalConfig.account(bank['id'])
            ofxdata = a.download(days=0)
            f = open(path.expanduser('~/tmp/ofxdata.tmp'), 'w')
            f.write(ofxdata.read())
            f.close()
            f = open(path.expanduser('~/tmp/ofxdata.tmp'), 'r')
            parsed = OfxParser.parse(f)
            f.close()
            log.info("OfxParser complete")
            positions = {}
            for pos in parsed.account.statement.positions:
                positions[pos.security] = round(pos.units * pos.unit_price, 2)
                log.info("Downloaded: " + str(bank['description']) + " " +
                         str(pos.security))

            sql = "select * from accounts where type=" + str(bank['type'])
            cur.execute(sql)
            accounts = cur.fetchall()
            for account in accounts:
                if account['name'] not in positions:
                    raise Exception('account ' + account['name'] +
                                    ' not present in download')
                log.info(bank['description'] + '\t' + account['name_local'] +
                         '\t' + str(positions[account['name']]))
                sql = "update constituents set value=" + str(
                    positions[account['name']]
                ) + "where symbol='" + account['name_local'] + "'"
                cur.execute(sql)
                conn.commit()
                log.info("Set: " + str(account['name_local']))

        except Exception as err:
            log.exception(err)
            log.error("Failed loading for bank: " + bank['description'])

    # Close the db
    cur.close()
    conn.close()
    log.info("Completed")
def populate_price_and_value(db, rows, populate_value):
    for row in rows:
        log.info( "Downloading %s..." % ( row.symbol ) )
        try:
            row.price = last( get_market_data_symbol( row.symbol ) )
            if populate_value:
                row.value = row.price * row.quantity
            log.info( "Updated %s..." % ( row.symbol ) )
        except Exception as err:
            log.error( "Could not get price for %s" % ( row.symbol ) )
            log.exception(err)
            continue    
        
    log.info( "Committing transaction..." )
    db.commit()
    log.info( "Done" )
Exemple #3
0
def main():
    log.info("Started...")
        
    conn = connect( config_database_connect )
    cur = conn.cursor(cursor_factory=DictCursor)
    sql = "select * from accounts_types where download=true";
    cur.execute(sql)
    banks = cur.fetchall()   
    for bank in banks:
        try:
            log.info("Downloading: " + " " + bank['description'])
            GlobalConfig = OfxConfig()
            a = GlobalConfig.account(bank['id'])
            ofxdata = a.download(days=0)
            f = open(path.expanduser('~/tmp/ofxdata.tmp'), 'w')
            f.write(ofxdata.read())
            f.close()
            f = open(path.expanduser('~/tmp/ofxdata.tmp'), 'r')
            parsed = OfxParser.parse(f)
            f.close()
            log.info("OfxParser complete")
            positions = {}
            for pos in parsed.account.statement.positions:
                positions[pos.security] = round(pos.units * pos.unit_price, 2)
                log.info("Downloaded: " + str(bank['description']) + " " + str(pos.security))
            
            sql = "select * from accounts where type=" + str(bank['type']);
            cur.execute(sql)
            accounts = cur.fetchall()
            for account in accounts:
                if account['name'] not in positions:
                    raise Exception('account ' + account['name'] + ' not present in download')
                log.info( bank['description'] + '\t' + account['name_local'] + '\t' + str(positions[account['name']]) ) 
                sql = "update constituents set value=" + str(positions[account['name']]) + "where symbol='" + account['name_local'] + "'"
                cur.execute(sql)
                conn.commit()
                log.info("Set: " + str(account['name_local']))
                
        except Exception as err:
            log.exception(err)
            log.error("Failed loading for bank: " + bank['description'])
    
    # Close the db
    cur.close()
    conn.close()
    log.info("Completed")
Exemple #4
0
def populate_price_and_value(db, rows, populate_value):
    for row in rows:
        log.info("Downloading %s..." % (row.symbol))
        fx = 1
        if row.symbol in CONST_FX_MAP:
            fx = CONST_FX_MAP[row.symbol]
            log.info("Using fx %f" % (fx))
        try:
            row.price = last(row.symbol)
            if populate_value:
                row.value = row.price * (Decimal(1) / fx) * row.quantity
            log.info("Updated %s..." % (row.symbol))
        except Exception as err:
            log.error("Could not get price for %s" % (row.symbol))
            log.exception(err)
            continue

    log.info("Committing transaction...")
    db.commit()
    log.info("Done")
        row = db.session.query(db.Stocks, db.Constituents).\
            filter(db.Constituents.stock_id == db.Stocks.id).\
            filter(db.Constituents.portfolio_id == db.CONST_PORTFOLIO_PLAY).\
            order_by(db.Stocks.__table__.columns[col].desc()).\
            first().stocks
        table.append( [ col + "_up", row.symbol, getattr(row, col), getattr(row, col + "_date" ) ] )
        row = db.session.query(db.Stocks, db.Constituents).\
            filter(db.Constituents.stock_id == db.Stocks.id).\
            filter(db.Constituents.portfolio_id == db.CONST_PORTFOLIO_PLAY).\
            order_by(db.Stocks.__table__.columns[col].asc()).\
            first().stocks
        table.append( [ col + "_down", row.symbol, getattr(row, col), getattr(row, col + "_date" ) ] )
    rpt.add_table( table, formats )

def main():
    log.info("Started...")
    db = database2()
    rpt = report()
    
    populate_max_movers( db, rpt )
    subject = 'Health Check - ' + strftime("%Y-%m-%d", localtime())
     
    send_mail_html_self(subject, rpt.get_html())
    log.info("Completed")

if __name__ == '__main__':
    try:
        main()    
    except Exception as err:
        log.exception(err)
        log.info("Aborted")
    md = market_data_by_symbol(i['symbol'])
    if md == None:
        log.info("POST market_data: %s, %f" % (i['symbol'], l))
        post_market_data(i['id'], l)
    else:
        log.info("PUT market_data: %s, %f" % (i['symbol'], l))
        put_market_data(md['id'], i['id'], l)


def main():
    log.info("Started loading market data...")
    log.info("Loading focus names...")
    instruments_focus = ref_data_focus()
    #instruments = ref_data()
    for i in instruments_focus:
        populate_market_data(i)
        #instruments = [x for x in instruments if x['symbolAlphaVantage'] != i['symbolAlphaVantage']]

    #log.info("Loading blurry names...")
    #for i in instruments:
    #populate_market_data(i)

    log.info("Completed")


if __name__ == '__main__':
    try:
        main()
    except Exception as err:
        log.exception(err)
        log.info("Aborted")