Hi, I’m new to Alpaca API and here I’m attempting to get OHLCV bar data for the crypto coin TIAUSDT, so i can paper trade it with my own strategy.
I’ve made sure the url and api is correct.
Any help is deeply appreciated. Thanks in advance
import asyncio
import logging
import time
from alpaca_trade_api.stream import Stream
from alpaca_trade_api.common import URL
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
def run_connection(conn):
try:
conn.run()
except KeyboardInterrupt:
print("Interrupted execution by user")
asyncio.get_event_loop().run_until_complete(conn.stop_ws())
exit(0)
except Exception as e:
print(f'Exception from websocket connection: {e}')
finally:
print("Trying to re-establish connection")
time.sleep(3)
run_connection(conn)
async def print_quote(q):
print('quote', q)
if __name__ == '__main__':
conn = Stream(api_key,
api_secret,
base_url=URL('https://paper-api.alpaca.markets'))
ohlc_data = conn.subscribe_crypto_bars(print_quote, 'BTCUSD')
on_crypto_bar(ohlc_data)
run_connection(conn)
Here’s the traceback:
2024-01-31 13:25:42,928 data websocket error, restarting connection: server rejected WebSocket connection: HTTP 404
2024-01-31 13:25:42,939 starting crypto data websocket connection
2024-01-31 13:25:43,447 data websocket error, restarting connection: server rejected WebSocket connection: HTTP 404
2024-01-31 13:25:43,458 starting crypto data websocket connection
2024-01-31 13:25:43,897 data websocket error, restarting connection: server rejected WebSocket connection: HTTP 404
2024-01-31 13:25:43,908 starting crypto data websocket connection