Sample Open API: Strange code
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
Replies
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
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
@PanagiotisCharalampous
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
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,
- The demo is configured for demo accounts since people use it on demo accounts mostly.
- That is not really necessary.
- Same as point 1.
Best Regards,
Panagiotis
@PanagiotisCharalampous
MZen
17 Jun 2020, 15:28
RE:
PanagiotisCharalampous said:
Hi MZen,
- The demo is configured for demo accounts since people use it on demo accounts mostly.
- That is not really necessary.
- Same as point 1.
Best Regards,
Panagiotis
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,
- 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.
- 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.
- 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
@PanagiotisCharalampous
MZen
17 Jun 2020, 16:24
RE:
PanagiotisCharalampous said:
Hi MZen,
- 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.
- 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.
- 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
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
@PanagiotisCharalampous
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