EventHandler - ProtoOAGetPositionUnrealizedPnLRes

Created at 03 May 2024, 11:39
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!
CT

ctid5752082

Joined 09.02.2023

EventHandler - ProtoOAGetPositionUnrealizedPnLRes
03 May 2024, 11:39


Good morning,

 

I have a question regarding ‘OpenAPI’ framework.

 

Note -

a) I am using the ‘gitHub’ repository samples - https://github.com/spotware/OpenAPI.Net

b) I have updated the ‘ProtoBuf’ libraries - https://github.com/spotware/openapi-proto-messages

 

I am trying to add ‘ProtoOAGetPositionUnrealizedPnLRes’ message to the code.

 

this.xDisposablesX.Add(this.xClientX.OfType<ProtoMessage>().Subscribe(OnMessage, OnError));

this.xDisposablesX.Add(this.xClientX.OfType<ProtoOAGetPositionUnrealizedPnLRes>().Subscribe(OnPositionPnL));

 

When the message response is received, it gets processed by the ‘OnMessage’ method, not the ‘OnPositionPnL’ method.

However. the ‘PayloadType’ value is ‘2188’ - which indicates ‘ProtoOAGetPositionUnrealizedPnLRes’ message type.

 

Is there something I am missing?

 

Thank you for your time,

 


@ctid5752082
Replies

PanagiotisCharalampous
03 May 2024, 15:00

Hi there,

The sample is not up to date with the latest protobuf files. Therefore you would need to develop this handling yourself.

Best regards,

Panagiotis


@PanagiotisCharalampous

ctid5752082
03 May 2024, 15:21 ( Updated at: 03 May 2024, 16:22 )

RE: EventHandler - ProtoOAGetPositionUnrealizedPnLRes

PanagiotisCharalampous said: 

Hi there,

The sample is not up to date with the latest protobuf files. Therefore you would need to develop this handling yourself.

Best regards,

Panagiotis

Good morning,

 

Thank you for the reply.

 

I realized that the sample wasn't up to date, so I updated the ‘ProtoBuf’ libraries.

I substituted the generated ‘c#’ files and rebuilt the ‘OpenAPI’ libraries.

That was noted in the question.

 

Also, I am not running samples code.

 

I used the code to generate ‘OpenAPI’ libraries for my own code.

 

However -

a) ‘this.xDisposablesX.Add(this.xClientX.OfType<ProtoOAGetPositionUnrealizedPnLRes>().Subscribe(OnPositionPnL));’

  • The code is aware of the existence of the ‘ProtoOAGetPositionUnrealizedPnLRes’ class library.  (Hence, the ‘ProtoBuf’ updates).
  • It wouldn't have compiled.
  • The program runs.
  • It receives messages.
  • Shouldn't the line of code set an event handler (or whatever), based on ‘ProtoOAGetPositionUnrealizedPnLRes’ message type, calling the ‘OnPositionPnL’ method?
  • The method signature string is ‘private void OnPositionPnL(ProtoOAGetPositionUnrealizedPnLRes message)’
  • Again, the code wouldn't compile if the ‘ProtoOAGetPositionUnrealizedPnLRes’ message type didn't exist.


Also, the code generates a 'ProtoOAGetPositionUnrealizedPnLReq' message request successfully.

Hence, the ‘ProtoOAGetPositionUnrealizedPnLRes’ message response.

Why wouldn't it process ‘ProtoOAGetPositionUnrealizedPnLRes’ messages correctly.

Why would the code compile, run and receive messages, based on 'ProtoOAGetPositionUnrealizedPnLReq', but it can't process 'ProtoOAGetPositionUnrealizedPnLRes' messages?

 

Also, if I ‘run stop’ the code, and use ‘intermediate’ window -

? ProtoOAGetPositionUnrealizedPnLRes.Parser.ParseFrom(message.Payload)


{ "ctidTraderAccountId": "xxxxxxxx", "positionUnrealizedPnL": [ { … } ], "moneyDigits": 2 }
   CtidTraderAccountId: xxxxxxxx
   HasCtidTraderAccountId: true
   HasMoneyDigits: true
   HasPayloadType: false
   MoneyDigits: 2
   PayloadType: ProtoOaGetPositionUnrealizedPnlRes
   PositionUnrealizedPnL: {[ { … } ]}
   _hasBits0: 6
   _unknownFields: null
   ctidTraderAccountId_: xxxxxxxx
   moneyDigits_: 2
   payloadType_: 0
   Google.Protobuf.IMessage.Descriptor: {Google.Protobuf.Reflection.MessageDescriptor}
   positionUnrealizedPnL_: {[ { … } ]}
 

 

Note the field -

‘PayloadType: ProtoOaGetPositionUnrealizedPnlRes’

 

Is this correct?  The spelling is wrong.

‘ProtoOaGetPositionUnrealizedPnlRes’

  • (The ‘OA’ is spelled ‘Oa’)
  • (The ‘PnL’ is spelled ‘Pnl’)

Shouldn't it be ‘ProtoOAGetPositionUnrealizedPnLRes’?

  • Which is how it is spelled in the ‘type libraries
  • Note - ‘OA’ (not ’Oa')
  • Note ‘ PnL’ (not ‘Pnl’)

 

Is that why the message handling is failing to detect the message, despite the ‘protoBuf’ libraries being ‘up to date’, and the code compiling (proving that the relevant references to libraries, etc) is correct?

 

Also, note the ability to use the function ‘ProtoOAGetPositionUnrealizedPnLRes.Parser.ParseFrom(message.Payload)’

If the code isn't up to date, then why can I access ‘ProtoOAGetPositionUnrealizedPnLRes.Parser.ParseFrom()’

 

 

Thank you for your time,

 

 

 

 


@ctid5752082

PanagiotisCharalampous
04 May 2024, 06:50

Hi there,

Protobuf class generation generates the ProtoOAGetPositionUnrealizedPnLRes class but it does not generate the code to handle the message. Therefore your code builds but it does not handle the specific message. For example, did you update the MessageFactory.GetMessage() method?

Best regards,

Panagiotis


@PanagiotisCharalampous