API Support Forum
OEC API > API Support > Newbie: onLoginComplete not being called after logging on
Author Topic: Newbie: onLoginComplete not being called after logging on
(2 messages, Page 1 of 1)
Moderators: VPfau
CCedrick
Posts: 1
Joined: Mar 16, 2010


Posted: Mar 16, 2010 @ 07:28 PM             Msg. 1 of 2
Hi-

I have a console app written with the API DLL's from the Full Executable example. Here's my issue: I connect to OEC (at least the oecClient.Connect(...) doesn't throw an exception. However, after this nothing happens. I have added the event listeners for the most relevant events such as onLoginComplete, etc.. but they never get called. It just sits there.

The Full API examples, however do work. Is there a workaround? I have included my (somewhat) self-contained example below. Also, the app stays open, in my main class I wait for myself to press 'q' before calling a disconnect() method:

using System;
using System.Collections.Generic;
using System.Text;

using OEC.API;

namespace OECTest
{
public class OECTestClass
{

private OECClient oecClient = new OECClient();

public OECTestClass()
{

this.initializeOEC();

}

private void initializeOEC() {
this.oecClient.EventBatchInterval = 0;
this.oecClient.PriceHost = "";
this.oecClient.RemoteHostingEnabled = false;
this.oecClient.OnLoginComplete += new OnLoginCompleteEvent(oecClient_OnLoginComplete);
this.oecClient.OnLoginFailed += new OnLoginFailedEvent(oecClient_OnLoginFailed);
this.oecClient.OnDisconnected += new OnDisconnectedEvent(oecClient_OnDisconnected);
this.oecClient.OnPriceChanged += new OnPriceChangedEvent(oecClient_OnPriceChanged);

this.logonOEC();

}

private void logonOEC()
{
Console.WriteLine("Attempting To Connect to OEC, User-{0}", "myusername");
try
{
this.oecClient.Connect("api.openecry.com", 9200, "myusername", "mypassword", false);

Console.WriteLine("Connected to OEC. Waiting to perform post connection events");

//this line prints. After that, nothing.

}
catch (Exception ex)
{
Console.WriteLine("An exception happened trying to connect: {0}", ex.ToString());
}

}

private void subscribeToOECContracts()
{
Contract ctr = oecClient.Contracts["ESH0"];
this.oecClient.Subscribe(ctr);
Console.WriteLine("Subscribed to ESH0");

}



void oecClient_OnPriceChanged(Contract Contract, Price Price)
{
Console.WriteLine("Price Changed {0}", Contract.Symbol);
sendPriceUpdate(Contract.Symbol, Price);
}

void oecClient_OnDisconnected(bool Unexpected)
{
Console.WriteLine("Disconnected From OEC.");
}

void oecClient_OnLoginFailed(OEC.Data.FailReason Reason)
{
Console.WriteLine("OEC Logon Failed. Reason: {0}", Reason.ToString());
}

void oecClient_OnLoginComplete()
{
Console.WriteLine("Successfully Connected to OEC");
Console.WriteLine("Subscribing to Market Data");
subscribeToOECContracts();
}

public void disconnectAdapters()
{
oecClient.Disconnect();

Console.WriteLine("Disconnected from OEC: {0}", oecClient.ConnectionClosed);

}

}
}

Cedrick Johnson
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Mar 18, 2010 @ 11:36 AM             Msg. 2 of 2
the thread which creates OECClient should run standard message loop - either by calling Application.Run or by processing messages manually with PeekMessage/TranslateMessage/DispatchMessage.