In RandomTime, there is some time comparison functionality that, when used,
may read something like:
Code:
if (isLaterThan(t0, t1))
;
but might read better:
Code:
if (t0.isLaterThan(t1))
;
Also, an oversight: there are two points in RandomBot where, if 'inMillis' or
'outMillis' are less than zero, logger.fatal is called. An object should
be "return"ed at that point; there are enums that support doing that, in
Return.java.
As for events: some that may occur after an order has been submitted have been
identified. There are also some that have to do with various connections that
need to be considered: tws<->ib and each data farm. For each of these, I am
thinking that they have three states: unknown, up and down. There are
error(int,int,String) events that could be used to keep the state of these
connections up to date. The initial state of the tws<->ib connection isn't
clear at this time, and when it moves from the "down" to "up" states there
are two possibilities to consider: "data lost" and "data preserved."
What will happen for events is this: a blocking queue will be used, which
permits waiting for an event with a timeout. So, instead of sleeping for
the entry time, the bot would do something like:
Code:
set time-to-wait-value
while (true) {
wait-for-any-event-with-time-to-wait-value
if timeout-has-occurred
break-the-loop
else if state-of-a-connection-has-changed
update-state-of-that-connection
else
; // more to be considered
update time-to-wait-value
}
if state-of-tws<->ib is UP
place-order
else
; // don't place order
This must be thought about some more, especially whether "event"s would work
with a bot that subscribes to data. I am thinking that because
IB doesn't backfill tick data (only bars?), that "event"s will work
for tickers, too. That is interesting, because although I've heard
of people waiting for a bar/candle to form before trading, that isn't
the way I trade. I trade when the price is right, which isn't likely
to coincide with the complete formation of a bar/candle.
(A lack of backfill on the tick data would require a bot to deal with discontinuites in the data;
trading with bars/candles is discontinuous, too, but they can be backfilled when a data farm goes down (?).
Tick "event"s might be expensive.)