API Support Forum
OEC API > API Support > GF API: Greeks Subscription
Author Topic: GF API: Greeks Subscription
(2 messages, Page 1 of 1)
Moderators: VPfau
CM4645
Posts: 33
Joined: Oct 25, 2022


Posted: Jan 13, 2023 @ 11:13 AM             Msg. 1 of 2
I am unable to receive Greeks information. Is there anything missing in below code to subscribe and receive greeks? Note, I am able to successfully receive price information.

internal class Program
{
private static SymbolLookupResponseHandler _symbolLookupResponseHandler;
private static PnlSubscriptionManager _pnlSubscriptionManager;
private static SymbolLookupRequestID _esRequestID;
private static SymbolLookupRequestID _esRequestID2;

private static void Main(string[] args)
{
var client = GFApi.CreateClient();
var runner = new GFClientRunner(client);
runner.Start();

_symbolLookupResponseHandler = new SymbolLookupResponseHandler(client);

client.Connection.Aggregate.LoginCompleted += GFClient_OnLoginCompleted;
client.Subscriptions.Price.PriceTick += GFClient_OnPriceTick;
client.Subscriptions.Greeks.GreeksChanged += GFClient_OnGreeksChanged;
client.Contracts.Lookup.SymbolLookupReceived += GFClient_OnSymbolLookupReceived;
client.Connection.Aggregate.LoginFailed += GFClient_OnLoginFailed;

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

client.Connection.Aggregate.Connect(
new ConnectionContextBuilder()
.WithUserName()
.WithPassword()
.WithPort(9210)
.WithHost("api.gainfutures.com")
.WithUUID()
.WithForceLogin(true)
.Build());


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

runner.Stop();
}

private static void GFClient_OnGreeksChanged(IGFClient client, GreeksChangedEventArgs e)
{
Console.WriteLine(e.Contract);
}

private static void GFClient_OnLoginFailed(IGFClient client, LoginFailedEventArgs e)
{
Console.WriteLine($"OnLoginFailed: {e.FailReason}");
}

private static void GFClient_OnPriceTick(IGFClient client, PriceChangedEventArgs e)
{
if (e.Contract.BaseContract.IsOption)
{
Console.WriteLine($"{e.Contract.Symbol}\t{e.Price.AskPrice}");
}

}

private static void GFClient_OnLoginCompleted(IGFClient client, LoginCompleteEventArgs e)
{
_esRequestID = client.Contracts.Lookup.BySymbol("OEW2F23 C3995");

}

private static void GFClient_OnSymbolLookupReceived(IGFClient client, SymbolLookupEventArgs e)
{

Console.WriteLine($"Symbol lookup for electronic contracts that starts with ES in symbol or description returned {e.Contracts.Count} contracts");
foreach (var contract in e.Contracts)
{
DisplayContract(contract);
client.Subscriptions.Price.Subscribe(contract.ID);
client.Subscriptions.Greeks.Subscribe(contract.ID);
}

}

private static void DisplayContract(IContract contract)
{
Console.WriteLine($"Contract: {contract.Symbol} - {contract.BaseSymbol}");
Console.WriteLine($"\tExpiration Date: {contract.ExpirationDate}");
Console.WriteLine($"\tTick Size: {contract.TickSize}");
Console.WriteLine($"\tContract Size: {contract.ContractSize:c}");
Console.WriteLine($"\tHas Options: {contract.HasOptions}");
Console.WriteLine($"\tTotal Num Option Contracts: {contract.Options.Count}");
}

private static void DisplayAccount(GF.Api.Accounts.IAccount account)
{
Console.WriteLine($"Account: {account.Spec}");
GF.Api.Balances.IBalance totalBalance = account.TotalBalance;
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}");
var netOptionsValue =
totalBalance.LongCallOptionsValue
+ totalBalance.LongPutOptionsValue
+ totalBalance.ShortCallOptionsValue
+ totalBalance.ShortPutOptionsValue;
Console.WriteLine($"\tNet Options Value: {netOptionsValue:c}");
Console.WriteLine($"Average Positions: {account.AvgPositions.Count}");
}

}
SRuscak
Posts: 50
Joined: Aug 24, 2017


Posted: Jan 13, 2023 @ 03:38 PM             Msg. 2 of 2
Hello,

Probably you need to enable Greeks. They are disabled by default due to potential performance impact.

client.Options.IsGreekCalculationEnabled = true;