usingSystem;usingSystem.Linq;usingGF.Api;usingGF.Api.Connection;usingGF.Api.Margin.Calculation;namespaceTestMarginRequest{internalclassProgram{privateconststringSymbol="NKDZ22";privateconststringAccount="replace_with_correct_value";privateconststringUserName="replace_with_correct_value";privateconststringPassword="replace_with_correct_value";publicstaticvoidMain(string[]args){varclient=GF.Api.Impl.GFApi.CreateClient();varrunner=newGF.Api.Threading.GFClientRunner(client);runner.Start();client.Connection.Aggregate.LoginCompleted+=(gfClient,eventArgs)=>{Console.WriteLine("Login Completed");gfClient.Contracts.Lookup.BySymbol(Symbol);};client.Contracts.Lookup.SymbolLookupReceived+=(gfClient,eventArgs)=>{varaccountID=gfClient.Accounts.Get(Account).ID;varcontractID=eventArgs.Contracts.First().ID;varposition=newHypoPosition(contractID,1,1);varorder=newHypoOrder(contractID,GF.Api.Values.Orders.OrderSide.Buy,1);varrequest=newMarginCalculationRequest(accountID,new[]{position},new[]{order});stringvalidation=client.Margin.ValidateMarginCalculationRequest(request);if(string.IsNullOrEmpty(validation))client.Margin.RequestMarginCalculation(request);elseConsole.WriteLine($"Margin request is not valid: {validation}");};client.Margin.MarginCalculationCompleted+=(gfClient,eventArgs)=>{Console.WriteLine("Margin request completed");Console.WriteLine($"Initial: {eventArgs.Result.InitialMarginRequirements}");Console.WriteLine($"Maintenance: {eventArgs.Result.MaintenanceMarginRequirements}");};client.Traders.TraderError+=(gfClient,eventArgs)=>{Console.WriteLine($"TraderApi error occurred: {eventArgs.Message}");};Console.WriteLine("Connecting...");client.Connection.Aggregate.Connect(newGF.Api.Connection.ConnectionContextBuilder().WithUserName(UserName).WithPassword(Password).WithPort(9210).WithHost("api.gainfutures.com").WithUUID("9e61a8bc-0a31-4542-ad85-33ebab0e4e86").WithForceLogin(true).Build());Console.WriteLine("Press any key to exit");Console.ReadKey();runner.Stop();}}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.