def index(): json_scorecards = retrieve_all_scorecards(db[BKT_SCORECARDS]) json_ptrading = json.dumps(get_traded_strategies(db[PAPER_TRADING], True), default=to_json) response.set_header('Content-Type', 'text/html') return template('templates/backtests', json_scorecards=json_scorecards, json_ptrading=json_ptrading)
def main(args): db = MongoClient(args.host, args.port)[args.db] now = datetime.datetime.utcnow() markets = list(islice(get_future_markets(hours=args.hours), 0, 1)) logging.info('Found %d horse races in the next %d hours' % (len(markets), args.hours)) strats = get_traded_strategies(db[args.paper_trading], True) for s in strats: strat = Balius.from_dict(db[BKT_STRATEGIES].find_one({'_id': s['strategy_id']})) strat.max_expsoure = 1e6 ex = PaperExecutionService() backtest(ex, strat, markets) bets = ex.get_mu_bets()[0] if len(bets) == 0: logging.info('Strategy with id=%s did not place any bets.' % s['strategy_id']) continue for bet in bets: bet['strategy_id'] = s['strategy_id'] bet['timestamp'] = now db[args.paper_bets].insert(bets) logging.info('Successfully insert %d bets for strategy with id=%s' % (len(bets), s['strategy_id']))
def paper_strategies_trading(): strats = get_traded_strategies(db[PAPER_TRADING], True) response.set_header('Content-Type', 'application/json') return json.dumps(strats, default=to_json)
def paper_summary(): json_strats = json.dumps(get_traded_strategies(db[PAPER_TRADING]), default=to_json) response.set_header('Content-Type', 'text/html') return template('templates/paper', json_strats=json_strats)