Messaging

GF API Documentation

GF API also provides functionality for news feed and chat with GAIN Capital Futures administrators

Notifications

To receive notifications, just listen to the OnNotificationMessage event.

Notifications
private static void RegisterOnNotificationMessage(IGFClient client)
{
    client.Connection.Aggregate.LoginCompleted += GFClient_OnLoginCompleted;
    client.Messaging.Notifications.NotificationMessageReceived += GFClient_OnNotificationMessageReceived;
}

private static void GFClient_OnLoginCompleted(IGFClient client,
    GF.Api.Connection.LoginCompleteEventArgs loginCompleteEventArgs)
{
    DisplayNotificationHistory(client);
}

private static void GFClient_OnNotificationMessageReceived(IGFClient client, NotificationMessageEventArgs e)
{
    DisplayNotificationMessage(DateTime.UtcNow, e.NotificationMessage.Channel, e.NotificationMessage.Message);
}

private static void DisplayNotificationHistory(IGFClient client)
{
    foreach (var notification in client.Messaging.Notifications.Get())
        DisplayNotificationMessage(notification.Timestamp, notification.Channel, notification.Message);
}

private static void DisplayNotificationMessage(DateTime timestamp, NotificationChannel channel, string message)
{
    Console.WriteLine($"Notification received. {channel}: {message} at {timestamp.ToLocalTime()}");
}
Note Note

Customer Service can enable particular channels for a user.

Chat

Chat functionality is the same level of simplicity. Let's implement some code that will let your counterpart know that there is no human operating your application:

Chat
private static void RegisterOnChatMessage(GF.Api.IGFClient client)
{
    client.Messaging.Chat.ChatMessageReceived += GFClient_OnChatMessageReceived;
}

private static void GFClient_OnChatMessageReceived(GF.Api.IGFClient client, GF.Api.Messaging.Chat.ChatMessageEventArgs e)
{
    Console.WriteLine($"User Message. {e.ChatMessage.FromUser.Name} - {e.ChatMessage.Message}");
    client.Messaging.Chat.SendMessage(e.ChatMessage.FromUser.ID, "Hey, I'm just a robot!");
}

Now our TradeDesk guys will see this in their application:

5:17 PM to vic: Please close all positions
5:17 PM vic: Hey, I'm just a robot!