How to read the Orders returned in ProtoOAOrderListRes

Created at 20 Feb 2024, 23:38
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!
IG

iggys77

Joined 20.02.2024

How to read the Orders returned in ProtoOAOrderListRes
20 Feb 2024, 23:38


I have successfully created my first app, connected etc. but how do I read the orders I get back in my OnMessageReceived?

There are no examples of how to read the message, just a generic OnMessageReceived(IMessage message).

I managed to read the PayLoadType and I know it's the answer to my request (2176), but then? How do I get the orders from the message?I have tried several ways, serializing into the right object etc. but have not succeeded so far…

 

private void OnMessageReceived(IMessage message)
{
   _logger.Log(LogLevel.Information, "The app got a MESSAGE in OnMessageReceived");
   _logger.Log(LogLevel.Information, "The app got message = " + message);

   switch (message.GetPayloadType().ToString())
   {
       case "2176":


@iggys77
Replies

a.babounia2004
31 May 2024, 07:33 ( Updated at: 03 Jun 2024, 01:01 )

Hello @geometry dash lite,

In order to read the orders returned in the ProtoOAOrderListRes message, you will need to deserialize the message payload into the appropriate object structure. Here's an example of how you can do that:

  1. First, make sure you have the necessary classes or data structures defined to represent the orders returned in the ProtoOAOrderListRes message. These classes should match the structure defined by the message protocol.
    2. In your OnMessageReceived method, after identifying that the payload type is "2176" (as you mentioned in your code snippet), you can proceed with deserializing the message payload into the appropriate object.
    csharp
    Copy
    case "2176":
       ProtoOAOrderListRes orderListResponse = ProtoOAOrderListRes.Parser.ParseFrom(message.GetPayloadBytes());

   // Access the orders from the deserialized object
   List<Order> orders = orderListResponse.OrdersList;
   // Process the orders as needed
   // ...

   break;


@a.babounia2004