API Support Forum
OEC API > API Support > Connection error/Socket error
Author Topic: Connection error/Socket error
(3 messages, Page 1 of 1)
Moderators: VPfau
PLakshmanan
Posts: 2
Joined: Jan 13, 2021


Posted: Feb 03, 2021 @ 01:49 AM             Msg. 1 of 3
Hello,

I got "Connection error/Socket error" while making connection to GF server.

I am using.
.Net core 2.1
.Net framework 4.7.2
Nuget package 4.0.3.44

-----------------My code --------
GF.Api.IGFClient gfClient = GF.Api.Impl.GFApi.CreateClient();

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

gfClient.Connection.Price.LoginCompleted += GFClient_OnLoginComplete;
gfClient.Connection.Price.LoginFailed += GFClient_OnLoginFailed;
gfClient.Connection.Price.Disconnected += GFClient_OnDisconnected;
gfClient.Logging.ErrorOccurred += (client, e) => Console.WriteLine($"{e.Exception.Message}");

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

gfClient.Threading.Invoke(() =>
{
if (!gfClient.Connection.Price.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();
});
--------------------------------------------------------------------

Please help me out on this.
Waiting for reply.
JSmith5611
Posts: 187
Joined:


Posted: Feb 04, 2021 @ 02:19 PM             Msg. 2 of 3
a price connection requires an order connection.

so the simplest fix would be to replace
gfClient.Connection.Price.Connect()
with
gfClient.Connection.Aggregate.Connect()
Jason Smith
PLakshmanan
Posts: 2
Joined: Jan 13, 2021


Posted: Feb 09, 2021 @ 11:35 PM             Msg. 3 of 3
Hi,

Thanks for your reply.

I used both Price and Aggregate to connect but unfortunately both gives same error.