dxFeed .Net API  5.13.0
dxFeed .Net API library intended to provide market data access for DX clients
Public Member Functions | Properties | Events | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
com.dxfeed.ipf.live.InstrumentProfileConnection Class Reference

Connects to an instrument profile URL and reads instrument profiles using Simple File Format with support of streaming live updates. Please see Instrument Profile Format documentation for complete description. More...

Collaboration diagram for com.dxfeed.ipf.live.InstrumentProfileConnection:
[legend]

Public Member Functions

delegate void OnErrorEventHandler (object sender, ErrorEventArgs e)
 
 InstrumentProfileConnection (string address)
 Creates instrument profile connection with a specified address. Address may be just "<host>:<port>" of server, URL, or a file path. The "[update=<period>]" clause can be optionally added at the end of the address to specify an UpdatePeriod via an address string. Default update period is 1 minute. Connection needs to be started to begin an actual operation. More...
 
void Start ()
 Starts this instrument profile connection. This connection's state immediately changes to State.Connecting and the actual connection establishment proceeds in the background. More...
 
void Close ()
 Closes this instrument profile connection. This connection's state immediately changes to State.Closed and the background update procedures are terminated. More...
 
void AddUpdateListener (InstrumentProfileUpdateListener listener)
 Adds listener that is notified about any updates in the set of instrument profiles. If a set of instrument profiles is not empty, then this listener is immediately notified right from inside this add method. More...
 
void RemoveUpdateListener (InstrumentProfileUpdateListener listener)
 Removes listener that is notified about any updates in the set of instrument profiles. More...
 
override string ToString ()
 Returns a string representation of the object. More...
 

Properties

long UpdatePeriod [get, set]
 Gets or sets update period in milliseconds. It is period of an update check when the instrument profiles source does not support live updates and/or when connection is dropped. Default update period is 1 minute. More...
 
State CurrentState [get]
 Returns state of this instrument profile connections. More...
 
DateTime LastModified [get, set]
 Get or set modification time of instrument profiles or DateTime.MinValue if it is unknown. More...
 

Events

OnErrorEventHandler OnError
 

Private Types

enum  State {
  State.NotConnected, State.Connecting, State.Connected, State.Completed,
  State.Closed
}
 Instrument profile connection state. More...
 

Private Member Functions

void Handler ()
 Method of worker thread. Runs downloading process by specified update period. More...
 
void MakeConnected ()
 Change connection status to connected. More...
 
void MakeComplete ()
 Change connection status to completed. More...
 
void Download ()
 Opens (or keeps) connection for receiving instrument profiles from server. More...
 
void Process (Stream inputStream)
 Instrument profiles parser operations. More...
 
void Flush (object sender, EventArgs e)
 Sends updates to listeners. More...
 
void Complete (object sender, EventArgs e)
 Set status of completed snapshot and sends updates to listeners. More...
 
void CallListeners (ICollection< InstrumentProfile > instrumentProfiles)
 Iterate through listeners and call them. More...
 
void CallOnError (Exception e)
 Call error listener. More...
 

Static Private Member Functions

static void CheckAndCallListener (InstrumentProfileUpdateListener listener, ICollection< InstrumentProfile > instrumentProfiles)
 Check that instrument profiles update is not empty and call listener. More...
 

Private Attributes

const string UpdatePattern = "(.*)\\[update=([^\\]]+)\\]"
 
const long DefaultUpdatePeriod = 60000
 
State state = State.NotConnected
 
long updatePeriod = DefaultUpdatePeriod
 
readonly string address
 
readonly object stateLocker = new object()
 
readonly object lastModifiedLocker = new object()
 
readonly object listenersLocker = new object()
 
WebResponse webResponse
 
readonly object webResponseLocker = new object()
 
Thread handlerThread
 Working thread to download instruments. Thread must != null when state in (CONNECTING, CONNECTED, COMPLETE). More...
 
DateTime lastModified = DateTime.MinValue
 
bool supportsLive
 
readonly List< InstrumentProfileUpdateListenerlisteners = new List<InstrumentProfileUpdateListener>()
 
readonly List< InstrumentProfileipBuffer = new List<InstrumentProfile>()
 
readonly InstrumentProfileUpdater updater = new InstrumentProfileUpdater()
 

Detailed Description

Connects to an instrument profile URL and reads instrument profiles using Simple File Format with support of streaming live updates. Please see Instrument Profile Format documentation for complete description.

