API Support Forum
OEC API > API Support > I am facing issues while running a simple datafetching script using dotnet8
Author Topic: I am facing issues while running a simple datafetching script using dotnet8
(2 messages, Page 1 of 1)
Moderators: VPfau
AAgarwal7127
Posts: 1
Joined: Feb 13, 2024


Posted: Feb 16, 2024 @ 08:56 AM             Msg. 1 of 2
GF.Api.IGFClient gfClient = GF.Api.Impl.GFApi.CreateClient();

var runner = new GF.Api.Threading.GFClientRunner(gfClient);
runner.Start();

Console.WriteLine("Connecting...");

gfClient.Connection.Aggregate.LoginCompleted += (client, e) => Console.WriteLine("Connection complete");
gfClient.Connection.Aggregate.LoginFailed += (client, e) => Console.WriteLine($"Connection failed: {e.FailReason}");
gfClient.Connection.Aggregate.Disconnected += (client, e) => Console.WriteLine($"Disconnected: {e.Message}");
gfClient.Logging.ErrorOccurred += (client, e) => Console.WriteLine($"Exception happened: {e.Exception.Message}");

gfClient.Threading.Invoke(() =>
gfClient.Connection.Aggregate.Connect(
new GF.Api.Connection.ConnectionContextBuilder()
.WithUserName("abcdefcg")
.WithPassword("112233122")
.WithUUID("9e61a8bc-0a31-4542-ad85-33ebab0e4e86")
.WithPort(9210)
.WithHost("api.gainfutures.com")
.WithForceLogin(true)
.Build()));

Console.WriteLine("Connecting...");

var timer = new System.Timers.Timer {Interval = TimeSpan.FromSeconds(2).TotalMilliseconds};
timer.Elapsed += (_, __) =>
{
// The timer callback is on a different thread than the GFClientRunner, so we must delegate to the runner thread
gfClient.Threading.Invoke(() =>
{
if (!gfClient.Connection.Aggregate.IsConnected)
return;

var account = gfClient.Accounts.Get().First();
GF.Api.Balances.IBalance totalBalance = account.TotalBalance;

Console.WriteLine($"Account: {account.Spec}");
Console.WriteLine($"\tNetLiq: {totalBalance.NetLiq:c}");
Console.WriteLine($"\tCash: {totalBalance.Cash:c}");
Console.WriteLine($"\tOpen P/L: {totalBalance.OpenPnL:c}");
Console.WriteLine($"\tTotal P/L: {totalBalance.RealizedPnL + totalBalance.OpenPnL:c}");
Console.WriteLine($"\tInitial Margin: {totalBalance.InitialMargin:c}");
Console.WriteLine($"\tNet Options Value: {totalBalance.LongCallOptionsValue + totalBalance.LongPutOptionsValue + totalBalance.ShortCallOptionsValue + totalBalance.ShortPutOptionsValue:c}");
Console.WriteLine($"Average Positions: {account.AvgPositions.Count}");
Console.WriteLine($"Orders: {gfClient.Orders.Get().Count}, last one: {(gfClient.Orders.Get().Count > 0 ? gfClient.Orders.Get().Last().ToString() : string.Empty)}");
Console.WriteLine();
});
};

Console.WriteLine("Press any key to quit");
Console.ReadKey();

timer.Stop();
runner.Stop();




This is the output:
Connecting...
Exception happened: Method not found: 'LanguageExt.Option`1 GF.Net.IProtoClient`2.get_Host()'.


can anyone help me understand the issue?
JHyatt8720
Posts: 4
Joined:


Posted: Feb 27, 2024 @ 07:44 AM             Msg. 2 of 2
We do not support .core. The package is not fully compatible with Net 8, ' Package GFAPI 4.11.519.358 was restored using v4.6.2/7/7.1 instead of the taget net8.0'

Using a ConsoleApp (.Net Framework) instead of .Net Core, fixes this issue and it is compatible with the GFAPI nuGet package 4.6.2

When run with .Net 4.8 the program ran fine.