ForeksPubsubSdk 1.0.18

Foreks Connection Sdk - Pubsub Client

.Net SDK to connect Foreks Pubsub Server

Install-Package ForeksPubsubSdk -Version 1.0.18
dotnet add package ForeksPubsubSdk --version 1.0.18
<PackageReference Include="ForeksPubsubSdk" Version="1.0.18" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ForeksPubsubSdk --version 1.0.18
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Quick Start

Simple 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

  • ToDEV
  • ToUAT
  • ToPROD
  • ToPRODSlave
ConnectionOptions connectionOptions = new ConnectionOptions({{hostname}},{{port}},{{username}},{{password}},{{applicationName}});
//or
ConnectionOptions connectionOptions = ConnectionOptions.ToPROD({{your_username}}, {{your_password}},{{applicationName}});

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: When the response of a login request is received this event will be triggered despite the fact that the login is succeeded.
  • OnHeartbeat: When the server sends heartbeat message, this event will be triggered. Server heartbeat messages periodically. Client heartbeat messages are send in the background.
  • OnData: When the subscribed field is changed, server sends new data and this event will be triggered.
  • OnDisconnect: When the connection is dropped, this event will be triggered.
  • OnError: When the server sends Error or Unknown message, this event will be triggered.
  • OnMessage: When the server sends global message, this event will be triggered. Not in use yet.
  • OnNotification: When the server sends notification, this event will be triggered.
  • OnSymbolAdd: When a symbol is added to definition, such as hot insert in BIST, this event will be triggered. Definition of the symbol will be sent.
  • OnSymbolRemove: When a symbol is removed from definition, this event will be triggered. Definition of the symbol will be sent.

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();
//or
foreksPubsubClient.StartWithoutBlocking();

Stopping Data
With stop function, unsubscribeAll method is triggered and existed TCP connection is closed.

foreksPubsubClient.Stop();

EXAMPLE

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}}, {{your_applicationName}});

                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) { }
        }
    }
}

Quick Start

Simple 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

  • ToDEV
  • ToUAT
  • ToPROD
  • ToPRODSlave
ConnectionOptions connectionOptions = new ConnectionOptions({{hostname}},{{port}},{{username}},{{password}},{{applicationName}});
//or
ConnectionOptions connectionOptions = ConnectionOptions.ToPROD({{your_username}}, {{your_password}},{{applicationName}});

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: When the response of a login request is received this event will be triggered despite the fact that the login is succeeded.
  • OnHeartbeat: When the server sends heartbeat message, this event will be triggered. Server heartbeat messages periodically. Client heartbeat messages are send in the background.
  • OnData: When the subscribed field is changed, server sends new data and this event will be triggered.
  • OnDisconnect: When the connection is dropped, this event will be triggered.
  • OnError: When the server sends Error or Unknown message, this event will be triggered.
  • OnMessage: When the server sends global message, this event will be triggered. Not in use yet.
  • OnNotification: When the server sends notification, this event will be triggered.
  • OnSymbolAdd: When a symbol is added to definition, such as hot insert in BIST, this event will be triggered. Definition of the symbol will be sent.
  • OnSymbolRemove: When a symbol is removed from definition, this event will be triggered. Definition of the symbol will be sent.

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();
//or
foreksPubsubClient.StartWithoutBlocking();

Stopping Data
With stop function, unsubscribeAll method is triggered and existed TCP connection is closed.

foreksPubsubClient.Stop();

EXAMPLE

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}}, {{your_applicationName}});

                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) { }
        }
    }
}

Release Notes

Initial Release

Version History

Version Downloads Last updated
1.0.18 0 5/23/2019
1.0.17 119 1/4/2019
1.0.16 75 12/19/2018
1.0.15 125 12/10/2018
1.0.14 78 12/7/2018
1.0.13 172 12/5/2018
1.0.12 106 12/5/2018
1.0.11 95 11/26/2018
1.0.10 100 11/26/2018
1.0.9 85 11/22/2018
1.0.8 109 10/19/2018
1.0.7 104 10/16/2018
1.0.6 157 8/8/2018
1.0.5 147 8/3/2018
1.0.4 170 8/3/2018
1.0.3 153 8/3/2018
1.0.2 129 8/2/2018
1.0.1 130 8/2/2018
1.0.0 142 8/2/2018