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
The IGFClient type exposes the following members.
Properties
Name | Description | |
---|---|---|
![]() | Accounts |
Accounts functionality
|
![]() | Allocation |
Allocation functionality
|
![]() | ClearingHouses |
Clearing Houses functionality
|
![]() | Connection |
Connection functionality
|
![]() | Contracts |
Contract functionality
|
![]() | Currencies |
Currency functionality
|
![]() | Exchanges |
Exchanges functionality
|
![]() | Logging |
Logging functionality
|
![]() | Margin |
Margin functionality
|
![]() | Messaging |
Messaging functionality
|
![]() | Options |
Options
|
![]() | Orders |
Orders functionality
|
![]() | PostAllocation |
PostAllocation functionality
|
![]() | Properties |
Properties associated with logged-in user
|
![]() | Strategies |
Strategy functionality
|
![]() | Strings |
String operations
|
![]() | Subscriptions |
Subscription functionality
|
![]() | Threading |
Threading functionality
|
![]() | Traders |
Traders functionality
|
![]() | Users |
Users functionality
|
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 detailsClient 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();
client.Connection.Aggregate.LoginCompleted += GFClient_OnLoginCompleted; client.Connection.Aggregate.LoginFailed += GFClient_OnLoginFailed; client.Connection.Aggregate.Disconnected += GFClient_OnDisconnected;
var runner = new GFClientRunner(gfClient); runner.Start();
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
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();
IReadOnlyList<OrderDraftValidationError> validationErrors = client.Orders.Drafts.Validate(orderDraft); if (validationErrors.Any()) { foreach (var error in validationErrors) Console.WriteLine($"\t{error.Message}"); }
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); ... }
_subscription.Unsubscribe();
See Also