Subscribing an indicator

I have been trying to get my program to subscribe to tick bars for a given symbol and I can’t seem to get it to work. I’ve read the documentation and I don’t understand what I am supposed to do differently. Below is the code for subscribing and opening a webSocket I’ve used:

import websocket
import requests

import IRONBEAM_Client as client


def get_streamId(token):

    streamId = client.getStreamId(token)
    return streamId

def subscribe(token, streamId):

    base_url = "https://demo.ironbeamapi.com/v2"
    endpoint = f"/indicator/{streamId}/tickBars/subscribe"
    
    url = f"{base_url}{endpoint}?token={token['token']}"

    payload = {
        "symbol": "XCME:NQ.M25",
        "period": 1,
        "barType": "DAILY",
        "loadSize": 100
    }

    try:
        resp = requests.post(url, json=payload)
        resp.raise_for_status()
        data = resp.json()
        print("Subscribe tick bars response:", data)
    except requests.HTTPError as e:
        print("Failed to subscribe to tick bars:", e, e.response.text)


def open_stream(token, streamId):
    url = f"wss://demo.ironbeamapi.com/v2/stream/{streamId}?token={token['token']}"

    def on_open(ws):
        print("Stream opened")

    def on_message(ws, message):
        print("Received message:", message)
    
    # Callback: print errors.
    def on_error(ws, error):
        print("WebSocket error:", error)
    
    # Callback: inform when the connection is closed.
    def on_close(ws, close_status_code, close_msg):
        print("WebSocket closed with code:", close_status_code, "message:", close_msg)
    
    # Create the WebSocketApp with the callbacks.
    ws_app = websocket.WebSocketApp(url,
                                    on_open=on_open,
                                    on_message=on_message,
                                    on_error=on_error,
                                    on_close=on_close)


    ws_app.run_forever()

I call these functions in this order :

streamId = get_streamId(token)
subscribe(token, streamId)
open_stream(token, streamId)

The error I am getting is:
Failed to subscribe to tick bars: 400 Client Error: Bad Request for url:…{“additionalProperties”:{},“error1”:“Can’t subscribe to tick bars”,“status”:“ERROR”,“message”:“Error”}

I know that the token is good because I can use it in other contexts like getting my account balance or other stuff, the streamId is also correct because if I don’t call subscribe() the stream opens and I get pinged.

Any help would be greatly appreciated

For anyone having the same problem I found out what I did wrong. The stream needs to be opened before you can actually subscribe to a symbol.

I also ran into this issue. Although it’s not obvious from reading the documentation, you need to open the stream before creating the subscription.

streamId = get_streamId(token)
open_stream(token, streamId)
subscribe(token, streamId)
1 Like

Also in the same type of issue. We cant unsubscribe either. I now 55 active subscriptions on data. Have tried all types of endpoints etc.
So we setup a stream right now I dont even subscribe to an a symbol since we have so many right now. Then i run the websocket and run something like this
curl --location --request DELETE ‘https://demo.ironbeamapi.com/v2/indicator/03863310-49b9-4f17-acd2-0d2cc110e132/unsubscribe/TimeBars_638838589480433621
–header ‘Accept: application/json’
–header ‘Authorization: ••••••’

And the result I get is:
{“additionalProperties”:{},“error1”:“Can’t unsubscribe”,“status”:“ERROR”,“message”:“Error”}

so we “cant subscribe” except it do actually subscribe since we get data etc. Then we cant unsubscribe so we cant get rid of getting the data 55 times. Any ideas?

A question here. Im trying to get this working. I use node but the basic is the same.
So we create a stream, We setup the stream, We recieve ping on the stream.
I then send something like this
curl -X POST “https://demo.ironbeamapi.com/v2/indicator/YOUR_STREAM_ID/timeBars/subscribe
-H “Content-Type: application/json”
-H “Authorization: Bearer YOUR_TOKEN”
-d ‘{
“symbol”: “XCME:MES.M25”,
“period”: 5,
“barType”: “MINUTE”,
“loadSize”: 5
}’

Tried it in program but also side after a litle wile. I then directly in the stream see time bars but then I recieve this {“additionalProperties”:{},“error1”:“Can’t subscribe to time bars”,“status”:“ERROR”,“message”:“Error”} right now its Saturday so I guess we dont have that much movment but i guess that should not matter here. error code is 400

Have tried waiting different long time and also in the example to really separate the processes from each other.

Any tips?

And lastly something I thought of now. Should not subscriptions be tiden to streamId? Why do i get stream results on subscriptions made on other stream id?

Feels like we have issues here with the stream that is either by design but not documented or bugs.