Repository navigation
Broker
The abstract Broker implements functionality used to execute trade signals. This will be done in a way that supports asynchronous/threaded programming. (For instance, a thread may need to wait until it is time to run the next trade signal.) That being said, this will need to be done carefully; the only method to override will be the one that executes on trade signals.
async push_signal(SignalDto): None will be awaited until the signal has been processed and submitted to the Broker for handling. SignalDto was defined in the IModel wiki page. This method is synchronized.
async get_next_signal(None): Signal will be awaited until its earliest trade signal is elapsed. See more details about the Signal class below; it is different than SignalDto. This method is synchronized.
async execute_next_signal(None): TradeDto will be awaited until the broker has successfully processed the trade. Its output, defined below, will contain the actual details of the investment. This method is not implemented by the base Broker. The synchronized get_next_signal method should be used to retrieve the next signal in order to prevent race conditions or corruption of data.
| TradeDto |
|---|
| ticker: str amount: int action: Action contract: Contract time: datetime value: Decimal |
Action and Contract are enumerations defined in the IModel wiki page. You may notice that TradeDto and SignalDto are very similar; however, we choose not to have them inherit from one another, as they represent fundamentally different things (a request and a response). As such, they may change at different times, for different reasons.
Tracking of these values is the responsibility of the calling software. The Broker can, but should not, keep track of such things, as that is not what the broker is for.
The Broker maintains a priority queue of Signal entities which are, again, very similar to SignalDto with slightly different behaviors. Mainly, Signal can be compared via relational operators (and maybe more later). This, most importantly, ensures that SignalDto remains a simple data transfer object, and that Signal can be internally organized.
| Signal |
|---|
| ticker: str amount: int action: Action contract: Contract time: datetime |
| __lt__(Signal): bool |
According to the Python docs, an object only needs to implement the < operator to be sorted, so we do not need to worry about the others.