API Support Forum
OEC API > Optimization > OEC API DOM events less frequent than OEC Trader software
Author Topic: OEC API DOM events less frequent than OEC Trader software
(4 messages, Page 1 of 1)
Moderators: VPfau
ORad821
Posts: 5
Joined: Aug 20, 2012


Posted: Aug 30, 2012 @ 03:26 AM             Msg. 1 of 4
Hi, when I subscribe to DOM changes in OEC API, I see that the OnDOMChanged event is invoked much less frequently than the DOM updates in OEC Trader. On high volumes the API OnDOMChanged event is called about 3 times less frequently than the DOM in OEC Trader. The following code can somehow demonstrate this on high volumes. Listening at the beeps on each OnDOMChanged event and looking at the OEC Trader DOM you can clearly see that.

So is my observation correct or is there any way I achieve the same frequency as OEC Trader in the API?

Thanks,
ORad821



using System;

namespace OECConsoleApp
{
class Program
{
static void Main(string[] args)
{
var program = new Program();
program.Connect();
Console.WriteLine("Press CTRL+C to exit.");
System.Windows.Forms.Application.Run();
}

private OEC.API.OECClient oecClient;

// Credentials
private string _login = "<user>";
private string _password = "<pass>";

public Program()
{
this.oecClient = new OEC.API.OECClient();

this.oecClient.EventBatchInterval = 0;
this.oecClient.PriceHost = "";
this.oecClient.RemoteHostingEnabled = false;

this.oecClient.OnLoginComplete += new OEC.API.OnLoginCompleteEvent(this.oecClient_OnLoginComplete);
this.oecClient.OnSymbolLookupReceived += new OEC.API.OnSymbolLookupEvent(this.oecClient_OnSymbolLookupReceived);
this.oecClient.OnDOMChanged += new OEC.API.OnDOMChangedEvent(oecClient_OnDOMChanged);
this.oecClient.OnLoginFailed += new OEC.API.OnLoginFailedEvent(this.oecClient_OnLoginFailed);
this.oecClient.OnDisconnected += new OEC.API.OnDisconnectedEvent(this.oecClient_OnDisconnected);

Console.WriteLine("Ready");
}

public void Connect()
{
try
{
oecClient.UUID = "9e61a8bc-0a31-4542-ad85-33ebab0e4e86";
oecClient.Connect("api.openecry.com", 9200, _login, _password, false);
Console.WriteLine("OEC Server found");
}
catch (Exception ex)
{
Console.WriteLine("Connect failed: " + ex.Message);
}
}

private void oecClient_OnLoginComplete()
{
Console.WriteLine("Logged in");
oecClient.SymbolLookup("ESU2");
}

private void oecClient_OnSymbolLookupReceived(OEC.API.SymbolLookupCriteria SymbolLookup, OEC.API.ContractList Contracts)
{
Console.WriteLine(String.Format("Symbol Lookup Received: {0}", SymbolLookup.SearchText));
if (Contracts.Count > 0)
oecClient.SubscribeDOM(Contracts.First);
}

private DateTime _lastUpdate = DateTime.Now;

private void oecClient_OnDOMChanged(OEC.API.Contract contract)
{
var now = DateTime.Now;
TimeSpan delta = now - _lastUpdate;
Console.WriteLine(delta.Milliseconds + " ms");
_lastUpdate = now;

Console.Beep();
}

private void oecClient_OnLoginFailed(OEC.Data.FailReason reason)
{
Console.WriteLine("Login Failed: " + reason.ToString());
}

private void oecClient_OnDisconnected(bool unexpected)
{
Console.WriteLine("Disconnected. Unexpected? " + unexpected.ToString());
}

}
}

Edited by ORad821 on Aug 30, 2012 at 03:27:33
Edited by ORad821 on Aug 30, 2012 at 03:38:11
RuslanK
Posts: 69
Joined: Jun 02, 2010


Posted: Aug 30, 2012 @ 08:29 AM             Msg. 2 of 4
Hello

If your application connects to the same environment (api.openecry.com) as OEC Trader does then frequency should be the same.
Otherwise it might be different.
Also, please take into consideration that DOM window in OEC Trader also subscribes for contract's quote, so user sees updates of DOM and quote.

Ruslan Kartokhin
Software Developer
ORad821
Posts: 5
Joined: Aug 20, 2012


Posted: Sep 03, 2012 @ 02:16 AM             Msg. 3 of 4
Hi,

How can I subscribe to contract's quote? The closest thing I can find is OECClient.SubscribeDealQuote method which gives me an "Invalid subscription" exception. What should I use in the API to subscribe to contract's quote and what event is triggered?

Thanks

Omid Rad
RuslanK
Posts: 69
Joined: Jun 02, 2010


Posted: Sep 03, 2012 @ 09:35 AM             Msg. 4 of 4
It's pretty simple.
You need to use Subscribe method to subscribe
http://www.openecry.com/api/api/OEC.API.OECClient.Subscribe.html

and then handle OnPriceChanged event
http://www.openecry.com/api/api/OEC.API.OECClient.OnPriceChanged.html

Ruslan Kartokhin
Software Developer