Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
import argparse

from bearstock.stock import Exchange
from bearstock.database import Database

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--on', action='store_true')
    group.add_argument('--off', action='store_true')
    parsed = parser.parse_args()

    if not parsed.on and not parsed.off:
        print('please supply eithe \'--on\' or \'--off\'')
    else:
        db = Database(Exchange.DATABASE_FILE)
        db.connect()

        if parsed.on:
            db.set_config_stock_running(True)
            print('Ticks turned ON')
        else:
            db.set_config_stock_running(False)
            print('Ticks turned OFF')

        db.close()