def main(): # parse args parser = ap.ArgumentParser() parser.add_argument('csv', type=str, help='CSV file to read products from') parser.add_argument('--budget', metavar='budget', type=int, required=True, help='Total budget to initialize db with.') parser.add_argument('--tick-length', metavar='tick_length', type=int, required=True, help='The length of a tick.') parser.add_argument('--tick-count', metavar='tick_count', type=int, required=True, help='Total number of planned ticks.') parser.add_argument('--quarantine', metavar='quarantine', type=int, required=True, help='Total number of planned ticks.') parsed = parser.parse_args() # get products and construct zero adjustments products = parse_products_csv(parsed.csv) adjustments = {product['code']: 0 for product in products} # setup DB db = Database(Exchange.DATABASE_FILE) db.connect() # ensure schema exists for statement in open('schema.sql').read().split(';'): db.exe(statement) # set configuration db.set_config_stock_running(False) db.set_config_budget(parsed.budget) db.set_config_tick_length(parsed.tick_length) db.set_config_total_ticks(parsed.tick_count) db.set_config_quarantine(parsed.quarantine) db.import_products(products, replace_existing=True) try: db.do_tick(adjustments, tick_no=0) except Exception as e: print('tick data already exsist') print(f'error: {e}') db.close()
import argparse from bearstock.stock import Exchange from bearstock.database import Database if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--seconds', type=int, required=True) parsed = parser.parse_args() db = Database(Exchange.DATABASE_FILE) db.connect() db.set_config_quarantine(parsed.seconds) print(f'Quarantine time set to {parsed.seconds}') db.close()