Class ExternalLiveBaseProvider
- All Implemented Interfaces:
java.lang.AutoCloseable
,Layer1ApiAdminListenable
,Layer1ApiAdminProvider
,Layer1ApiDataListenable
,Layer1ApiDataProvider
,Layer1ApiInstrumentListenable
,Layer1ApiInstrumentProvider
,Layer1ApiMboDataListenable
,Layer1ApiProvider
,Layer1ApiTradingListenable
,Layer1ApiTradingProvider
,LayerApiListenable
public abstract class ExternalLiveBaseProvider extends java.lang.Object implements Layer1ApiProvider
This is a base class that should help you writing your own connector for live data and trading.
Lifecycle
Typical lifecycle looks like this:
- Provider is created (constructor with no parameters is invoked).
- addListener methods are called. Provider should remember the listeners and use those for sending data later.
Layer1ApiAdminProvider.login(LoginData)
is called with instance ofUserPasswordDemoLoginData
as parameter.- Provider should attempt to establish connection asynchronously, if that
fails it should call
Layer1ApiAdminListener.onLoginFailed(velox.api.layer1.data.LoginFailedReason, String)
and anotherLayer1ApiAdminProvider.login(LoginData)
call can be made later. If connection is establishedLayer1ApiAdminListener.onLoginSuccessful()
should be called -
Now provider is in connected state. Subscription/unsubscription requests could be made as well as order-related requests (if provider supports trading, which should be stated using
getSupportedFeatures()
).Provider should push updates into Bookmap by calling corresponding listener methods.
If connection is lost provider can report it with
Layer1ApiAdminAdapter.onConnectionLost(velox.api.layer1.data.DisconnectionReason, String)
and useLayer1ApiAdminListener.onConnectionRestored()
when it's restored. Layer1ApiAdminProvider.close()
is invoked. This is the place to clean up resources. After this point provider instance will not be used anymore.
However it's possible that Layer1ApiAdminProvider.close()
method will be called earlier. In
this case provider should stop invoking callbacks and clean up resources.
Important note: All callbacks that do not return a value are asynchronous. Timestamp of an event is defined by the time when callback was invoked. Provider methods that do not return value are also allowed to be implemented in asynchronous manner. For ones that take noticeable amount of time it's recommended.
If event rate is higher than Bookmap can process events will be queued but timestamps will not be distorted.
-
Field Summary
Fields Modifier and Type Field Description java.util.concurrent.CopyOnWriteArrayList<Layer1ApiAdminListener>
adminListeners
java.util.concurrent.CopyOnWriteArrayList<Layer1ApiDataListener>
dataListeners
java.util.concurrent.CopyOnWriteArrayList<Layer1ApiInstrumentListener>
instrumentListeners
java.util.concurrent.CopyOnWriteArrayList<Layer1ApiMboDataListener>
mboDataListeners
java.util.concurrent.CopyOnWriteArrayList<Layer1ApiTradingListener>
tradingListeners
-
Constructor Summary
Constructors Constructor Description ExternalLiveBaseProvider()
-
Method Summary
Modifier and Type Method Description void
addListener(Layer1ApiAdminListener listener)
Add listener for general eventsvoid
addListener(Layer1ApiDataListener listener)
Add data listenervoid
addListener(Layer1ApiInstrumentListener listener)
Add instrument events listenervoid
addListener(Layer1ApiMboDataListener listener)
Add mbo data listenervoid
addListener(Layer1ApiTradingListener listener)
Add trading listenerprotected java.lang.String
formatPriceDefault(double pips, double price)
Formats prices using default bookmap price formatting logic.long
getCurrentTime()
This method will not be invoked for external providersLayer1ApiProviderSupportedFeatures
getSupportedFeatures()
You can override this if you are implementing a live trading support.void
removeListener(Layer1ApiAdminListener listener)
Remove listener for general eventsvoid
removeListener(Layer1ApiDataListener listener)
Remove data listenervoid
removeListener(Layer1ApiInstrumentListener listener)
Remove instrument events listenervoid
removeListener(Layer1ApiMboDataListener listener)
Remove mbo data listenervoid
removeListener(Layer1ApiTradingListener listener)
Remove trading listenerjava.lang.Object
sendUserMessage(java.lang.Object data)
Some messages might reach the provider, but those can be ignoredMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface velox.api.layer1.Layer1ApiInstrumentProvider
subscribe, subscribe, unsubscribe
-
Field Details
-
Constructor Details
-
ExternalLiveBaseProvider
public ExternalLiveBaseProvider()
-
-
Method Details
-
formatPriceDefault
protected java.lang.String formatPriceDefault(double pips, double price)Formats prices using default bookmap price formatting logic. In newer versions of bookmapPriceFormatHelper.formatPriceDefault(double, double)
can be used instead -
getSupportedFeatures
You can override this if you are implementing a live trading support.- Specified by:
getSupportedFeatures
in interfaceLayer1ApiAdminProvider
- Returns:
- object describing supported features
- See Also:
MaximumSupportedFeatures
-
sendUserMessage
public java.lang.Object sendUserMessage(java.lang.Object data)Some messages might reach the provider, but those can be ignored- Specified by:
sendUserMessage
in interfaceLayer1ApiAdminProvider
- Parameters:
data
- Message content- Returns:
-
addListener
Description copied from interface:Layer1ApiAdminListenable
Add listener for general events- Specified by:
addListener
in interfaceLayer1ApiAdminListenable
- Parameters:
listener
- listener to add
-
removeListener
Description copied from interface:Layer1ApiAdminListenable
Remove listener for general events- Specified by:
removeListener
in interfaceLayer1ApiAdminListenable
- Parameters:
listener
- listener to remove
-
addListener
Description copied from interface:Layer1ApiInstrumentListenable
Add instrument events listener- Specified by:
addListener
in interfaceLayer1ApiInstrumentListenable
- Parameters:
listener
- listener to add
-
removeListener
Description copied from interface:Layer1ApiInstrumentListenable
Remove instrument events listener- Specified by:
removeListener
in interfaceLayer1ApiInstrumentListenable
- Parameters:
listener
- listener to remove
-
addListener
Description copied from interface:Layer1ApiTradingListenable
Add trading listener- Specified by:
addListener
in interfaceLayer1ApiTradingListenable
- Parameters:
listener
- listener to add
-
removeListener
Description copied from interface:Layer1ApiTradingListenable
Remove trading listener- Specified by:
removeListener
in interfaceLayer1ApiTradingListenable
- Parameters:
listener
- listener to remove
-
addListener
Description copied from interface:Layer1ApiDataListenable
Add data listener- Specified by:
addListener
in interfaceLayer1ApiDataListenable
- Parameters:
listener
- listener to add
-
removeListener
Description copied from interface:Layer1ApiDataListenable
Remove data listener- Specified by:
removeListener
in interfaceLayer1ApiDataListenable
- Parameters:
listener
- listener to remove
-
addListener
Description copied from interface:Layer1ApiMboDataListenable
Add mbo data listener- Specified by:
addListener
in interfaceLayer1ApiMboDataListenable
- Parameters:
listener
- listener to add
-
removeListener
Description copied from interface:Layer1ApiMboDataListenable
Remove mbo data listener- Specified by:
removeListener
in interfaceLayer1ApiMboDataListenable
- Parameters:
listener
- listener to remove
-
getCurrentTime
public final long getCurrentTime()This method will not be invoked for external providers- Specified by:
getCurrentTime
in interfaceLayer1ApiAdminProvider
- Returns:
- current Unix epoch time in nanoseconds
-