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 ofUserPasswordDemoLoginDataas 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>adminListenersjava.util.concurrent.CopyOnWriteArrayList<Layer1ApiDataListener>dataListenersjava.util.concurrent.CopyOnWriteArrayList<Layer1ApiInstrumentListener>instrumentListenersjava.util.concurrent.CopyOnWriteArrayList<Layer1ApiMboDataListener>mboDataListenersjava.util.concurrent.CopyOnWriteArrayList<Layer1ApiTradingListener>tradingListeners -
Constructor Summary
Constructors Constructor Description ExternalLiveBaseProvider() -
Method Summary
Modifier and Type Method Description voidaddListener(Layer1ApiAdminListener listener)Add listener for general eventsvoidaddListener(Layer1ApiDataListener listener)Add data listenervoidaddListener(Layer1ApiInstrumentListener listener)Add instrument events listenervoidaddListener(Layer1ApiMboDataListener listener)Add mbo data listenervoidaddListener(Layer1ApiTradingListener listener)Add trading listenerprotected java.lang.StringformatPriceDefault(double pips, double price)Formats prices using default bookmap price formatting logic.longgetCurrentTime()This method will not be invoked for external providersLayer1ApiProviderSupportedFeaturesgetSupportedFeatures()You can override this if you are implementing a live trading support.voidremoveListener(Layer1ApiAdminListener listener)Remove listener for general eventsvoidremoveListener(Layer1ApiDataListener listener)Remove data listenervoidremoveListener(Layer1ApiInstrumentListener listener)Remove instrument events listenervoidremoveListener(Layer1ApiMboDataListener listener)Remove mbo data listenervoidremoveListener(Layer1ApiTradingListener listener)Remove trading listenerjava.lang.ObjectsendUserMessage(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, waitMethods 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:
getSupportedFeaturesin 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:
sendUserMessagein interfaceLayer1ApiAdminProvider- Parameters:
data- Message content- Returns:
-
addListener
Description copied from interface:Layer1ApiAdminListenableAdd listener for general events- Specified by:
addListenerin interfaceLayer1ApiAdminListenable- Parameters:
listener- listener to add
-
removeListener
Description copied from interface:Layer1ApiAdminListenableRemove listener for general events- Specified by:
removeListenerin interfaceLayer1ApiAdminListenable- Parameters:
listener- listener to remove
-
addListener
Description copied from interface:Layer1ApiInstrumentListenableAdd instrument events listener- Specified by:
addListenerin interfaceLayer1ApiInstrumentListenable- Parameters:
listener- listener to add
-
removeListener
Description copied from interface:Layer1ApiInstrumentListenableRemove instrument events listener- Specified by:
removeListenerin interfaceLayer1ApiInstrumentListenable- Parameters:
listener- listener to remove
-
addListener
Description copied from interface:Layer1ApiTradingListenableAdd trading listener- Specified by:
addListenerin interfaceLayer1ApiTradingListenable- Parameters:
listener- listener to add
-
removeListener
Description copied from interface:Layer1ApiTradingListenableRemove trading listener- Specified by:
removeListenerin interfaceLayer1ApiTradingListenable- Parameters:
listener- listener to remove
-
addListener
Description copied from interface:Layer1ApiDataListenableAdd data listener- Specified by:
addListenerin interfaceLayer1ApiDataListenable- Parameters:
listener- listener to add
-
removeListener
Description copied from interface:Layer1ApiDataListenableRemove data listener- Specified by:
removeListenerin interfaceLayer1ApiDataListenable- Parameters:
listener- listener to remove
-
addListener
Description copied from interface:Layer1ApiMboDataListenableAdd mbo data listener- Specified by:
addListenerin interfaceLayer1ApiMboDataListenable- Parameters:
listener- listener to add
-
removeListener
Description copied from interface:Layer1ApiMboDataListenableRemove mbo data listener- Specified by:
removeListenerin interfaceLayer1ApiMboDataListenable- Parameters:
listener- listener to remove
-
getCurrentTime
public final long getCurrentTime()This method will not be invoked for external providers- Specified by:
getCurrentTimein interfaceLayer1ApiAdminProvider- Returns:
- current Unix epoch time in nanoseconds
-