.Net SDK to connect ForInvest Pubsub Server
License
—
Deps
2
Install Size
—
Vulns
✓ 0
Published
Apr 8, 2025
$ dotnet add package ForeksPubsubSdkSimple explanations of the functions can be found in this section.
Deciding Options Options must be decided and an object instance of ConnectionOptions class must be created to connect Foreks Pubsub Server. Help for username and password click www.foreks.com.
Some static functions are implemented to connect predefined destiontion ip and port
ConnectionOptions connectionOptions = new ConnectionOptions({{hostname}},{{port}},{{username}},{{password}});
//or
ConnectionOptions connectionOptions = ConnectionOptions.ToPROD({{your_username}}, {{your_password}});
Reconnect parameter: When the connection is dropped, new connection is established automatically. Default is true; On state of unauthorized user and login on another device, reconnection is not start.
Creating Client An object instance of PubsubClient must be created. Object takes an object instance of connectionOptions class.
PubsubClient foreksPubsubClient = new PubsubClient(connectionOptions);
Listening Events PubsubClient events must be listened.
OnLogin If the ResponseArgs.Success is false, the status of the user must be determined via the ResponseArgs.Code. Along with unsuccessful OnLogin method, OnDisconnect method is called also.
*ConnectionStatus.Drop.SERVER_LOGOUT : login on another device *ConnectionStatus.Drop.LOGIN_REJECT : unauthorized *ConnectionStatus.Drop.SERVER_EXCEPTION : server exception
foreksPubsubClient.OnLogin += PubsubClient_OnLogin;
foreksPubsubClient.OnHeartbeat += PubsubClient_OnHeartbeat;
foreksPubsubClient.OnData += PubsubClient_OnData;
foreksPubsubClient.OnDisconnect += PubsubClient_OnDisconnect;
foreksPubsubClient.OnError += PubsubClient_OnError;
foreksPubsubClient.OnMessage += PubsubClient_OnMessage;
foreksPubsubClient.OnNotification += PubsubClient_OnNotification;
foreksPubsubClient.OnSymbolAdd += PubsubClient_OnSymbolAdd;
foreksPubsubClient.OnSymbolRemove += PubsubClient_OnSymbolRemove;
Subscription Subscribe method of an object which is an instance of PubsubClient takes to List<string> as an input parameters. First one holds the id's of the symbols which can be found in https://feed-definition.foreks.com/symbol/search Second one holds the shortCode's of the fields which are predefined in Fields class.
foreksPubsubClient.Subscribe(new List<string>() { "H1846", "H14678" }, new List<string>() { Fields.Last, Fields.DateTime });
You can use 'ForeksDefinitions' helper method instead of id's.
Unsubscription
Unsubscribe(symbols,fields) Unsubscribe(symbols) UnsubscribeAll()
foreksPubsubClient.Unsubscribe(new List<string>() { "H1846" }, new List<string>() { Fields.Last });
Listening Data With start function, new TCP connection is created and login request is send. If the login request is succeeded, subscriptions which were set before start function are called automatically. With every incoming data related event is triggered.
foreksPubsubClient.Start();
Stopping Data With stop function, unsubscribeAll method is triggered and existed TCP connection is closed.
foreksPubsubClient.Stop();
using System;
using System.Collections.Generic;
using ForeksPubsubSdk;
namespace PubsubTest
{
class MainClass
{
static void ForeksPubsubClient_OnNotification(object sender, ResponseArgs e)
{
Console.WriteLine("OnNotification: " + e.ToString());
}
static void ForeksPubsubClient_OnSymbolRemove(object sender, ResponseArgs e)
{
Console.WriteLine("OnSymbolAdd: " + e.ToString());
}
static void ForeksPubsubClient_OnSymbolAdd(object sender, ResponseArgs e)
{
Console.WriteLine("OnSymbolAdd: " + e.ToString());
}
static void ForeksPubsubClient_OnError(object sender, ResponseArgs e)
{
Console.WriteLine("OnError: " + e.ToString());
}
static void ForeksPubsubClient_OnDisconnect(object sender, ResponseArgs e)
{
Console.WriteLine("OnDisconnect: " + e.ToString());
}
static void ForeksPubsubClient_OnHeartbeat(object sender, ResponseArgs e)
{
Console.WriteLine("OnHeartbeat: " + e.ToString());
}
static void ForeksPubsubClient_OnLogin(object sender, ResponseArgs e)
{
Console.WriteLine("OnLogin: " + e.ToString());
}
static void ForeksPubsubClient_OnMessage(object sender, ResponseArgs e)
{
Console.WriteLine("OnMessage: " + e.ToString());
}
static void ForeksPubsubClient_OnData(object sender, ResponseArgs e)
{
Console.WriteLine("OnData: " + e.ToString());
}
static void Main(string[] args)
{
try
{
ConnectionOptions connectionOptions = ConnectionOptions.ToPROD({{your_username}}, {{your_password}});
PubsubClient foreksPubsubClient = new PubsubClient(connectionOptions);
foreksPubsubClient.OnLogin += ForeksPubsubClient_OnLogin;
foreksPubsubClient.OnHeartbeat += ForeksPubsubClient_OnHeartbeat;
foreksPubsubClient.OnData += ForeksPubsubClient_OnData;
foreksPubsubClient.OnDisconnect += ForeksPubsubClient_OnDisconnect;
foreksPubsubClient.OnError += ForeksPubsubClient_OnError;
foreksPubsubClient.OnMessage += ForeksPubsubClient_OnMessage;
foreksPubsubClient.OnNotification += ForeksPubsubClient_OnNotification;
foreksPubsubClient.OnSymbolAdd += ForeksPubsubClient_OnSymbolAdd;
foreksPubsubClient.OnSymbolRemove += ForeksPubsubClient_OnSymbolRemove;
foreksPubsubClient.Subscribe(new List<string>() { "H1846", "H14678" }, new List<string>() { Fields.Last, Fields.DateTime });
//ForeksDefinitions helper method for finding ids
//ForeksDefinitions foreksDefinitions = new ForeksDefinitions(connectionOptions);
//foreksPubsubClient.Subscribe(foreksDefinitions.GetSubscriptionList("code=EURUSD&code=GARAN"), new List<string>() { Fields.Last, Fields.DateTime });
foreksPubsubClient.Start();
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
while (true) { }
}
}
}