Class Layer1ApiRelay
- All Implemented Interfaces:
AutoCloseable,Layer1ApiAdminListenable,Layer1ApiAdminListener,Layer1ApiAdminProvider,Layer1ApiDataListenable,Layer1ApiDataListener,Layer1ApiDataProvider,Layer1ApiInstrumentListenable,Layer1ApiInstrumentListener,Layer1ApiInstrumentProvider,Layer1ApiListener,Layer1ApiMboDataListenable,Layer1ApiMboDataListener,Layer1ApiProvider,Layer1ApiTradingListenable,Layer1ApiTradingListener,Layer1ApiTradingProvider,LayerApiListenable,Layer1ApiTimeSource
- Direct Known Subclasses:
Layer1ApiDepthFreezer,Layer1ApiInjectorRelay
A relay is one link of the layer chain: every downstream command is forwarded to provider - the layer
below. Every received upstream message is forwarded to this relay's own listeners, the layer above.
Subclasses override only the calls they care about and call super for the rest, so a message a layer does
not understand keeps flowing to the next layer.
The public constructor wires up this relay with provider for all upstream listener types. Subclasses
that must finish their own initialization first must use the protected constructor with false,
and subscribe themselves afterward.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface velox.api.layer1.layers.Layer1ApiTimeSource
Layer1ApiTimeSource.Layer1TimeSourceShortcutAllowed -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Layer1ApiProviderDo not change it directly, usesetProvider(Layer1ApiProvider).Fields inherited from class velox.api.layer1.layers.Layer1ApiUpstreamRelay
closedFields inherited from class velox.api.layer1.Layer1ApiBasicListenable
adminListeners, dataListeners, instrumentListeners, mboDataListeners, theOnlyAdminListener, theOnlyDataListener, theOnlyInstrumentListener, theOnlyMboDataListener, theOnlyTradingListener, tradingListeners -
Constructor Summary
ConstructorsModifierConstructorDescriptionLayer1ApiRelay(Layer1ApiProvider provider) Wires up this relay withproviderfor all upstream listener types.protectedLayer1ApiRelay(Layer1ApiProvider provider, boolean subscribeToProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the layer below first, then stops relaying events upward.formatPrice(String alias, double price) Format price using platform capabilities if possible.longReturns current Unix epoch time.Returns string representing data source.Get information about features that are supported by a provider.Delegates the lookup to the layer below, which makes this relay transparent to the time shortcut.voidInitiate login to the platform.voidsendOrder(OrderSendParameters orderSendParameters) Submit order with specified parameters.sendUserMessage(Object data) Send a downstream event.protected voidsetProvider(Layer1ApiProvider provider) Replaces the layer below and re-resolves the time source.voidsubscribe(SubscribeInfo subscribeInfo) Subscribe to specified instrument.toString()voidunsubscribe(String alias) Unsubscribe from the instrument.voidupdateOrder(OrderUpdateParameters orderUpdateParameters) Update order according to parameters.Methods inherited from class velox.api.layer1.layers.Layer1ApiUpstreamRelay
onBalance, onConnectionLost, onConnectionRestored, onDepth, onInstrumentAdded, onInstrumentAlreadySubscribed, onInstrumentNotFound, onInstrumentRemoved, onLoginFailed, onLoginSuccessful, onMarketMode, onMboCancel, onMboReplace, onMboSend, onOrderExecuted, onOrderUpdated, onStatus, onSystemTextMessage, onTrade, onUserMessageMethods inherited from class velox.api.layer1.Layer1ApiBasicListenable
addListener, addListener, addListener, addListener, addListener, getAdminListenerBroadcaster, getDataListenerBroadcaster, getInstrumentListenerBroadcaster, getTradingListenerBroadcaster, getUniqueListenersCount, onNoSubscribers, removeListener, removeListener, removeListener, removeListener, removeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface velox.api.layer1.Layer1ApiAdminListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiAdminListener
onConnectionLost, onConnectionRestored, onLoginFailed, onLoginSuccessful, onSystemTextMessage, onUserMessageMethods inherited from interface velox.api.layer1.Layer1ApiDataListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiDataListener
onDepth, onMarketMode, onTradeMethods inherited from interface velox.api.layer1.Layer1ApiInstrumentListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiInstrumentListener
onInstrumentAdded, onInstrumentAlreadySubscribed, onInstrumentNotFound, onInstrumentRemovedMethods inherited from interface velox.api.layer1.Layer1ApiInstrumentProvider
subscribeMethods inherited from interface velox.api.layer1.Layer1ApiMboDataListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiMboDataListener
onMboCancel, onMboReplace, onMboSendMethods inherited from interface velox.api.layer1.Layer1ApiTradingListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiTradingListener
onBalance, onOrderExecuted, onOrderUpdated, onStatus
-
Field Details
-
provider
Do not change it directly, usesetProvider(Layer1ApiProvider). And don't do that unless you really need to.
-
-
Constructor Details
-
Layer1ApiRelay
Wires up this relay withproviderfor all upstream listener types. -
Layer1ApiRelay
- Parameters:
subscribeToProvider- false to skip registering this relay as a listener ofprovider. The subclass is then responsible for subscribing, throughListenableHelper.addListeners(Object, Object).
-
-
Method Details
-
setProvider
Replaces the layer below and re-resolves the time source. Listener registrations are not touched: the caller must unsubscribe from the old provider and subscribe to the new one itself. If you use this method you must implementgetCurrentTime()so time shortcut is not applied. -
formatPrice
Description copied from interface:Layer1ApiDataProviderFormat price using platform capabilities if possible. Layers forward this to the data adapter; when the adapter returns null Bookmap falls back to its default formatter based on the instrument's pips.- Specified by:
formatPricein interfaceLayer1ApiDataProvider- Parameters:
alias- instrument aliasprice- real price (not in ticks)- Returns:
- human-readable price, or null if this provider has no platform-specific formatting for the instrument
-
subscribe
Description copied from interface:Layer1ApiInstrumentProviderSubscribe to specified instrument. Some parameters can be null depending on the platform.The call only initiates the subscription; the outcome is reported asynchronously through
Layer1ApiInstrumentListener: exactly one ofLayer1ApiInstrumentListener.onInstrumentAdded(String, InstrumentInfo),Layer1ApiInstrumentListener.onInstrumentNotFound(String, String, String)orLayer1ApiInstrumentListener.onInstrumentAlreadySubscribed(String, String, String)follows. The alias that identifies the instrument in all later callbacks and commands is assigned by Bookmap and delivered inonInstrumentAdded; do not derive it from the subscribe parameters.- Specified by:
subscribein interfaceLayer1ApiInstrumentProvider- Parameters:
subscribeInfo- has fields similar toInstrumentCoreInfo
-
unsubscribe
Description copied from interface:Layer1ApiInstrumentProviderUnsubscribe from the instrument. Confirmed asynchronously byLayer1ApiInstrumentListener.onInstrumentRemoved(String). Data for the alias may still arrive until that callback.- Specified by:
unsubscribein interfaceLayer1ApiInstrumentProvider- Parameters:
alias- instrument alias originating fromLayer1ApiInstrumentListener.onInstrumentAdded(String, InstrumentInfo)
-
sendOrder
Description copied from interface:Layer1ApiTradingProviderSubmit order with specified parameters.Fire-and-forget: the result arrives asynchronously through
Layer1ApiTradingListener. Acceptance and later state changes come asLayer1ApiTradingListener.onOrderUpdated(velox.api.layer1.data.OrderInfoUpdate), a rejection as the same callback with statusOrderStatus.REJECTED, fills asLayer1ApiTradingListener.onOrderExecuted(velox.api.layer1.data.ExecutionInfo). Order types the connected platform does not support natively (OCO, OSO, brackets, trailing stops) are emulated by Bookmap layers below the caller, so the caller sees the same callbacks either way.- Specified by:
sendOrderin interfaceLayer1ApiTradingProvider- Parameters:
orderSendParameters- parameters
-
updateOrder
Description copied from interface:Layer1ApiTradingProviderUpdate order according to parameters. The kind of update is determined by the concrete class of the argument: cancel, move, move to market or resize (see the subclasses ofOrderUpdateParameters). LikeLayer1ApiTradingProvider.sendOrder(OrderSendParameters), the call returns immediately and the outcome is reported throughLayer1ApiTradingListener.onOrderUpdated(velox.api.layer1.data.OrderInfoUpdate).- Specified by:
updateOrderin interfaceLayer1ApiTradingProvider- Parameters:
orderUpdateParameters- parameters
-
login
Description copied from interface:Layer1ApiAdminProviderInitiate login to the platform.- Specified by:
loginin interfaceLayer1ApiAdminProvider- Parameters:
loginData- credentials, different platforms use different subclasses
-
getCurrentTime
public long getCurrentTime()Description copied from interface:Layer1ApiAdminProviderReturns current Unix epoch time. This method allows time distortions if consumer is too slow - in this case time of the next event may be returned.- Specified by:
getCurrentTimein interfaceLayer1ApiAdminProvider- Returns:
- current Unix epoch time in nanoseconds
-
close
public void close()Closes the layer below first, then stops relaying events upward.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLayer1ApiAdminProvider- Overrides:
closein classLayer1ApiUpstreamRelay
-
getSource
Description copied from interface:Layer1ApiAdminProviderReturns string representing data source.- Specified by:
getSourcein interfaceLayer1ApiAdminProvider- Returns:
- string representing data source
-
sendUserMessage
Description copied from interface:Layer1ApiAdminProviderSend a downstream event. Allows incorporating arbitrary functionality into protocol.This is the extension point of the downstream direction: the caller hands an arbitrary object to the layer below, which either handles it or passes it further down. The counterpart for the upstream direction is
Layer1ApiAdminListener.onUserMessage(Object).The call is synchronously propagated downstream. It must eventually be consumed by a layer, that will stop propagation and return the result back upwards. Layers are also allowed to alter it without consuming. Layers that do not recognize a message must forward it unchanged (see
Layer1ApiRelay). Messages that implementLayer1ApiIgnorableDownwardMessagemay reach the bottom of the stack unhandled. All others throw if unhandled.Some messages are requests whose reply is not the return value but an upstream
onUserMessagethat arrives later, possibly after this method has returned.- Specified by:
sendUserMessagein interfaceLayer1ApiAdminProvider- Parameters:
data- Message content, never null- Returns:
- response of the handling layer, or null if the message has no synchronous response or nobody handled it
-
getSupportedFeatures
Description copied from interface:Layer1ApiAdminProviderGet information about features that are supported by a provider. Note that some fields might be set differently depending on when request is made. E.g. adapter might not know if trading will be there until login actually happens.
If you are writing a provider - take a look at
MaximumSupportedFeaturesas a way to declare full list of capabilities before being instantiated- Specified by:
getSupportedFeaturesin interfaceLayer1ApiAdminProvider- Returns:
- object describing supported features
- See Also:
-
getTimeSource
Delegates the lookup to the layer below, which makes this relay transparent to the time shortcut.- Specified by:
getTimeSourcein interfaceLayer1ApiTimeSource
-
toString
-