How can i close a order buy or sell position in my ctrader account with OpenAPi?

Created at 10 Jul 2023, 21:30
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!
EM

emahohaz

Joined 02.11.2022

How can i close a order buy or sell position in my ctrader account with OpenAPi?
10 Jul 2023, 21:30


How can i close a order buy or sell position in my ctrader account with OpenAPi? I've tried to open and close a buy postion with "close postion" button but i got an error like this:System.FormatException: 'Input string was not in a correct format.' how can i manage to solve this issue ? In the close postion button i specified the volume and the trade id but still got this error


@emahohaz
Replies

PanagiotisChar
11 Jul 2023, 08:50

Hi there,

I would advice that you share some screenshots of what you are using and where do you get such an error from since you do not seem to use Open API.

Aieden Technologies

Need help? Join us on Telegram

 


@PanagiotisChar

emahohaz
24 Jul 2023, 08:55

RE: How can i close a order buy or sell position in my ctrader account with OpenAPi?

PanagiotisChar said: 

Hi there,

I would advice that you share some screenshots of what you are using and where do you get such an error from since you do not seem to use Open API.

Aieden Technologies

Need help? Join us on Telegram

i fixed the problem , now i'm able to close postion correctly

 


@emahohaz

emahohaz
24 Jul 2023, 09:00

RE: How can i close a order buy or sell position in my ctrader account with OpenAPi?

PanagiotisChar said: 

Hi there,

I would advice that you share some screenshots of what you are using and where do you get such an error from since you do not seem to use Open API.

Aieden Technologies

Need help? Join us on Telegram

but now i'm wondering if there is any method that can allow me to get the positionID of the current open position/trade

 


@emahohaz

PanagiotisChar
25 Jul 2023, 06:25

Hi there,

Check ProtoOAReconcileReq. It returns all open positions and pending orders.

Aieden Technologies

Need help? Join us on Telegram


 


@PanagiotisChar

emahohaz
25 Jul 2023, 14:50

RE: How can i close a order buy or sell position in my ctrader account with OpenAPi?

PanagiotisChar said: 

Hi there,

Check ProtoOAReconcileReq. It returns all open positions and pending orders.

Aieden Technologies

Need help? Join us on Telegram

and i have th efollowing question

To receive live bid/ask quotes for a symbol, perform the following actions.

      what type of method i need to call in order to receive the ProtoOASubscribeSpotsRes typeresponse ? maybe btnSubscribeForSpots_Click function ?
 

 


@emahohaz

emahohaz
25 Jul 2023, 14:51

RE: RE: How can i close a order buy or sell position in my ctrader account with OpenAPi?

emahohaz said: 

PanagiotisChar said: 

Hi there,

Check ProtoOAReconcileReq. It returns all open positions and pending orders.

Aieden Technologies

Need help? Join us on Telegram

and i have th efollowing question

To receive live bid/ask quotes for a symbol, perform the following actions.

      what type of method i need to call in order to receive the ProtoOASubscribeSpotsRes typeresponse ? maybe btnSubscribeForSpots_Click function ?
 

thank you 

 


@emahohaz

emahohaz
25 Jul 2023, 18:47 ( Updated at: 26 Jul 2023, 10:45 )

RE: RE: RE: How can i close a order buy or sell position in my ctrader account with OpenAPi?

emahohaz said: 

emahohaz said: 

PanagiotisChar said: 

Hi there,

Check ProtoOAReconcileReq. It returns all open positions and pending orders.

Aieden Technologies

Need help? Join us on Telegram

and i have th efollowing question

To receive live bid/ask quotes for a symbol, perform the following actions.

      what type of method i need to call in order to receive the ProtoOASubscribeSpotsRes typeresponse ? maybe btnSubscribeForSpots_Click function ?
 

 

 

 


@emahohaz

PanagiotisChar
26 Jul 2023, 12:56

Hi there,

I am not sure what method you are looking for. You just need to send the relevant message. See the relevant examples on GitHub e.g. for C#

            var spotRequest = new ProtoOASubscribeSpotsReq
           {
               CtidTraderAccountId = _accountID,
           };

           spotRequest.SymbolId.Add(10003);

           var message = new ProtoMessage
           {
               Payload = spotRequest.ToByteString(),
               PayloadType = (int)ProtoOAPayloadType.ProtoOaSubscribeSpotsReq,
           };

           Transmit(message);

Aieden Technologies

Need help? Join us on Telegram


@PanagiotisChar

emahohaz
26 Jul 2023, 13:04

RE: How can i close a order buy or sell position in my ctrader account with OpenAPi?

PanagiotisChar said: 

Hi there,

I am not sure what method you are looking for. You just need to send the relevant message. See the relevant examples on GitHub e.g. for C#

            var spotRequest = new ProtoOASubscribeSpotsReq
           {
               CtidTraderAccountId = _accountID,
           };

           spotRequest.SymbolId.Add(10003);

           var message = new ProtoMessage
           {
               Payload = spotRequest.ToByteString(),
               PayloadType = (int)ProtoOAPayloadType.ProtoOaSubscribeSpotsReq,
           };

           Transmit(message);

Aieden Technologies

Need help? Join us on Telegram

I already know the example, but need a method in order to update a ProtoSpotevent variable so I can call its object and get the ask or bid price like this:

ProtoSpotevent objc =new ProtoSpotevent();

objc.ASK;

objc.BID;

 

 


@emahohaz

PanagiotisChar
26 Jul 2023, 13:10

Hi there,

You can check the examples and see how these messages are read from the stream e.g. 

            _client.ObserveOn(SynchronizationContext.Current).OfType<ProtoOASpotEvent>().Subscribe(OnSpotMessage);

Aieden Technologies

Need help? Join us on Telegram


@PanagiotisChar