IGFClient Interface

GF API Documentation
Central GF API class. Provides access to all GF functionality and maintains data and server connection state.

Namespace:  GF.Api
Assembly:  GF.Api (in GF.Api.dll) Version: dd7171be68430789135ec75c4e9f4bbfeca31201
Syntax

public interface IGFClient

The IGFClient type exposes the following members.

Properties

  NameDescription
Public propertyAccounts
Accounts functionality
Public propertyAllocation
Allocation functionality
Public propertyClearingHouses
Clearing Houses functionality
Public propertyConnection
Connection functionality
Public propertyContracts
Contract functionality
Public propertyCurrencies
Currency functionality
Public propertyExchanges
Exchanges functionality
Public propertyLogging
Logging functionality
Public propertyMargin
Margin functionality
Public propertyMessaging
Messaging functionality
Public propertyOptions
Options
Public propertyOrders
Orders functionality
Public propertyPostAllocation
PostAllocation functionality
Public propertyProperties
Properties associated with logged-in user
Public propertyStrategies
Strategy functionality
Public propertyStrings
String operations
Public propertySubscriptions
Subscription functionality
Public propertyThreading
Threading functionality
Public propertyTraders
Traders functionality
Public propertyUsers
Users functionality
Top
Remarks

Principles of work
The IGFClient component serves as a gateway to the GF servers, sending client requests and receiving server responses over the internet. Client session data are represented in as an object tree available through IGFClient instance properties. IGFClient.Orders.Get() returns a collection of orders, for example. See "Data model" section below for details

Client requests are sent by calling component methods, such as CancelOrder(OrderID, SubmissionType, Location, Tag50), and any changes or additions to session data are visible to the client as events (like ChatMessageReceived)

Network transmission is asynchronous (performed in background), so these method calls do not return immediate results. In most cases the client should wait for the appropriate event to check the result.
Data Model
The primary object of the GF API data model is the IOrder. This object contains all information about order lifetime, such as IVersion, ICommand and IOrderState history, and order IFills (remaining or cancelled). GF API loads all orders for the current trading session on login.
Accounting information can be accessed by IAccount objects. There are open/closed IPosition statistics and account cash IBalance (or several balances for different currencies, if any).
Trading environment objects, such as contracts, currencies, exchanges provide access to fundamental data. Some additional object types, like IBaseContracts and ContractGroups were introduced to maintain structured access.
Dynamic data like currency conversion rate, contract last price and depth of market updates are stored in corresponding objects - e.g. ICurrency and IContract. Theoretical profit/loss for open positions is updated in real-time, if the price feed is available for the given contract.
All objects can be found in their respective collections by ID, or retrieved from another object's properties - for example, an order contains references to its account and contract.
Note that any date/time values provided by the API are in UTC time zone, except the opening/closing times for contracts, which are local to contract exchange.
Getting started
To use the API, the client should first connect to the GF servers:
GF.Api.IGFClient gfClient = GF.Api.Impl.GFApi.CreateClient();
Register events:
client.Connection.Aggregate.LoginCompleted += GFClient_OnLoginCompleted;
client.Connection.Aggregate.LoginFailed += GFClient_OnLoginFailed;
client.Connection.Aggregate.Disconnected += GFClient_OnDisconnected;
Then you need start a runner for the client:
var runner = new GFClientRunner(gfClient);
runner.Start();
And finally call Connect method:
client.Connection.Aggregate.Connect(
    new ConnectionContextBuilder()
        .WithUserName(username)
        .WithPassword(password)
        .WithPort(9210)
        .WithHost("api.gainfutures.com")
        .WithUUID("9e61a8bc-0a31-4542-ad85-33ebab0e4e86")
        .WithForceLogin(true)
        .Build());

After that, client application should need to wait for one of events: LoginCompleted or LoginFailed If the connection is dropped for some reason, the Disconnected event will fire. The API can't process requests while disconnected.
On successful login, all collections will already be populated with session data (order states and fills, account positions, etc.). The system is ready to process client requests: from subscriptions to price feeds and order requests.
Examples

This code creates and sends the order "Buy 1 ESZ18 MKT"
var orderDraft = new OrderDraftBuilder()
    .WithAccountID(client.Accounts.Get().First().ID)
    .WithContractID(gfClient.Contracts.Get("ESZ18").ID)
    .WithSide(OrderSide.Buy)
    .WithOrderType(OrderType.Market)
    .WithQuantity(1)
    .Build();
Validate the order and print errors if any:
IReadOnlyList<OrderDraftValidationError> validationErrors = client.Orders.Drafts.Validate(orderDraft);
if (validationErrors.Any())
{
    foreach (var error in validationErrors)
        Console.WriteLine($"\t{error.Message}");
}
and, if everything is good, send the order
else
{
    IOrder order = client.Orders.SendOrder(orderDraft);
    Console.WriteLine($"Order {order} was sent");
}

Now the client can expect events OrderConfirmed, OrderStateChanged with OrderState = Working, then OrderFilled and finally OrderStateChanged with OrderState = Completed.

This code subscribes for a price feed:
IPriceSubscription _subscription;

void SomeMethod()
{
   ...
   gfClient.Subscriptions.Price.PriceChanged += GFClient_OnPriceChanged;
   ...
   _subscription = gfClient.Subscriptions.Price.Subscribe(gfClient.Contracts.Get("ZSPZ18").ID);
   ...
}

void GFClient_OnPriceChanged(IGFClient client, PriceChangedEventArgs e)
{
   string price = e.Contract.FormatPrice(e.Price.LastPrice);
   ...
}
The client will periodically receive PriceChanged events whenever the contract's market price data is updated, until unsubscribed:
_subscription.Unsubscribe();
See Also

Reference