Getting up to date OHLC candle values (Futures API)

I am unable to see the latest OHLC candles. In my code, each second the following is called:
https://testnet.binancefuture.com/fapi/v1/markPriceKlines?symbol=BTCUSDT&interval=1m&limit=300

I then process the jason string into a structured array.
_resultData(x).time
_resultData(x).open
_resultData(x).high
_resultData(x).low
_resultData(x).close
When I compare the values to the candles onthe chart, I am using

the latest OHLC received does not match the last candle data on chart. The close does not even update correctly,

I also make a separate call once/minute to update the 300 candles (shifth then over and append the new OHLC), That is also not exact. There is about a 20-37 second delay.

Has anyone run into this situation?

I also tested my code using klines, just change an input from “markPriceKlines” to “kilines” then used the same exact loops and code. In that case all was fine. The lastest close updates per second and the OHLC values of all previous candles are updated as well without any issues.

Similar thing happens when I then just get the “markPrice” value. It updates each second with no issues.

Its just when I try to use “markPriceKlines” that the latest candle does not update properly and then there is a delay for updating the other 300 candles OHLCs.

Any info would be appreciated.

Jess

Looks normal to me. Do you have “Mark Price” selected?
Also, just in case notice that data from the API key is returned in ascending order. Oldest first, newest last.

Hi aisling, thnx for answering.
Yup I have Mark Price selected on the chart, and Yup, I gather the OHLC values into a structured array and then flip the array. So at item 0 I am seeing the latest candle.

Doesn’t make sense why this delay would be there, how can we test functionality if there is a delay?

My client gave me his API keys so I am going to see if this is also happening under the live condition. If it is then, this is an issue that Binance needs to look into.

Just for kicks. I’ll post a video where I show exactly what is happening etc etc… stay tuned…
Jess

There is no problem, certain latency with REST API is expected due to its protocol.
A better practice to stay updated with the kline is through the use of websocket:
https://binance-docs.github.io/apidocs/futures/en/#kline-candlestick-streams
→ where “Last trade ID” is refers to last price.

Hi, well my client’s approach is based on the Mark Price candles not the kline candles which as far as I can see correspond to Last price candles.

Here, take a look at my video. Hope it makes sense, I crunched in alot of information, so there will be errors in me explanation, LOL.

(Note: I mention Keys, ignore that, I didn’t neet them to get OHLC data, :slight_smile: )

Thnx for the help. Take care
Jess

LOL, I couldn’t help it, so, I continue to debug this situation and I still see the issue.

So I went to the part of the code where I collect only 2 bars of OHLC data. So I end up with a structured array with 2 sets of OHLC data. I coontinue to step thru the debug and on each iteration the array is updated with new OHCL data… NO CHANGE. The close of Candle 0 does not change at all, There is a sudden change but that happens at about 15-30 seconds after the open of the minute. Then the value doesn’t change.

Now if I change over to “klines” or Last Price… Then I see the close constantly changing, as it should be.

If needed I can provide a simplified version of the code, for anyone to try it out.

I guess a better question would be if there is anyone who has been able to get up to date OHLC data when using Mark Price data??

Thnx
Jess

Wait a second!!!
According to this URL:

“Mark Price is not used in the actual trading and can be regarded as an indicator that monitors a position’s risk, while the Last Price is the essential market price that every user trades on.”

And in addition:
“Mark price = Median*(Price 1, Price 2, Contract Price)
Price 1 = Price Index*(1 + Last Funding Rate*(Time Until Funding / 8))
Price 2 = Price Index + Moving Average (5-minute Basis) *”

WOW no wonder!!! its based on a 5minute basis (well the MA is) and its not what is used for trading!!!

Ok so next question… will moving to SPOT trading help us get OHLC that points to a mark Price like candle series???