API Support Forum
OEC API > API Support > OECClient.Contracts is empty?
Author Topic: OECClient.Contracts is empty?
(4 messages, Page 1 of 1)
Moderators: VPfau
MMartinovic306
Posts: 2
Joined: Oct 11, 2012


Posted: Oct 23, 2012 @ 04:31 AM             Msg. 1 of 4
I am trying to connect to api servers, the connection seems to be established fine, but when I try to pick a contract, it fails, because OECClient.Contracts contains no items (it's not null, just zero-length list.)

I am using following code:


oclient = OEC.API.OECClient.CreateInstance(false);
oclient.OnLoginComplete += new OEC.API.OnLoginCompleteEvent(oclient_OnLoginComplete);
oclient.OnLoginFailed += new OEC.API.OnLoginFailedEvent(oclient_OnLoginFailed);
oclient.OnError += new OEC.API.OnErrorEvent(oclient_OnError);
oclient.UUID = uuid;
oclient.Connect(host, port, username, password, true);


and then in oclient_OnLoginComplete i try to retrieve the contract:

OEC.API.Contract esuContract = oclient.Contracts["ESZ2"];
oclient.Subscribe(esuContract);
oclient.OnPriceTick += new OEC.API.OnPriceChangedEvent(oclient_OnPriceTick);


which fails on the first line as oclient.Contracts.Count is zero.
What am I doing wrong?

(I've been snooping around other oclient variables, and for example oclient.BaseContracts populates just fine, but all the items in it seem to have their Contracts list/property zero-length as well. All the other properties (Accounts, Channels, Currencies, everything) seem to be initialized fine, it seems to me just as if server was consistently trying to convince me there are no contracts available to subscribe to...)

Miroslav Martinovic
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Oct 24, 2012 @ 02:35 PM             Msg. 2 of 4
You need to load a contract first. Please check SymbolLookup method.

Victor Vins
Lead Software Developer
MMartinovic306
Posts: 2
Joined: Oct 11, 2012


Posted: Oct 24, 2012 @ 03:14 PM             Msg. 3 of 4
Thank you, that solved it.

As a sidenote, having a sample app more informative than the documentation iteslf is generally not an ideal state of things, that's just for your consideration.

Nevertheless, thank you very much.

Miroslav Martinovic
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Oct 25, 2012 @ 01:38 PM             Msg. 4 of 4
We've updated our API Documentation. Hopefully new version can clarify some issues http://www.openecry.com/cfbb/index.cfm?page=topic&topicID=766

Victor Vins
Lead Software Developer