Esempio 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()
import sys
import csv

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

db = Database(Exchange.DATABASE_FILE)
db.connect()

filename = sys.argv[1]

with open(filename, 'r') as csvfile:
    # detect dialect
    dialect = csv.Sniffer().sniff(csvfile.readline().rstrip(',;\t'))
    csvfile.seek(0)
    # parse
    reader = csv.reader(csvfile, dialect=dialect)
    next(reader)
    for row in reader:
        name = row[4]
        username = row[5]
        db.insert_buyer(name=name, username=username, icon=None)
Esempio n. 3
0
    def run_default(self):
        db = Database(Exchange.DATABASE_FILE)
        db.connect()

        Exchange(db).run()