alpacahq/alpaca-backtrader-api

Multiple datas has connection limited error?

kang205 opened this issue · 0 comments

It seems Alpaca's wss server only allow 1 connection (I had the unlimited plan but also had this issue), and the example seems to have 2 connections to the wss server, which causing a "connection limit exceed" error.

If I change one of the datas to the "iex" data feed, it will work (as they're two different wss server). However, I'd love to have both data from sip. Is there any solution on this? Many thanks!

if __name__ == '__main__':
    import logging
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

    cerebro = bt.Cerebro()
    cerebro.addstrategy(SmaCross1)

    store = alpaca_backtrader_api.AlpacaStore(
        key_id=ALPACA_API_KEY,
        secret_key=ALPACA_SECRET_KEY,
        paper=not IS_LIVE,
    )

    DataFactory = store.getdata  # or use alpaca_backtrader_api.AlpacaData
    if IS_BACKTEST:
        pass
    else:
        fromdate=datetime.utcnow() - dt.timedelta(minutes=70)
        data0 = DataFactory(dataname=symbol0,
                            historical=False,
                            timeframe=bt.TimeFrame.TFrame("Minutes"),
                            backfill_start=True,
                            compression=1,
                            fromdate=fromdate,
                            data_feed='sip'
                            )
        data1 = DataFactory(dataname=symbol1,
                            historical=False,
                            timeframe=bt.TimeFrame.TFrame("Minutes"),
                            backfill_start=True,
                            compression=1,
                            fromdate=fromdate,
                            data_feed='sip'
                            )
        # or just alpaca_backtrader_api.AlpacaBroker()
        broker = store.getbroker()
        cerebro.setbroker(broker)
    cerebro.adddata(data0)
    cerebro.adddata(data1)