Update brokerd msgs with modern type annots, add a "closed" status

basic_buy_bot
Tyler Goodlet 2023-06-16 21:07:42 -04:00
parent f2c1988536
commit 77dfeb4bf2
1 changed files with 11 additions and 12 deletions

View File

@ -23,7 +23,6 @@ Clearing sub-system message and protocols.
# deque, # deque,
# ) # )
from typing import ( from typing import (
Optional,
Literal, Literal,
) )
@ -140,7 +139,7 @@ class Status(Struct):
# this maps normally to the ``BrokerdOrder.reqid`` below, an id # this maps normally to the ``BrokerdOrder.reqid`` below, an id
# normally allocated internally by the backend broker routing system # normally allocated internally by the backend broker routing system
reqid: Optional[int | str] = None reqid: int | str | None = None
# the (last) source order/request msg if provided # the (last) source order/request msg if provided
# (eg. the Order/Cancel which causes this msg) and # (eg. the Order/Cancel which causes this msg) and
@ -153,7 +152,7 @@ class Status(Struct):
# event that wasn't originated by piker's emsd (eg. some external # event that wasn't originated by piker's emsd (eg. some external
# trading system which does it's own order control but that you # trading system which does it's own order control but that you
# might want to "track" using piker UIs/systems). # might want to "track" using piker UIs/systems).
src: Optional[str] = None src: str | None = None
# set when a cancel request msg was set for this order flow dialog # set when a cancel request msg was set for this order flow dialog
# but the brokerd dialog isn't yet in a cancelled state. # but the brokerd dialog isn't yet in a cancelled state.
@ -181,7 +180,7 @@ class BrokerdCancel(Struct):
# for setting a unique order id then this value will be relayed back # for setting a unique order id then this value will be relayed back
# on the emsd order request stream as the ``BrokerdOrderAck.reqid`` # on the emsd order request stream as the ``BrokerdOrderAck.reqid``
# field # field
reqid: Optional[int | str] = None reqid: int | str | None = None
action: str = 'cancel' action: str = 'cancel'
@ -205,7 +204,7 @@ class BrokerdOrder(Struct):
# for setting a unique order id then this value will be relayed back # for setting a unique order id then this value will be relayed back
# on the emsd order request stream as the ``BrokerdOrderAck.reqid`` # on the emsd order request stream as the ``BrokerdOrderAck.reqid``
# field # field
reqid: Optional[int | str] = None reqid: int | str | None = None
# --------------- # ---------------
@ -233,14 +232,14 @@ class BrokerdOrderAck(Struct):
class BrokerdStatus(Struct): class BrokerdStatus(Struct):
reqid: int | str
time_ns: int time_ns: int
reqid: int | str
status: Literal[ status: Literal[
'open', 'open',
'canceled', 'canceled',
'fill',
'pending', 'pending',
'error', 'error',
'closed',
] ]
account: str account: str
@ -259,24 +258,24 @@ class BrokerdStatus(Struct):
class BrokerdFill(Struct): class BrokerdFill(Struct):
''' '''
A single message indicating a "fill-details" event from the broker A single message indicating a "fill-details" event from the
if avaiable. broker if avaiable.
''' '''
# brokerd timestamp required for order mode arrow placement on x-axis # brokerd timestamp required for order mode arrow placement on x-axis
# TODO: maybe int if we force ns? # TODO: maybe int if we force ns?
# we need to normalize this somehow since backends will use their # we need to normalize this somehow since backends will use their
# own format and likely across many disparate epoch clocks... # own format and likely across many disparate epoch clocks...
time_ns: int
broker_time: float broker_time: float
reqid: int | str reqid: int | str
time_ns: int
# order exeuction related # order exeuction related
size: float size: float
price: float price: float
name: str = 'fill' name: str = 'fill'
action: Optional[str] = None action: str | None = None
broker_details: dict = {} # meta-data (eg. commisions etc.) broker_details: dict = {} # meta-data (eg. commisions etc.)
@ -293,7 +292,7 @@ class BrokerdError(Struct):
# if no brokerd order request was actually submitted (eg. we errored # if no brokerd order request was actually submitted (eg. we errored
# at the ``pikerd`` layer) then there will be ``reqid`` allocated. # at the ``pikerd`` layer) then there will be ``reqid`` allocated.
reqid: Optional[int | str] = None reqid: int | str | None = None
name: str = 'error' name: str = 'error'
broker_details: dict = {} broker_details: dict = {}