API Support Forum
User Profile

Viewing User Profile for: AAmi1662


Sep 15, 2021 08:21 AM

Sep 17, 2021 02:37 PM

Sep 18, 2021 03:20 AM

Post Statistics
AAmi1662 has contributed to 4 posts out of 5221 total posts (0.08%) in 31 days (0.00 posts per day).

20 most recent posts:

API Support » Connection problem Sep 17, 2021 @ 02:37 PM (Total replies: 1)

Hi, trying to connect to the servers with the code from the documentaion :https://gainfutures.com/GFAPI/
gfClient.Threading.Invoke(() =>
new GF.Api.Connection.ConnectionContextBuilder()


except from the username and password there's anything else that need to be changed? i tried different ports as well but keep getting connection failed.

Thank you!

API Support » Try to run a sample program from the documentaion get System.TypeLoadException error Sep 17, 2021 @ 02:34 PM (Total replies: 3)

** FIxed by reinstalling everything

API Support » Try to run a sample program from the documentaion get System.TypeLoadException error Sep 17, 2021 @ 05:30 AM (Total replies: 3)

Hi, updated the post with the code.

API Support » Try to run a sample program from the documentaion get System.TypeLoadException error Sep 15, 2021 @ 03:55 PM (Total replies: 3)

Hi, first time using C# and gain api. I'm trying to create a connection to the servers and i get the error:

System.TypeLoadException: 'Method 'TryGetConstructor' in type 'GF.SimpleInjector.InternalConstructorResolutionBehavior' from assembly 'GF.SimpleInjector, Version=, Culture=neutral, PublicKeyToken=b6b45f2252711217' does not have an implementation.'

not sure if it helpful but i got alert as well with yellow triangle saying:

Package 'GFAPI' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.

The code:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
internal class Program
private static void Main(string[] args)
GF.Api.IGFClient gfClient = GF.Api.Impl.GFApi.CreateClient();

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


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($"{e.Exception.Message}");

gfClient.Threading.Invoke(() =>
new GF.Api.Connection.ConnectionContextBuilder()

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)

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("Press any key to quit");


How do i solve it?
Thank you
Edited by AAmi1662 on Sep 17, 2021 05:29 AM