The key different between this class and InstrumentProfileReader is that the later just reads a snapshot of a set of instrument profiles, while this classes allows to track live updates, e.g. addition and removal of instruments.

To use this class you need an address of the data source from you data provider. The name of the IPF file can also serve as an address for debugging purposes.

The recommended usage of this class to receive a live stream of instrument profile updates is:

class UpdateListener : InstrumentProfileUpdateListener {
public void InstrumentProfilesUpdated(ICollection<InstrumentProfile> instruments) {
foreach (InstrumentProfile ip in instruments) {
// do something with instrument here.
}
}
}
class Program {
static void Main(string[] args) {
string address = "<host>:<port>";
UpdateListener updateListener = new UpdateListener();
connection.AddUpdateListener(updateListener);
connection.Start();
}
}

If long-running processing of instrument profile is needed, then it is better to use InstrumentProfileUpdateListener.InstrumentProfilesUpdated notification to schedule processing task in a separate thread.

This class is thread-safe.

Member Enumeration Documentation

◆ State

Instrument profile connection state.

Enumerator
NotConnected 

Instrument profile connection is not started yet. InstrumentProfileConnection.Start() was not invoked yet.

Connecting 

Connection is being established.

Connected 

Connection was established.

Completed 

Initial instrument profiles snapshot was fully read (this state is set only once).

Closed 

Instrument profile connection was closed.

Constructor & Destructor Documentation

◆ InstrumentProfileConnection()

com.dxfeed.ipf.live.InstrumentProfileConnection.InstrumentProfileConnection ( string  address)
inline

Creates instrument profile connection with a specified address. Address may be just "&lt;host&gt;:&lt;port&gt;" of server, URL, or a file path. The "[update=&lt;period&gt;]" clause can be optionally added at the end of the address to specify an UpdatePeriod via an address string. Default update period is 1 minute. Connection needs to be started to begin an actual operation.

Parameters
addressAddress of server

Member Function Documentation

◆ AddUpdateListener()

void com.dxfeed.ipf.live.InstrumentProfileConnection.AddUpdateListener ( InstrumentProfileUpdateListener  listener)
inline

Adds listener that is notified about any updates in the set of instrument profiles. If a set of instrument profiles is not empty, then this listener is immediately notified right from inside this add method.

Parameters
listenerProfile update listener.
Exceptions
ArgumentNullExceptionIf listener is null.

◆ CallListeners()

void com.dxfeed.ipf.live.InstrumentProfileConnection.CallListeners ( ICollection< InstrumentProfile instrumentProfiles)
inlineprivate

Iterate through listeners and call them.

Parameters
instrumentProfiles

◆ CallOnError()

void com.dxfeed.ipf.live.InstrumentProfileConnection.CallOnError ( Exception  e)
inlineprivate

Call error listener.

Parameters
eException object.

◆ CheckAndCallListener()

static void com.dxfeed.ipf.live.InstrumentProfileConnection.CheckAndCallListener ( InstrumentProfileUpdateListener  listener,
ICollection< InstrumentProfile instrumentProfiles 
)
inlinestaticprivate

Check that instrument profiles update is not empty and call listener.

Parameters
listenerListener to call.
instrumentProfilesInstrument profiles updates.

◆ Close()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Close ( )
inline

Closes this instrument profile connection. This connection's state immediately changes to State.Closed and the background update procedures are terminated.

◆ Complete()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Complete ( object  sender,
EventArgs  e 
)
inlineprivate

Set status of completed snapshot and sends updates to listeners.

Parameters
sender
e

◆ Download()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Download ( )
inlineprivate

Opens (or keeps) connection for receiving instrument profiles from server.

◆ Flush()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Flush ( object  sender,
EventArgs  e 
)
inlineprivate

Sends updates to listeners.

Parameters
sender
e

◆ Handler()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Handler ( )
inlineprivate

Method of worker thread. Runs downloading process by specified update period.

◆ MakeComplete()

void com.dxfeed.ipf.live.InstrumentProfileConnection.MakeComplete ( )
inlineprivate

Change connection status to completed.

◆ MakeConnected()

void com.dxfeed.ipf.live.InstrumentProfileConnection.MakeConnected ( )
inlineprivate

Change connection status to connected.

◆ OnErrorEventHandler()

