Common Ember API Questions
Supported Programming Languages
The Execution Server (ES) uses Java for all user-programmable components, such as algorithms, connectors, callbacks, and so on. All these components running inside the Execution Server must be written in Java. External clients can use Java, REST/WS, or FIX APIs to interact with the Execution Server.
Deltix has other solutions that support C#, C++, and Python, and can interoperate with the Execution Server.
"Publication is closed due timeout" Error
If you are debugging an issue and get a "publication is closed due to timeout" error, it essentially kills the Ember process. There is a workaround.
When setting a breakpoint in the code, edit the Breakpoint Properties:
- Select Suspend > Thread > Make Default.
This keeps the Aeron Heartbeat thread running in the background while you stopped in debugger on breakpoint.
compilation failed
Error while Running Ember Apps under IntelliJ/IDEA
Issue: I see the following or similar compilation failed
error while running Ember apps from IDEA:
ERROR [main] Error compiling type "deltix.timebase.api.messages.calendar.CalendarMessage" bound to deltix.timebase.api.messages.calendar.CalendarMessage: compilation failed: /CalendarMessageBOUND_DECODER1.java:2: error: package deltix.qsrv.hf.pub.codec does not exist public final class CalendarMessageBOUND_DECODER1 implements deltix.qsrv.hf.pub.codec.BoundDecoder, deltix.qsrv.hf.pub.codec.CharSequenceDecoder { ...
This error comes from the TimeBase client code as it tries to compile codecs for the stream you are trying to read. This happens when the compiler sees an incorrect CLASSPATH
.
Workaround options:
- Switch the IDEA runner to a different command line shortening method.
- In .idea/workspace.xml, add
<property name="dynamic.classpath" value="true" />
to<component name="PropertiesComponent">
.
How Do I Set a Custom Order Attribute?
To set a single custom order attribute, follow this code snippet:
private final ReusableCustomAttribute attr = new ReusableCustomAttribute();
/// then something like this:
private void transform(MutableOrderRequest request) {
if (request.getAttributes() != null) {
attr.clear();
attr.setKey(OnBehalfOfCompID);
attr.setValueAsAlphanumeric(request.getSourceId());
((ObjectArrayList)request.getAttributes()).add(attr);
} else {
ObjectList<CustomAttribute> customAttributes = attrBuilder
.clear()
.addText(OnBehalfOfCompID, buffer
.clear()
.appendAlphanumeric(request.getSourceId()))
.build();
request.setAttributes(customAttributes);
}
}
Alternatively, if you need to set multiple custom attributes in an allocation-free manner, use this approach:
private final CustomAttributeListBuilder customAttributesBuilder = new CustomAttributeListBuilder();
request.setAttributes(customAttributesBuilder
.clear()
.addEnum(MyOrderEntryReq.REASON_CUSTOM_ATTRIBUTE_TAG, reason);
.addInteger(Tag.ExecInst, ExecInst.DO_NOT_REDUCE)
.build());
Why Am I Getting a NullPointerException When Setting a Custom Order Request Attribute?
Issue: I am trying to set a custom order request attribute and getting a NullPointerException (NPE):
((ObjectArrayList)request.getAttributes()).add(myAttribute);
In many cases, you don't need custom attributes in a request. By default, when you create a new instance, the MutableOrderNewRequest.attributes
field is NULL
.
To append a custom attribute, you need to initialize it:
ObjectArrayList attributes = (ObjectArrayList) request.getAttributes();
if (attributes == null)
request.setAttributes(attributes = new ObjectArrayList());
MutableCustomAttribute attribute = new MutableCustomAttribute();
attribute.setKey(6021);
attribute.setValue("BEST");
attributes.add(attribute);
To prepare and submit all your algorithm orders, use single instances of MutabeOrderNewRequest
and pre-initialize the attributes list:
private final MutabeOrderNewRequest request = new MutableOrderNewRequest();
private final ObjectArrayList attributes = new ObjectArrayList ();
{
request.setAttributes(attributes);
}
This way, when you submit each order request, you just need to make sure the attributes list contains all the intended attributes.
What happens to the Ember (and specifically with MessageChannel) when the TimeBase is restarted?
When it comes to reading and writing data to TimeBase Ember API offers narrow wrapper over TimeBase. Algorithm MessageChannel output channels are mapped to TickLoader objects of TimeBase API, wrapped into AutoRecoveringLoader
. When this wrapper detects that TimeBase is disconnect it will step sending data to underlying tick loader. When connection to TimeBase is restored, auto-recovering loader will auto-create underlying TickLoader and continue work normally. There is a high chance that message written from the moment connection to TimeBase was lost will be lost.
Ember lost connection to exchange (server crashed). How fills for active orders are recovered?
Full question: Imagine a scenario:
- Algorithm sent to exchange some orders.
- Ember server was shutdown (or crashed) immediately after that.
- Order was executed on exchange.
Can we get information about executions after Ember startup?
Answer: Protocol is the following:
- Ember replays journal on startup. State of algorithm is restored, including information about recently placed orders (they are in active state as far as restored history is concerned)
- Ember finishes startup and sends “I am switching to live mode” event. When a Trade Connector receives this event it establishes connectivity with exchange, and sends “I am connected” event to Ember OMS.
- Some FIX based Trade Connectors receive missed fills at this point and send them to Ember OMS.
- Ember OMS reacts to exchange re-connection by issuing OrderStatusRequest for each active order (including restored active orders we mentioned)
- Trade Connector recovers state of each active order by issuing order status requests to exchange, if necessary. In response we should receive information about cumulative fills size and average executed price for each order. Connector reports these to OMS.
How to find out parameters of rejected OrderReplaceRequest?
Question related with replace request -> replace reject event.
Scenario:
- Algorithm sends ReplaceOrderRequest to exchange (current qty 3 -> new QTY 8)
- Algorithm receives OrderReplaceRejectEvent(ChildOrder order, OrderReplaceRejectEvent event) {
Is there legal way to know from OrderReplaceRejectEvent or Order what the new quantity (QTY 8) should have been? In general, I want to get a difference - 5 qty.
Answer: Order has a linked list of OrderEntry objects representing multiple order modifications.
When you receive
public boolean onOrderReplaceReject(Order order, OrderReplaceRejectEvent event)
event callback, the reject event is already applied. So Order.getWorkingOrder() returns the last order accepted by exchange (3 in your case). However, Order.getWorkingOrder().getNext() should point to just rejected order.
Accessing next entry to see OrderReplaceRequest parameter is only possible while you are in order reject event callback. Subsequent order replace requests will affect order entries linked list.