API Support Forum
User Profile

Viewing User Profile for: AAmi1662


About

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 5677 total posts (0.07%) in 1162 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(() =>
gfClient.Connection.Aggregate.Connect(
new GF.Api.Connection.ConnectionContextBuilder()
.WithUserName("username")
.WithPassword("pass")
.WithUUID("9e61a8bc-0a31-4542-ad85-33ebab0e4e86")
.WithPort(9200)
.WithHost("api.gainfutures.com")
.WithForceLogin(true)
.Build()));

/code]


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=4.0.3.13, 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 4.0.3.44' 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);
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($"{e.Exception.Message}");

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

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();
}
}






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