ProtoOAGetTickDataReq sporadically returns swapped ASK and BID data

Created at 16 Jan 2023, 18:44
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JA

jakob22

Joined 16.01.2023

ProtoOAGetTickDataReq sporadically returns swapped ASK and BID data
16 Jan 2023, 18:44


Hi,

I'm trying to get into OpenAPI with Python and am currently tying to get some historical tick data. As I need both, ask and bid prices, I first request the ask prices into a Pandas data frame, then request the bid prices and store them into Pandas data frame. Then I join both data frames using an outer join and fill missing values with the previous price. I guess that is the right way of dealing with missing tick prices?

Having the bid and ask prices in a data frame I am able to calculate the spread (ask - bid). However, I noticed that from time to time the spread gets negative, meaning, the bid and ask prices somehow get swapped. I already reviewed my code multiple times and I'm actually sure that I don't mixed up the prices within my code.

Is it possible that the API sporadically returns the wrong values? Unfortunately the response just includes the prices itself and doesn't have an indication whether they are bid or ask prices.

Regards,
Jakob


@jakob22
Replies

jakob22
18 Jan 2023, 18:46

Hi again,

I did some further investigation and found out that the data is not swapped but just not correct. In two different requests the same timestamp contains different data if the from and to timestamp are not exactly the same in two requests.

Here some examples for EURUSD:

Req 1: 2023-01-18 15:46:06.155000+00:00,108235.0,108235.0,0.0
Req 2: 2023-01-18 15:46:06.155000+00:00,108231.0,108233.0,-2.0

Req 1: 2023-01-18 15:46:06.463000+00:00,108236.0,108235.0,1.0
Req 2: 2023-01-18 15:46:06.463000+00:00,108232.0,108233.0,-1.0

Req 1: 2023-01-18 15:46:06.487000+00:00,108239.0,108238.0,1.0
Req 2: 2023-01-18 15:46:06.487000+00:00,108235.0,108236.0,-1.0

Then I tried multiple requests with the same from and to timestamps and there the data is at least consistent but I still have negative spreads.

Is this issue maybe related to a round-off issue because prices are calculated? Or am I handling missing values incorrectly? But I can see negative spreads even for timestamps where I get BID and ASK prices so this doesn't seem to be the main issue.

The main question is: Is there any way to resolve this issue?

Kind regards,
Jakob


@jakob22

PanagiotisChar
19 Jan 2023, 09:01

Hi Jakob,

The fact that the spreads are negative does not mean that the data is wrong. Negative spreads can happen from time to time.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar