Getting new messages from price stream after subscribing

Created at 24 Mar 2017, 22:26
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!
HA

hans177

Joined 24.03.2017

Getting new messages from price stream after subscribing
24 Mar 2017, 22:26


Hello, I'm completely new to FIX API as well as TCP connections.

I was able to write a small program which can connect to my account and subscribe to price quotes (with the help of this forum).

My beginner question is: How do I catch these new quotes (in FIX messages) that should arrive on the stream? Or do I constantly have to send requests for new price quotes? I thought subscribing means I will receive all new quotes via the stream.

So far I only get the prices when I send the initial 'MarketDataRequestMessage'.

How could you, for example, get a "label" that always shows the current bid-price of a symbol?

Thx for your help.


@hans177
Replies

hans177
25 Mar 2017, 10:59

I'm quite expierenced in MQL4/5. There you got functions like OnTick(), which is called in case of a new quote. Unfortunately the tutorial isn't really explaining basic stuff about FIX API very well in my opinion. Can I only get a single response to a message I sent or can I get continuos messages (which I assumed 'subscribing to future quote updates' meant)?


@hans177

hans177
26 Mar 2017, 14:09

I guess I have to set a timer and check for new data, because there is no system event when there is new data available on the TCP stream?


@hans177

taskman9
27 Mar 2017, 02:40

RE:

hans177 said:

I guess I have to set a timer and check for new data, because there is no system event when there is new data available on the TCP stream?

Hi Hnas, can you you take a look at my messages to see if they matches with yours?
shared FIX logs with you at: 

http://fixparser.targetcompid.com?sharedlink=-KgBuGVR7E7YHHHj_KEd
key to unlock:
G#YtmrE3XlnCvSCR3DtpEMNoBTDJUM9cfCrmk6c3(8p:xvyKCI8

 

I'm not getting any quote reply. And CSERVER sending me HEARTBEAT & TESTID.


@taskman9

hans177
27 Mar 2017, 13:57

Hi, looks to me like you are getting quote replies.

How do you get these MarketDataSnapshotFullRefresh-messages? What's the best way to do it? Some endless _priceStream.Read-loop?


@hans177

taskman9
27 Mar 2017, 14:16

RE:

hans177 said:

Hi, looks to me like you are getting quote replies.

How do you get these MarketDataSnapshotFullRefresh-messages? What's the best way to do it? Some endless _priceStream.Read-loop?

Hello Hans, i'm totally clueless about the chain of processes. But you can see i'm running the endless Read loop (in another thread where i posted my code).

You can try that code. If you try   it,please let me know if you get any clue.


@taskman9

hans177
27 Mar 2017, 15:28

Ok, I managed to do it, without really understanding what I'm doing of course ;)

1. Subscribe to quote updates

2.

private AsyncCallback quoteReceived;
...
quoteReceived = new AsyncCallback(OnTick);
...
_priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);

3.

        private void OnTick(IAsyncResult ar)
        {
            int bytesRead = _priceStream.EndRead(ar);

            if (bytesRead > 0)
            {
                Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesRead));
                _priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);
            }
        }

 

 


@hans177

taskman9
27 Mar 2017, 15:32

RE:

hans177 said:

Ok, I managed to do it, without really understanding what I'm doing of course ;)

1. Subscribe to quote updates

2.

private AsyncCallback quoteReceived;
...
quoteReceived = new AsyncCallback(OnTick);
...
_priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);

3.

        private void OnTick(IAsyncResult ar)
        {
            int bytesRead = _priceStream.EndRead(ar);

            if (bytesRead > 0)
            {
                Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesRead));
                _priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);
            }
        }

 

Ohw. great....Fullcode example pls?

 


@taskman9

taskman9
27 Mar 2017, 15:52

RE:

hans177 said:

Ok, I managed to do it, without really understanding what I'm doing of course ;)

1. Subscribe to quote updates

2.

private AsyncCallback quoteReceived;
...
quoteReceived = new AsyncCallback(OnTick);
...
_priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);

3.

        private void OnTick(IAsyncResult ar)
        {
            int bytesRead = _priceStream.EndRead(ar);

            if (bytesRead > 0)
            {
                Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesRead));
                _priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);
            }
        }

 

Ok let me try this

 


@taskman9

MHBB
18 May 2018, 11:38

RE:

hans177 said:

Ok, I managed to do it, without really understanding what I'm doing of course ;)

1. Subscribe to quote updates

2.

private AsyncCallback quoteReceived;
...
quoteReceived = new AsyncCallback(OnTick);
...
_priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);

3.

        private void OnTick(IAsyncResult ar)
        {
            int bytesRead = _priceStream.EndRead(ar);

            if (bytesRead > 0)
            {
                Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytesRead));
                _priceStream.BeginRead(buffer, 0, 1024, quoteReceived, null);
            }
        }

 

 

Could you share your code on how to get market data after subscribing, I'm having troubles getting my head around implementing FIX


@MHBB