Skip to content

Commit b6a805c

Browse files
author
Shlomi Kushchi
authored
Merge pull request #109 from alpacahq/make_project_compatible_to_proxy_agent
Make project compatible with proxy agent
2 parents 980b532 + 3b5aee6 commit b6a805c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ using 'key_id' and 'secret_key'.
9191
The 'paper' parameter is default to False, which allows live trading.
9292
If you set it to True, then you are in the paper trading mode.
9393

94+
## Running Multiple Algorithm/Symbols
95+
There's a way to execute an algorithm with multiple datas or/and execute more than one algorithm.<br>
96+
The websocket connection is limited to 1 connection per account. Alpaca backtrader opens a websocket connection for each data you define.<br>
97+
For that exact purpose this project was created: https://github.com/shlomikushchi/alpaca-proxy-agent <br>
98+
The steps to execute this are:
99+
* Run the Alpaca Proxy Agent as described in the project's README
100+
* Define this env variable: `DATA_PROXY_WS` to be the address of the proxy agent. (e.g: `DATA_PROXY_WS=ws://192.168.99.100:8765`)
101+
* execute your algorithm. it will connect to the servers through the proxy agent allowing you to execute multiple datas/strategies
102+
94103
## Support and Contribution
95104

96105
For technical issues particular to this module, please report the

alpaca_backtrader_api/alpacastore.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3-
3+
import os
44
import collections
55
from enum import Enum
66
import traceback
@@ -119,6 +119,7 @@ def __init__(
119119
self.conn = tradeapi.StreamConn(api_key,
120120
api_secret,
121121
base_url,
122+
data_url=data_url,
122123
data_stream=self.data_stream)
123124
self.instrument = instrument
124125
self.method = method
@@ -345,6 +346,7 @@ def _t_streaming_events(self, q, tmout=None):
345346
api_key=self.p.key_id,
346347
api_secret=self.p.secret_key,
347348
base_url=self.p.base_url,
349+
data_url=os.environ.get("DATA_PROXY_WS", ''),
348350
data_stream='polygon' if self.p.usePolygon else
349351
'alpacadatav1'
350352
)
@@ -694,6 +696,7 @@ def _t_streaming_prices(self, dataname, q, tmout):
694696
instrument=dataname,
695697
method='quote',
696698
base_url=self.p.base_url,
699+
data_url=os.environ.get("DATA_PROXY_WS", ''),
697700
data_stream='polygon' if self.p.usePolygon else
698701
'alpacadatav1')
699702

0 commit comments

Comments
 (0)