Sample Open API: Strange code

Created at 10 Jun 2020, 16:18
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!
MZ

MZen

Joined 29.12.2014

Sample Open API: Strange code
10 Jun 2020, 16:18


Hi,

I am trying to get familiar with Open API. I downloaded Sample Open API and discovered strange code inside Main.cs, lines 328-331

        private (double A, double B) TupleMethod()
        {
            return (2.1, 7.6);
        }

It gives a bunch of errors when build. Can anybody give an idea what it is for?

Thanks


@MZen
Replies

PanagiotisCharalampous
10 Jun 2020, 16:26

Hi MZen,

You can remove it and I will update the code soon.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

MZen
10 Jun 2020, 18:58

RE:

PanagiotisCharalampous said:

Hi MZen,

You can remove it and I will update the code soon.

Best Regards,

Panagiotis 

Join us on Telegram

 

Thanks,

 

in the Main design there is also second Get Tick Data button tied to button1 .

 

Could you tell why? And what it does?

Also btnUnSubscribeFrorSpots name looks like typo to my eye, but it works.


@MZen

PanagiotisCharalampous
11 Jun 2020, 08:44

Hi MZen,

I updated the code on GitHub accordingly. You can take the latest version.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

MZen
11 Jun 2020, 15:00

RE:

PanagiotisCharalampous said:

Hi MZen,

I updated the code on GitHub accordingly. You can take the latest version.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you!


@MZen

MZen
16 Jun 2020, 17:13

RE:

PanagiotisCharalampous said:

Hi MZen,

I updated the code on GitHub accordingly. You can take the latest version.

Best Regards,

Panagiotis 

Join us on Telegram

Hello,

sorry  to bother you, yet I think there are some inconsistencies in the sample code.

1. Line 28 _apiHost value should be "live.ctraderapi.com"

2. Line 29 _accountID should be long instead of int

3. Line 179  I think works better if we change it to           if (account.IsLive)

Let me know what you think,

Thank you


@MZen

PanagiotisCharalampous
17 Jun 2020, 08:43

Hi MZen,

  1. The demo is configured for demo accounts since people use it on demo accounts mostly.
  2. That is not really necessary.
  3. Same as point 1.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

MZen
17 Jun 2020, 15:28

RE:

PanagiotisCharalampous said:

Hi MZen,

  1. The demo is configured for demo accounts since people use it on demo accounts mostly.
  2. That is not really necessary.
  3. Same as point 1.

Best Regards,

Panagiotis 

Join us on Telegram

1. Gives very funny execution errors and exceptions not directly linked to proxy address. Wouldn't it be better for code to work on real account as well?

2. Gives a compilation error somewhere.

3. Makes real account build unusable. Not everyone has guts to question usability of the sample code. Most people will assume they are wrong. There could be warning about it, at least.

 

Anyway, it is your code.

Best Regards


@MZen

PanagiotisCharalampous
17 Jun 2020, 15:42

Hi MZen,

  1. What execution errors? There should not be any errors when changing the proxy address. To make the code work for both demo and live accounts will add unnecessary complexity to the code and will defeat the purpose, which is to find out how to exchange messages with the server using the API. I don't see why somebody would need to use the sample application with a live account. 
  2. What compilation error? I just read again your question and I am not sure what do you mean. The variable is long and this is what it should be.
  3. I don't get what you mean. If you are working with demo accounts the condition should be false. If you are working with live accounts then it should be true.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

MZen
17 Jun 2020, 16:24

RE:

PanagiotisCharalampous said:

Hi MZen,

  1. What execution errors? There should not be any errors when changing the proxy address. To make the code work for both demo and live accounts will add unnecessary complexity to the code and will defeat the purpose, which is to find out how to exchange messages with the server using the API. I don't see why somebody would need to use the sample application with a live account. 
  2. What compilation error? I just read again your question and I am not sure what do you mean. The variable is long and this is what it should be.
  3. I don't get what you mean. If you are working with demo accounts the condition should be false. If you are working with live accounts then it should be true.

Best Regards,

Panagiotis 

Join us on Telegram

This is exactly what I am trying to do, learn how to use API. Yet, demo account does not make sense to me, since my goal is to make it work with real money.

You have included in your sample demo account portion (lines 17 to 23) and real account portion (lines 25 to 30). So, I commented demo and un-commented real portion of the code and started to play with sample. Of course I could not go past authorization of application. I started to debug and here I consistently get exception in the Listener.

This was solved by changing proxy name (1)

In real account portion (line 29:         // private int _accountID = 102741;)  _accountID is integer, and it gives compilation error(2)

Finally, change of condition to true made code work with real account. Yet, I did not realize it should be false for demo. That is why I told you about it in (3).

And I told you about it as I think it would be beneficial to other traders, who are like me not familiar enough with C# .

 

Thank you

 


@MZen

PanagiotisCharalampous
17 Jun 2020, 16:28

Hi MZen,

Understood. I will remove obsolete code and add comments wherever necessary to indicate required changes for the app to work on live accounts.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous