Hello All,
I am new to C# and am having trouble replicating an example of some functionality I am trying to alter. Basically, I have a working example of connecting to an external API via a C# forms application and I am having trouble replicating the results in a console
application. I think the problem is that when I create a new instance of the API-based object in my console applications Main function, I can acces the objects properties and methods while Im in the Main function, but functions that I call from my
Main function are unable to access this objects properties. Main is a member of the same class as the functions which are not able to access the properties of the object that I instantiate in Main.
I have...
Namespace IBCSharp.TWSConnectTrade
Public Class TWSConnectTrade
{
.
.
.
static void Main(string[] args)<br/>
{<br/>
TWSConnectTrade TWSConnectTrade = new TWSConnectTrade();<br/>
<br/>
<br/>
IBClient IBClient = new IBClient();<br/>
<br/>
<br/>
IBClient.ConnectToTws(7496, 1);<br/>
<br/>
<br/>
if (!IBClient.Connected)<br/>
{<br/>
<br/>
File.AppendAllText("ordering.txt", " Error: Cannot trade when disconnected from button." + Environment.NewLine);<br/>
//textBoxMessages.WriteLine("Error: Cannot trade when disconnected.");<br/>
return;<br/>
}<br/>
<br/>
ThreadPool.QueueUserWorkItem((object tradeRequestObject) =><br/>
{<br/>
string tradeRequestString = tradeRequestObject as string;<br/>
TWSConnectTrade.SubmitOrdersWithLimitPricesDerviedFromYesterdaysClosesRequestedFromTws(tradeRequestString);<br/>
}, "dell l");<br/>
<br/>
<br/>
IBClient.DisconnectFromTws();<br/>
File.AppendAllText(TomTestFilePath, "Disconnected" + Environment.NewLine);<br/>
<br/>
}
}
The problem seems to be that functions called from SubmitOrdersWithLimitPricesDerviedFromYesterdaysClosesRequestedFromTws() think that IBClient.Connected is false, but within Main IBClient.Connected is True.
Can anyone tell me what my problem might be?
View the full article
I am new to C# and am having trouble replicating an example of some functionality I am trying to alter. Basically, I have a working example of connecting to an external API via a C# forms application and I am having trouble replicating the results in a console
application. I think the problem is that when I create a new instance of the API-based object in my console applications Main function, I can acces the objects properties and methods while Im in the Main function, but functions that I call from my
Main function are unable to access this objects properties. Main is a member of the same class as the functions which are not able to access the properties of the object that I instantiate in Main.
I have...
Namespace IBCSharp.TWSConnectTrade
Public Class TWSConnectTrade
{
.
.
.
static void Main(string[] args)<br/>
{<br/>
TWSConnectTrade TWSConnectTrade = new TWSConnectTrade();<br/>
<br/>
<br/>
IBClient IBClient = new IBClient();<br/>
<br/>
<br/>
IBClient.ConnectToTws(7496, 1);<br/>
<br/>
<br/>
if (!IBClient.Connected)<br/>
{<br/>
<br/>
File.AppendAllText("ordering.txt", " Error: Cannot trade when disconnected from button." + Environment.NewLine);<br/>
//textBoxMessages.WriteLine("Error: Cannot trade when disconnected.");<br/>
return;<br/>
}<br/>
<br/>
ThreadPool.QueueUserWorkItem((object tradeRequestObject) =><br/>
{<br/>
string tradeRequestString = tradeRequestObject as string;<br/>
TWSConnectTrade.SubmitOrdersWithLimitPricesDerviedFromYesterdaysClosesRequestedFromTws(tradeRequestString);<br/>
}, "dell l");<br/>
<br/>
<br/>
IBClient.DisconnectFromTws();<br/>
File.AppendAllText(TomTestFilePath, "Disconnected" + Environment.NewLine);<br/>
<br/>
}
}
The problem seems to be that functions called from SubmitOrdersWithLimitPricesDerviedFromYesterdaysClosesRequestedFromTws() think that IBClient.Connected is false, but within Main IBClient.Connected is True.
Can anyone tell me what my problem might be?
View the full article