Class ExternalLiveBaseProvider
- All Implemented Interfaces:
AutoCloseable,Layer1ApiAdminListenable,Layer1ApiAdminProvider,Layer1ApiDataListenable,Layer1ApiDataProvider,Layer1ApiInstrumentListenable,Layer1ApiInstrumentProvider,Layer1ApiMboDataListenable,Layer1ApiProvider,Layer1ApiTradingListenable,Layer1ApiTradingProvider,LayerApiListenable
This is a base class that should help you writing your own connector for live data and trading.
Lifecycle
Typical lifecycle looks like this:
- An instance of your provider class is created (constructor with no parameters is invoked).
- addListener methods are called. Assuming you are extending this class, you don't need to worry about this step. This allows your provider to send data into Bookmap.
- A user tries to connect the provider -
Layer1ApiAdminProvider.login(LoginData)is called with either an instance of:UserPasswordDemoLoginData- by defaultExtendedLoginData- if you usedLayer0CredentialsFieldsManagerannotation on your adapter
- This object contains the user's credentials, you may use it to login into the exchange API.
- Provider should attempt to establish connection asynchronously.
- If the attempt fails (connection issues, wrong credentials), your provider should
should call
Layer1ApiAdminListener.onLoginFailed(LoginFailedReason, String). In this case the provider will be automatically unloaded withLayer1ApiAdminProvider.close()call. - If connection is established
Layer1ApiAdminListener.onLoginSuccessful()should be called
- If the attempt fails (connection issues, wrong credentials), your provider should
should call
-
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 methods on the corresponding listeners, e.g. to push a depth update use:
dataListeners.forEach(listener -> listener.onDepth(alias, isBid, price, size)); -
If the connection is lost provider can report it with
Layer1ApiAdminListener.onConnectionLost(DisconnectionReason, String)and useLayer1ApiAdminListener.onConnectionRestored()when it's restored. - Provider can be disconnected at any time - in this case
Layer1ApiAdminProvider.close()is invoked. After this point provider instance will not be used anymore. Your provider should clean up resources and stop invoking callbacks
Important note: All callbacks that do not return a value (upstream
events, available via *Listener interfaces, like Layer1ApiAdminListener),
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(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 StringformatPriceDefault(double pips, double price) Formats prices using default bookmap price formatting logic.final longThis method will not be invoked for external providersYou 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 listenersendUserMessage(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.Layer1ApiAdminProvider
close, getSource, loginMethods inherited from interface velox.api.layer1.Layer1ApiDataProvider
formatPriceMethods inherited from interface velox.api.layer1.Layer1ApiInstrumentProvider
subscribe, subscribe, unsubscribeMethods inherited from interface velox.api.layer1.Layer1ApiTradingProvider
sendOrder, updateOrder
-
Field Details
-
adminListeners
-
instrumentListeners
-
dataListeners
-
mboDataListeners
-
tradingListeners
-
-
Constructor Details
-
ExternalLiveBaseProvider
public ExternalLiveBaseProvider()
-
-
Method Details
-
formatPriceDefault
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:
-
sendUserMessage
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
-