Candle data and mark price not matching with he candles seen on trading terminal

// subscription
DELTA_WS_URL = “wss://socket.delta.exchange”
SUBSCRIBE_MESSAGE = {
“type”: “subscribe”,
“payload”: {
“channels”: [
{“name”: “candlestick_1m”, “symbols”: [“BTCUSD”]},
{“name”: “candlestick_15m”, “symbols”: [“BTCUSD”]},
{“name”: “candlestick_30m”, “symbols”: [“BTCUSD”]},
{“name”: “candlestick_1h”, “symbols”: [“BTCUSD”]},
{“name”: “candlestick_4h”, “symbols”: [“BTCUSD”]},
{“name”: “v2/ticker”, “symbols”: [“BTCUSD”]}
]
}
}
// Driver code part
log(f"Received data: {data}", level=‘debug’)
closePrice = None
# Handle candlestick feeds
if msg_type.startswith(“candlestick_”):
if data.get(“symbol”) == “BTCUSD”:
o = float(data[“open”])
h = float(data[“high”])
l = float(data[“low”])
c = float(data[“close”])
vol = float(data[“volume”])
cst_str = data[“candle_start_time”] # nanoseconds

            # Route to the correct aggregator based on resolution
            if msg_type == "candlestick_1m":
                candles_1m.add_candle(o, h, l, c, vol, cst_str)
                log(f"1M: {data}", level='info')
            elif msg_type == "candlestick_15m":
                candles_15m.add_candle(o, h, l, c, vol, cst_str)
            elif msg_type == "candlestick_30m":
                candles_30m.add_candle(o, h, l, c, vol, cst_str)
            elif msg_type == "candlestick_1h":
                candles_1h.add_candle(o, h, l, c, vol, cst_str)
            elif msg_type == "candlestick_4h":
                candles_4h.add_candle(o, h, l, c, vol, cst_str)
            else:
                log(f"Unhandled candlestick type: {msg_type}", level='warning')

    elif msg_type == "v2/ticker":
        if "mark_price" in data:
            runningPrice = float(data['mark_price'])

The data I am receiving is not matching with the values of candles or current price.

There can be a few different reasons why the values you see in the WebSocket feed might not line up with the prices or candle data you expect.

find some common causes, along with suggestions to troubleshoot:

If you want the actual traded price, look for last_price or subscribe to the “trades” feed instead of using /in addition to mark_price

Wait for a candle to close, then compare the final data to the official chart on Delta or to the REST/historical API data. In-progress candles will always be a moving target.

Make sure candle_start_time is defined in UTC vs. local, partial intervals

1 Like

Thanks a lot for the help.