in simulator/src/main/java/com/google/cloud/JSONOutputConsumer.java [50:111]
private String convert(OrderBookEvent obe) {
String timestamp = sdf.format(new Date(obe.getTimestampMS()));
// Last message for all messages
if (obe.getLastMessage()) {
return String.format("{\"ts\":\"%s\",\"type\":\"last_message\",\"gseq\":%d}", obe.getSeqId());
}
// Last message for contract
if (obe.getLastContractMessage()) {
return String.format("{\"ts\":\"%s\",\"type\":\"last_contract_message\",\"gseq\":%d, \"contract\":%d, \"cseq\":%d}",
timestamp,
obe.getSeqId(),
obe.getContractId(),
obe.getContractSeqId()
);
}
// Order type
switch (obe.getType()) {
case NEW: {
return String.format("{\"ts\":\"%s\",\"type\":\"new_order\",\"gseq\":%d, \"contract\":%d, \"cseq\":%d, \"order_id\":%s, \"side\":\"%s\", \"remaining\":%d, \"price\":%d}",
timestamp,
obe.getSeqId(),
obe.getContractId(),
obe.getContractSeqId(),
obe.getOrderId(),
obe.getSide(),
obe.getQuantityRemaining(),
obe.getPrice()
);
}
case EXECUTED: {
return String.format("{\"ts\":\"%s\",\"type\":\"executed\",\"gseq\":%d, \"contract\":%d, \"cseq\":%d, \"order_id\":%s, \"side\":\"%s\", \"filled\":%d, \"price\":%d}",
timestamp,
obe.getSeqId(),
obe.getContractId(),
obe.getContractSeqId(),
obe.getOrderId(),
obe.getSide(),
obe.getQuantityFilled(),
obe.getPrice()
);
}
case DELETED: {
return String.format("{\"ts\":\"%s\",\"type\":\"cancelled\",\"gseq\":%d, \"contract\":%d, \"cseq\":%d, \"order_id\":%s, \"side\":\"%s\", \"remaining\":%d, \"price\":%d}",
timestamp,
obe.getSeqId(),
obe.getContractId(),
obe.getContractSeqId(),
obe.getOrderId(),
obe.getSide(),
obe.getQuantityRemaining(),
obe.getPrice()
);
}
default: {
return String.format("BROKEN: %s", obe.toString());
}
}
}