Hi everyone!
We are trying to recive our account’s trade updates along with the stream of the quotes. However, we don’t understand how to implement the trade updates. This is the code we are developing (it doesn’t work):
query_list = [‘Q.’+q for q in stockUniverse] + [‘trade_updates’]
#stockUniverse is a list of stocks
def on_open(ws):
print(“opened”)
auth_data = {“action”: “authenticate”, “data”: {“key_id”: api_key, “secret_key”: api_secret}}
ws.send(json.dumps(auth_data))
query = {“action”: “listen”, “data”: {“streams”: query_list}}
ws.send(json.dumps(query))
def on_message(ws, message):
print(message)
ws=websocket.WebSocketApp(streamURL, on_open = on_open, on_message = on_message)
ws.run_forever()
Could you help us?
Thanks!
Shlomik
September 23, 2020, 3:45pm
2
Hi, here’s an example algorithm to receive websocket stream (updates, quotes, trades, …)
okay with it to learn what you are looking for.
from alpaca_trade_api import StreamConn
from alpaca_trade_api.common import URL
ALPACA_API_KEY = "<YOUR-API-KEY>"
ALPACA_SECRET_KEY = "<YOUR-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'),
data_stream='polygon' if USE_POLYGON else 'alpacadatav1'
)
This file has been truncated. show original
1 Like
can you reshare this? The link to full code doesn’t work