Hi,
After reading https://alpaca.markets/learn/alpaca-proxy-agent-01/ and https://alpaca.markets/learn/alpaca-proxy-agent-02/ , I followed the instructions and attempted to setup the alpaca proxy agent, without success, for quite some time. The author is obviously quite talented and capable, but simple users may need some additional information to get the service working.
On a linux machine with alpaca-trade-api, websockets, and additional python requirements properly setup (including docker), follow the instructions from the author.
The easiest way to use the service, without taking into account security, is to pull and run the docker image:
docker pull shlomik/alpaca-proxy-agent
docker run -p 8765:8765 -e USE_POLYGON=false shlomik/alpaca-proxy-agent
This starts up a docker container as root.
Find the container name or id of the running alpaca proxy agent:
docker container ps -a
This will give you a “CONTAINER_ID” or “NAMES” parameter to use.
Here is an example output from above command:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9e967616212 shlomik/alpaca-proxy-agent “/bin/sh -c 'python …” 35 minutes ago Up 35 minutes 0.0.0.0:8765->8765/tcp awesome_mcnulty
I used this command to find the IP address of the alpaca proxy agent docker container:
docker inspect --format=’{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ d9e967616212
This command will return an IP address - for example: 172.17.0.2 (Copy this address)
Probably the easiest way to test the proxy agent is to edit the author’s websocket_example.py, which is found in the alpaca-trade-api-python/examples subdirectory.
Edit the example websocket example, enter your ALPACA_API_KEY and ALPACA_SECRET_KEY parameters, and change the data_url to the docker container IP address and proxy port number. It’s also important to change 'https" to “http”, as the proxy agent does not use secure socket layers (SSL). Here’s an example of how the changes appear:
import os
ALPACA_API_KEY = os.environ[‘APCA_API_KEY_ID’]
ALPACA_SECRET_KEY = os.environ[‘APCA_API_SECRET_KEY’]
USE_POLYGON = False
if name == ‘main’:
import logging
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
conn = StreamConn(
ALPACA_API_KEY,
ALPACA_SECRET_KEY,
base_url=URL('https://paper-api.alpaca.markets'),
# data_url=URL('https://data.alpaca.markets'), **<--- comment this out.**
**data_url=URL('http://172.17.0.2:8765'),**
Next export the environment variable “DATA_PROXY_WS” or place it in your shell configuration file (.bashrc for example). Be sure to source the .bashrc file after editing or open a new IDE.
export DATA_PROXY_WS=“ws://172.17.0.2:8765”
That’s it - make sure the docker container is running and execute the example websocket in a separate shell:
python websocket_example.py
You should see some authentication and logging information in the proxy server shell.
I have not tested the polygon websocket connection yet, but hopefully it will execute without issue. You should be able to run multiple instances of streaming clients, as advertised by the author’s intent.
Hope this helps other simple users, like myself.
Best Regards,
Joe O.