Beispiel #1
0
    def from_config(self, config):
        root = os.path.join(cfg.DATA_DIR, config['experiment'])
        store = DATA_STORES[cfg.DATA_STORE](root)
        feed = load_feed(
            name=config['feed']['name'],
            fpath=config['feed']['fpath'],
            assets=[Asset.from_symbol(a) for a in config['feed']['symbols']],
            timeframe=Timeframe[config['feed']['timeframe']],
            start=str_to_date(config['feed'].get('start')),
            end=str_to_date(config['feed'].get('end')),
        )
        feed.initialize(exchange)
        perf = PerformanceTracker(
            starting_cash=config['starting_cash'],
            timeframe=Timeframe[config['feed']['timeframe']],
            store=store)
        record = Record(config=cfg,
                        portfolio=Portfolio(config['cash_currency'],
                                            config['starting_cash'], perf),
                        balance=Balance.from_dict(config['balance']),
                        store=store)
        exchange = load_exchange(config['exchange']['exchange_id'],
                                 cfg=config['exchange'])
        logger = get_logger(fpath=root,
                            logger_name='progress',
                            ch_log_level=logging.INFO)

        return Context(exchange=exchange,
                       feed=feed,
                       record=record,
                       logger=logger)
Beispiel #2
0
def download_and_save_order_book_data(exchange_id, asset, depth):
    exchange = load_exchange(exchange_id)
    depth = {} if depth is None else {'depth': depth}
    data = exchange.fetch_order_book(asset, depth)
    fname = get_order_book_fname(exchange_id, asset)
    fpath = Path(ORDER_BOOK_DIR, fname)
    utils.files.save_dct(fpath, data, mode='a+')
    return fpath
Beispiel #3
0
def paperexchange(balance, asset):
    exchange_id = ex_cfg.BINANCE
    assets = [asset]
    balance = deepcopy(balance)
    timeframe = Timeframe.ONE_MIN

    # Ensuring we have data for the paper exchange
    start = datetime(year=2018, month=1, day=1, hour=0)
    end = datetime(year=2018, month=1, day=2, hour=0)
    data_exchange = load_exchange(exchange_id)
    ohlcv_feed.download_ohlcv([data_exchange], assets, timeframe, start, end)

    feed = ohlcv_feed.OHLCVFileFeed(exchange_ids=[exchange_id],
                                    assets=assets,
                                    timeframe=timeframe,
                                    start=None,
                                    end=None)
    feed.next()
    ex = load_feed_based_paper_exchange(balance, feed, exchange_id)
    return ex
Beispiel #4
0
def ccxtexchange():
    return load_exchange(ex_cfg.BINANCE)
Beispiel #5
0
            assets=[asset],
            timeframe=timeframe,
            start=
            None,  # Usually None for backtest, but its possible to filter the csv
            end=None)
        exchange = load_feed_based_paper_exchange(deepcopy(balance), feed,
                                                  exchange_id)
        runner.backtest(experiment_name, exchange, portfolio.balance,
                        portfolio, feed, strategy)

    elif trade_mode is TradeMode.SIMULATE:
        exchange = load_ccxt_based_paper_exchange(deepcopy(balance),
                                                  feedexchange_id)
        feed = OHLCVExchangeFeed(exchange=exchange,
                                 assets=[asset],
                                 timeframe=timeframe,
                                 start=datetime.datetime.utcnow(),
                                 end=None)
        runner.simulate(experiment_name, exchange, balance, portfolio, feed,
                        strategy)

    elif trade_mode is TradeMode.LIVE:
        exchange = load_exchange(exchange_id)
        feed = OHLCVExchangeFeed(exchange=exchange,
                                 assets=[asset],
                                 timeframe=timeframe,
                                 start=datetime.datetime.utcnow(),
                                 end=None)
        runner.live(experiment_name, exchange, balance, portfolio, feed,
                    strategy)
Beispiel #6
0
def fetch_and_save(ex_id, asset, timeframe, start, end):
    exchange = load_exchange(ex_id)
    df = ohlcv_feed.fetch_asset(exchange, asset, timeframe, start, end)
    fpath = get_rotating_ohlcv_fpath(ex_id, asset, timeframe, start)
    df.to_csv(fpath, index=True)
    return df
Beispiel #7
0
def paperexchange():
    return load_exchange(ex_cfg.PAPER)