delegate void com.dxfeed.ipf.live.InstrumentProfileConnection.OnErrorEventHandler ( object  sender,
ErrorEventArgs  e 
)

◆ Process()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Process ( Stream  inputStream)
inlineprivate

Instrument profiles parser operations.

Parameters
inputStreamDecompressed input stream of instrument profiles.
Returns
Number of received instrument profiles.

◆ RemoveUpdateListener()

void com.dxfeed.ipf.live.InstrumentProfileConnection.RemoveUpdateListener ( InstrumentProfileUpdateListener  listener)
inline

Removes listener that is notified about any updates in the set of instrument profiles.

Parameters
listenerProfile update listener.
Exceptions
ArgumentNullExceptionIf listener is null.

◆ Start()

void com.dxfeed.ipf.live.InstrumentProfileConnection.Start ( )
inline

Starts this instrument profile connection. This connection's state immediately changes to State.Connecting and the actual connection establishment proceeds in the background.

◆ ToString()

override string com.dxfeed.ipf.live.InstrumentProfileConnection.ToString ( )
inline

Returns a string representation of the object.

Returns
String representation of the object.

Field Documentation

◆ address

readonly string com.dxfeed.ipf.live.InstrumentProfileConnection.address
private

◆ DefaultUpdatePeriod

const long com.dxfeed.ipf.live.InstrumentProfileConnection.DefaultUpdatePeriod = 60000
private

◆ handlerThread

Thread com.dxfeed.ipf.live.InstrumentProfileConnection.handlerThread
private

Working thread to download instruments. Thread must != null when state in (CONNECTING, CONNECTED, COMPLETE).

◆ ipBuffer

readonly List<InstrumentProfile> com.dxfeed.ipf.live.InstrumentProfileConnection.ipBuffer = new List<InstrumentProfile>()
private

◆ lastModified

DateTime com.dxfeed.ipf.live.InstrumentProfileConnection.lastModified = DateTime.MinValue
private

◆ lastModifiedLocker

readonly object com.dxfeed.ipf.live.InstrumentProfileConnection.lastModifiedLocker = new object()
private

◆ listeners

readonly List<InstrumentProfileUpdateListener> com.dxfeed.ipf.live.InstrumentProfileConnection.listeners = new List<InstrumentProfileUpdateListener>()
private

◆ listenersLocker

readonly object com.dxfeed.ipf.live.InstrumentProfileConnection.listenersLocker = new object()
private

◆ state

State com.dxfeed.ipf.live.InstrumentProfileConnection.state = State.NotConnected
private

◆ stateLocker

readonly object com.dxfeed.ipf.live.InstrumentProfileConnection.stateLocker = new object()
private

◆ supportsLive

bool com.dxfeed.ipf.live.InstrumentProfileConnection.supportsLive
private

◆ UpdatePattern

const string com.dxfeed.ipf.live.InstrumentProfileConnection.UpdatePattern = "(.*)\\[update=([^\\]]+)\\]"
private

◆ updatePeriod

long com.dxfeed.ipf.live.InstrumentProfileConnection.updatePeriod = DefaultUpdatePeriod
private

◆ updater

readonly InstrumentProfileUpdater com.dxfeed.ipf.live.InstrumentProfileConnection.updater = new InstrumentProfileUpdater()
private

◆ webResponse

WebResponse com.dxfeed.ipf.live.InstrumentProfileConnection.webResponse
private

◆ webResponseLocker

readonly object com.dxfeed.ipf.live.InstrumentProfileConnection.webResponseLocker = new object()
private

Property Documentation

◆ CurrentState

State com.dxfeed.ipf.live.InstrumentProfileConnection.CurrentState
getprivate

Returns state of this instrument profile connections.

◆ LastModified

DateTime com.dxfeed.ipf.live.InstrumentProfileConnection.LastModified
getsetprivate

Get or set modification time of instrument profiles or DateTime.MinValue if it is unknown.

◆ UpdatePeriod

long com.dxfeed.ipf.live.InstrumentProfileConnection.UpdatePeriod
getset

Gets or sets update period in milliseconds. It is period of an update check when the instrument profiles source does not support live updates and/or when connection is dropped. Default update period is 1 minute.

Event Documentation

◆ OnError

OnErrorEventHandler com.dxfeed.ipf.live.InstrumentProfileConnection.OnError

The documentation for this class was generated from the following file: