Skip to content

Commit d84bcf7

Browse files
authored
Merge pull request #438 from pikers/msgspec_ordering
Msgspec field ordering
2 parents f218b80 + 0474d66 commit d84bcf7

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

piker/clearing/_allocate.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
class Allocator(Struct):
4444

4545
symbol: Symbol
46+
47+
# TODO: if we ever want ot support non-uniform entry-slot-proportion
48+
# "sizes"
49+
# disti_weight: str = 'uniform'
50+
51+
units_limit: float
52+
currency_limit: float
53+
slots: int
4654
account: Optional[str] = 'paper'
4755

4856
_size_units: bidict[str, Optional[str]] = _size_units
@@ -66,14 +74,6 @@ def size_unit(self, v: str) -> Optional[str]:
6674
self._size_unit = v
6775
return v
6876

69-
# TODO: if we ever want ot support non-uniform entry-slot-proportion
70-
# "sizes"
71-
# disti_weight: str = 'uniform'
72-
73-
units_limit: float
74-
currency_limit: float
75-
slots: int
76-
7777
def step_sizes(
7878
self,
7979
) -> (float, float):

piker/clearing/_messages.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class Cancel(Struct):
107107
broker-submitted (live) trigger/order.
108108
109109
'''
110-
action: str = 'cancel'
111110
oid: str # uuid4
112111
symbol: str
112+
action: str = 'cancel'
113113

114114

115115
# --------------
@@ -120,7 +120,6 @@ class Cancel(Struct):
120120

121121
class Status(Struct):
122122

123-
name: str = 'status'
124123
time_ns: int
125124
oid: str # uuid4 ems-order dialog id
126125

@@ -135,6 +134,8 @@ class Status(Struct):
135134
'error',
136135
]
137136

137+
name: str = 'status'
138+
138139
# this maps normally to the ``BrokerdOrder.reqid`` below, an id
139140
# normally allocated internally by the backend broker routing system
140141
reqid: Optional[int | str] = None
@@ -168,7 +169,6 @@ class Status(Struct):
168169

169170
class BrokerdCancel(Struct):
170171

171-
action: str = 'cancel'
172172
oid: str # piker emsd order id
173173
time_ns: int
174174

@@ -180,6 +180,7 @@ class BrokerdCancel(Struct):
180180
# on the emsd order request stream as the ``BrokerdOrderAck.reqid``
181181
# field
182182
reqid: Optional[int | str] = None
183+
action: str = 'cancel'
183184

184185

185186
class BrokerdOrder(Struct):
@@ -188,6 +189,10 @@ class BrokerdOrder(Struct):
188189
account: str
189190
time_ns: int
190191

192+
symbol: str # fqsn
193+
price: float
194+
size: float
195+
191196
# TODO: if we instead rely on a +ve/-ve size to determine
192197
# the action we more or less don't need this field right?
193198
action: str = '' # {buy, sell}
@@ -200,10 +205,6 @@ class BrokerdOrder(Struct):
200205
# field
201206
reqid: Optional[int | str] = None
202207

203-
symbol: str # fqsn
204-
price: float
205-
size: float
206-
207208

208209
# ---------------
209210
# emsd <- brokerd
@@ -218,19 +219,18 @@ class BrokerdOrderAck(Struct):
218219
``.oid`` (which is a uuid4).
219220
220221
'''
221-
name: str = 'ack'
222222

223223
# defined and provided by backend
224224
reqid: int | str
225225

226226
# emsd id originally sent in matching request msg
227227
oid: str
228228
account: str = ''
229+
name: str = 'ack'
229230

230231

231232
class BrokerdStatus(Struct):
232233

233-
name: str = 'status'
234234
reqid: int | str
235235
time_ns: int
236236
status: Literal[
@@ -242,6 +242,7 @@ class BrokerdStatus(Struct):
242242
]
243243

244244
account: str
245+
name: str = 'status'
245246
filled: float = 0.0
246247
reason: str = ''
247248
remaining: float = 0.0
@@ -260,24 +261,22 @@ class BrokerdFill(Struct):
260261
if avaiable.
261262
262263
'''
263-
name: str = 'fill'
264+
# brokerd timestamp required for order mode arrow placement on x-axis
265+
# TODO: maybe int if we force ns?
266+
# we need to normalize this somehow since backends will use their
267+
# own format and likely across many disparate epoch clocks...
268+
broker_time: float
264269
reqid: int | str
265270
time_ns: int
266271

267272
# order exeuction related
268273
size: float
269274
price: float
270275

276+
name: str = 'fill'
271277
action: Optional[str] = None
272278
broker_details: dict = {} # meta-data (eg. commisions etc.)
273279

274-
# brokerd timestamp required for order mode arrow placement on x-axis
275-
276-
# TODO: maybe int if we force ns?
277-
# we need to normalize this somehow since backends will use their
278-
# own format and likely across many disparate epoch clocks...
279-
broker_time: float
280-
281280

282281
class BrokerdError(Struct):
283282
'''
@@ -286,27 +285,27 @@ class BrokerdError(Struct):
286285
This is still a TODO thing since we're not sure how to employ it yet.
287286
288287
'''
289-
name: str = 'error'
290288
oid: str
289+
symbol: str
290+
reason: str
291291

292292
# if no brokerd order request was actually submitted (eg. we errored
293293
# at the ``pikerd`` layer) then there will be ``reqid`` allocated.
294294
reqid: Optional[int | str] = None
295295

296-
symbol: str
297-
reason: str
296+
name: str = 'error'
298297
broker_details: dict = {}
299298

300299

301300
class BrokerdPosition(Struct):
302301
'''Position update event from brokerd.
303302
304303
'''
305-
name: str = 'position'
306304

307305
broker: str
308306
account: str
309307
symbol: str
310308
size: float
311309
avg_price: float
312310
currency: str = ''
311+
name: str = 'position'

piker/data/_web_bs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ async def open_autorecon_ws(
165165

166166

167167
class JSONRPCResult(Struct):
168-
jsonrpc: str = '2.0'
169168
id: int
169+
jsonrpc: str = '2.0'
170170
result: Optional[dict] = None
171171
error: Optional[dict] = None
172172

piker/ui/_flows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,14 @@ class Flow(msgspec.Struct): # , frozen=True):
338338
name: str
339339
plot: pg.PlotItem
340340
graphics: Union[Curve, BarItems]
341+
_shm: ShmArray
341342
yrange: tuple[float, float] = None
342343

343344
# in some cases a flow may want to change its
344345
# graphical "type" or, "form" when downsampling,
345346
# normally this is just a plain line.
346347
ds_graphics: Optional[Curve] = None
347348

348-
_shm: ShmArray
349349

350350
is_ohlc: bool = False
351351
render: bool = True # toggle for display loop

0 commit comments

Comments
 (0)