Class Layer1ApiInjectorRelay
- 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:
Layer1ApiStrategiesEchoMessagesLayer
Upstream events passing through this relay are synchronized on upstreamInjectorLock.
Async injected messages are also synchronized on it.
Therefore, the above layer sees all coming events synchronized as a single stream.
Threading. An injected runnable must not wait for processing happening for other messages. Also, upstream messages should not send downstream messages in the same thread or block on them.
-
Nested Class Summary
Nested classes/interfaces inherited from interface velox.api.layer1.layers.Layer1ApiTimeSource
Layer1ApiTimeSource.Layer1TimeSourceShortcutAllowed -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ObjectSerializes pass-through events with injected ones.Fields inherited from class velox.api.layer1.layers.Layer1ApiRelay
providerFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the chain below and stops the injector thread.protected voidInject runnable into upstream.protected voidInject runnable into messages stream provider -> gui from the same thread.voidonBalance(BalanceInfo balanceInfo) Called when account balance information changesvoidonConnectionLost(DisconnectionReason reason, String message) Connection to server lost.voidConnection to server restored.voidDepth data update.voidonInstrumentAdded(String alias, InstrumentInfo instrumentInfo) Indicates successful subscription to the instrumentvoidonInstrumentAlreadySubscribed(String symbol, String exchange, String type) Indicates that attempt to subscribe failed because subscription is already activevoidonInstrumentNotFound(String symbol, String exchange, String type) Indicates that attempt to subscribe failed because instrument does not existvoidonInstrumentRemoved(String alias) Unsubscribed from instrument (user-initiated or provider initiated).
Please note that if you use this in strategy that implementsOnlineCalculatable, you should not delete any data about instrument that is expected inOnlineCalculatable.calculateValuesInRange(String, String, long, long, int, velox.api.layer1.layers.strategies.interfaces.CalculatedResultListener)orOnlineCalculatable.createOnlineValueCalculator(String, String, long, java.util.function.Consumer, velox.api.layer1.layers.strategies.interfaces.InvalidateInterface), or should handle absence of that data (in case you delete it) gracefully.voidonLoginFailed(LoginFailedReason reason, String message) Failed to log in with specified credentialsvoidSuccessful login.voidonMarketMode(String alias, MarketMode marketMode) Market mode update.voidonMboCancel(String alias, String orderId) An order left the book, whether canceled or fully executed.voidonMboReplace(String alias, String orderId, int price, int size) An existing order changed its price and/or size.voidA new order entered the book.voidonOrderExecuted(ExecutionInfo executionInfo) Called when one of our orders gets executedvoidonOrderUpdated(OrderInfoUpdate orderInfoUpdate) Called when order is updated (order creation is also considered an update).voidonStatus(StatusInfo statusInfo) Called when instrument status information changes (PnL, number of open orders, position, etc).voidonSystemTextMessage(String message, SystemTextMessageType messageType) Passes the message into Bookmap and shows it as a popup.voidTradevoidonUserMessage(Object data) Send an upstream event.protected voidDeprecated.Methods inherited from class velox.api.layer1.layers.Layer1ApiRelay
formatPrice, getCurrentTime, getSource, getSupportedFeatures, getTimeSource, login, sendOrder, sendUserMessage, setProvider, subscribe, toString, unsubscribe, updateOrderMethods 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.Layer1ApiDataListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiInstrumentListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiInstrumentProvider
subscribeMethods inherited from interface velox.api.layer1.Layer1ApiMboDataListenable
addListener, removeListenerMethods inherited from interface velox.api.layer1.Layer1ApiTradingListenable
addListener, removeListener
-
Field Details
-
upstreamInjectorLock
Serializes pass-through events with injected ones. Subclasses may use it to guard their own state.
-
-
Constructor Details
-
Layer1ApiInjectorRelay
-
-
Method Details
-
inject
Inject runnable into upstream. Event is handled asynchronously on a dedicated executor. If you need to inject event synchronously and/or from the same thread - useinjectSynchronously(Runnable)instead. Runnables injected afterclose()are silently dropped. -
injectSynchronously
Inject runnable into messages stream provider -> gui from the same thread. Blocks until it finishes. Be careful when using this method, it's easy to cause a deadlock. If in doubt - useinject(Runnable)instead. -
safeInject
Deprecated.Inject runnable into upstream. If exception happens, this method will log it, but won't crash the application (this was a behavior that appeared by accident). Useinject(Runnable)instead.- Throws:
RejectedExecutionException
-
close
public void close()Closes the chain below and stops the injector thread. Runnables already queued still run.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLayer1ApiAdminProvider- Overrides:
closein classLayer1ApiRelay
-
onInstrumentAdded
Description copied from interface:Layer1ApiInstrumentListenerIndicates successful subscription to the instrument- Specified by:
onInstrumentAddedin interfaceLayer1ApiInstrumentListener- Overrides:
onInstrumentAddedin classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasinstrumentInfo- instrument specifications
-
onInstrumentRemoved
Description copied from interface:Layer1ApiInstrumentListenerUnsubscribed from instrument (user-initiated or provider initiated).
Please note that if you use this in strategy that implementsOnlineCalculatable, you should not delete any data about instrument that is expected inOnlineCalculatable.calculateValuesInRange(String, String, long, long, int, velox.api.layer1.layers.strategies.interfaces.CalculatedResultListener)orOnlineCalculatable.createOnlineValueCalculator(String, String, long, java.util.function.Consumer, velox.api.layer1.layers.strategies.interfaces.InvalidateInterface), or should handle absence of that data (in case you delete it) gracefully. The reason is that you can getLayer1ApiInstrumentListener.onInstrumentRemoved(String)in the middle ofOnlineCalculatablerequest- Specified by:
onInstrumentRemovedin interfaceLayer1ApiInstrumentListener- Overrides:
onInstrumentRemovedin classLayer1ApiUpstreamRelay- Parameters:
alias-
-
onInstrumentNotFound
Description copied from interface:Layer1ApiInstrumentListenerIndicates that attempt to subscribe failed because instrument does not exist- Specified by:
onInstrumentNotFoundin interfaceLayer1ApiInstrumentListener- Overrides:
onInstrumentNotFoundin classLayer1ApiUpstreamRelay- Parameters:
symbol-exchange-type- seeInstrumentCoreInfo.type
-
onInstrumentAlreadySubscribed
Description copied from interface:Layer1ApiInstrumentListenerIndicates that attempt to subscribe failed because subscription is already active- Specified by:
onInstrumentAlreadySubscribedin interfaceLayer1ApiInstrumentListener- Overrides:
onInstrumentAlreadySubscribedin classLayer1ApiUpstreamRelay- Parameters:
symbol-exchange-type- seeInstrumentCoreInfo.type
-
onTrade
Description copied from interface:Layer1ApiDataListenerTrade- Specified by:
onTradein interfaceLayer1ApiDataListener- Overrides:
onTradein classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasprice- price in the same units as in depth update (e.g. if pips=25 then price=1000 means 25000).size- trade sizetradeInfo- additional information about the trade, e.g. aggressor side and whether it is an OTC trade
-
onDepth
Description copied from interface:Layer1ApiDataListenerDepth data update. This is an absolute update, not a delta: the size becomes the total size at that price level. A size of 0 removes the level from the book. Bookmap sends the full initial book as a sequence of these calls afterLayer1ApiInstrumentListener.onInstrumentAdded(java.lang.String, velox.api.layer1.data.InstrumentInfo).- Specified by:
onDepthin interfaceLayer1ApiDataListener- Overrides:
onDepthin classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasisBid- true if it is for bids, false for asksprice- price where size changed, in tickssize- new total size at the level, 0 to remove the level
-
onMboSend
Description copied from interface:Layer1ApiMboDataListenerA new order entered the book.- Specified by:
onMboSendin interfaceLayer1ApiMboDataListener- Overrides:
onMboSendin classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasorderId- id of the order, unique within the instrumentisBid- true for a bid, false for an askprice- price in tickssize- order size
-
onMboReplace
Description copied from interface:Layer1ApiMboDataListenerAn existing order changed its price and/or size. The side never changes. Bookmap keeps the order's queue position only when the price is unchanged and the size decreased. Any other change moves the order to the back of the queue at the new price.- Specified by:
onMboReplacein interfaceLayer1ApiMboDataListener- Overrides:
onMboReplacein classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasorderId- id of an order previously reported byLayer1ApiMboDataListener.onMboSend(String, String, boolean, int, int)price- new price in ticks (may equal the old one)size- new size (may equal the old one)
-
onMboCancel
Description copied from interface:Layer1ApiMboDataListenerAn order left the book, whether canceled or fully executed. No further events for this id will follow unless it is re-sent.- Specified by:
onMboCancelin interfaceLayer1ApiMboDataListener- Overrides:
onMboCancelin classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasorderId- id of the removed order
-
onMarketMode
Description copied from interface:Layer1ApiDataListenerMarket mode update. Only sent when the mode changes, so most instruments receive it rarely or never.- Specified by:
onMarketModein interfaceLayer1ApiDataListener- Overrides:
onMarketModein classLayer1ApiUpstreamRelay- Parameters:
alias- instrument aliasmarketMode- new mode
-
onOrderUpdated
Description copied from interface:Layer1ApiTradingListenerCalled when order is updated (order creation is also considered an update).- Specified by:
onOrderUpdatedin interfaceLayer1ApiTradingListener- Overrides:
onOrderUpdatedin classLayer1ApiUpstreamRelay- Parameters:
orderInfoUpdate- information about update
-
onOrderExecuted
Description copied from interface:Layer1ApiTradingListenerCalled when one of our orders gets executed- Specified by:
onOrderExecutedin interfaceLayer1ApiTradingListener- Overrides:
onOrderExecutedin classLayer1ApiUpstreamRelay- Parameters:
executionInfo- information about execution
-
onStatus
Description copied from interface:Layer1ApiTradingListenerCalled when instrument status information changes (PnL, number of open orders, position, etc).- Specified by:
onStatusin interfaceLayer1ApiTradingListener- Overrides:
onStatusin classLayer1ApiUpstreamRelay- Parameters:
statusInfo- status information
-
onBalance
Description copied from interface:Layer1ApiTradingListenerCalled when account balance information changes- Specified by:
onBalancein interfaceLayer1ApiTradingListener- Overrides:
onBalancein classLayer1ApiUpstreamRelay- Parameters:
balanceInfo- account balance information
-
onLoginFailed
Description copied from interface:Layer1ApiAdminListenerFailed to log in with specified credentials- Specified by:
onLoginFailedin interfaceLayer1ApiAdminListener- Overrides:
onLoginFailedin classLayer1ApiUpstreamRelay- Parameters:
reason- Reason codemessage- test message associated with login fail
-
onLoginSuccessful
public void onLoginSuccessful()Description copied from interface:Layer1ApiAdminListenerSuccessful login.- Specified by:
onLoginSuccessfulin interfaceLayer1ApiAdminListener- Overrides:
onLoginSuccessfulin classLayer1ApiUpstreamRelay
-
onConnectionLost
Description copied from interface:Layer1ApiAdminListenerConnection to server lost. Provider can call this method multiple times in sequence if the reason was changed (i.e. fromDisconnectionReason.NO_INTERNETtoDisconnectionReason.FATAL)- Specified by:
onConnectionLostin interfaceLayer1ApiAdminListener- Overrides:
onConnectionLostin classLayer1ApiUpstreamRelay- Parameters:
reason- Reason codemessage- text message associated with login disconnection
-
onConnectionRestored
public void onConnectionRestored()Description copied from interface:Layer1ApiAdminListenerConnection to server restored. A provider should call it only if it previously invokedLayer1ApiAdminListener.onConnectionLost(DisconnectionReason, String)- Specified by:
onConnectionRestoredin interfaceLayer1ApiAdminListener- Overrides:
onConnectionRestoredin classLayer1ApiUpstreamRelay
-
onSystemTextMessage
Description copied from interface:Layer1ApiAdminListenerPasses the message into Bookmap and shows it as a popup. It is suitable for 1-time notifications, but for the general case take a look at the notifications API -Layer1ApiSoundAlertMessage- Specified by:
onSystemTextMessagein interfaceLayer1ApiAdminListener- Overrides:
onSystemTextMessagein classLayer1ApiUpstreamRelay- Parameters:
message- message itselfmessageType- message type- See Also:
-
onUserMessage
Description copied from class:Layer1ApiUpstreamRelaySend an upstream event. Allows incorporating arbitrary functionality into protocol.This is the extension point of the upstream direction: any layer or the provider may emit an arbitrary object, and it travels towards the GUI through every layer above the origin. The counterpart for the downstream direction is
Layer1ApiAdminProvider.sendUserMessage(Object).Contract for layers: inspect the message by type, act on the ones you understand and pass every other message on unchanged. Swallowing an unknown message breaks layers above you.
Messages emitted by Bookmap use classes from
velox.api.layer1.messages. Some of them are sent in response to a downstream request and arrive asynchronously, after the correspondingsendUserMessagecall has already returned.For a
SelectAccountMessagearriving afterLayer1ApiUpstreamRelay.close(), selected index is set to 0 instead of dropping the message. Thus, provider thread blocked inSelectAccountMessage.get()does not hang forever.- Specified by:
onUserMessagein interfaceLayer1ApiAdminListener- Overrides:
onUserMessagein classLayer1ApiUpstreamRelay- Parameters:
data- Message content, never null
-