Mk `Brokerd[Order].price` avoid `float`-errs
By re-typing to a `.price: Decimal` field on both legs of the EMS. It seems we must do it ourselves since, - these msg's (fields) are relayed through the clearing engine to each `brokerd` backend and, - bc many (if not all) of those backends `.broker`-clients (nor their encapsulated "brokerage services") **are not** doing any precision-truncation themselves. So, for now, instead we opt to expect rounding at the source. This means we will explicitly require casting to/from `float` at the line-graphics interface to the order-clearing-engine (as implemented throughout `.ui.order_mode.OrderMode`); and this is coming shortly.decimal_prices_thru_ems
							parent
							
								
									17aebf44a9
								
							
						
					
					
						commit
						ec71dc2018
					
				| 
						 | 
				
			
			@ -1182,12 +1182,16 @@ async def process_client_order_cmds(
 | 
			
		|||
    submitting live orders immediately if requested by the client.
 | 
			
		||||
 | 
			
		||||
    '''
 | 
			
		||||
    # cmd: dict
 | 
			
		||||
    # TODO, only allow `msgspec.Struct` form!
 | 
			
		||||
    cmd: dict
 | 
			
		||||
    async for cmd in client_order_stream:
 | 
			
		||||
        log.info(f'Received order cmd:\n{pformat(cmd)}')
 | 
			
		||||
        log.info(
 | 
			
		||||
            f'Received order cmd:\n'
 | 
			
		||||
            f'{pformat(cmd)}\n'
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        # CAWT DAMN we need struct support!
 | 
			
		||||
        oid = str(cmd['oid'])
 | 
			
		||||
        oid: str = str(cmd['oid'])
 | 
			
		||||
 | 
			
		||||
        # register this stream as an active order dialog (msg flow) for
 | 
			
		||||
        # this order id such that translated message from the brokerd
 | 
			
		||||
| 
						 | 
				
			
			@ -1347,7 +1351,11 @@ async def process_client_order_cmds(
 | 
			
		|||
                # (``translate_and_relay_brokerd_events()`` above) will
 | 
			
		||||
                # handle relaying the ems side responses back to
 | 
			
		||||
                # the client/cmd sender from this request
 | 
			
		||||
                log.info(f'Sending live order to {broker}:\n{pformat(msg)}')
 | 
			
		||||
                log.info(
 | 
			
		||||
                    f'Sending live order to {broker}:\n'
 | 
			
		||||
                    f'{pformat(msg)}'
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
                await brokerd_order_stream.send(msg)
 | 
			
		||||
 | 
			
		||||
                # an immediate response should be ``BrokerdOrderAck``
 | 
			
		||||
| 
						 | 
				
			
			@ -1531,7 +1539,7 @@ async def _emsd_main(
 | 
			
		|||
    ctx: tractor.Context,
 | 
			
		||||
    fqme: str,
 | 
			
		||||
    exec_mode: str,  # ('paper', 'live')
 | 
			
		||||
    loglevel: str | None = None,
 | 
			
		||||
    loglevel: str|None = None,
 | 
			
		||||
 | 
			
		||||
) -> tuple[
 | 
			
		||||
    dict[
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,7 @@ Clearing sub-system message and protocols.
 | 
			
		|||
 | 
			
		||||
"""
 | 
			
		||||
from __future__ import annotations
 | 
			
		||||
from decimal import Decimal
 | 
			
		||||
from typing import (
 | 
			
		||||
    Literal,
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -71,7 +72,15 @@ class Order(Struct):
 | 
			
		|||
    symbol: str  # | MktPair
 | 
			
		||||
    account: str  # should we set a default as '' ?
 | 
			
		||||
 | 
			
		||||
    price: float
 | 
			
		||||
    # https://docs.python.org/3/library/decimal.html#decimal-objects
 | 
			
		||||
    #
 | 
			
		||||
    # ?TODO? decimal usage throughout?
 | 
			
		||||
    # -[ ] possibly leverage the `Encoder(decimal_format='number')`
 | 
			
		||||
    #  bit?
 | 
			
		||||
    # |_https://jcristharif.com/msgspec/supported-types.html#decimal
 | 
			
		||||
    # -[ ] should we also use it for .size?
 | 
			
		||||
    #
 | 
			
		||||
    price: Decimal
 | 
			
		||||
    size: float  # -ve is "sell", +ve is "buy"
 | 
			
		||||
 | 
			
		||||
    brokers: list[str] = []
 | 
			
		||||
| 
						 | 
				
			
			@ -178,7 +187,7 @@ class BrokerdOrder(Struct):
 | 
			
		|||
    time_ns: int
 | 
			
		||||
 | 
			
		||||
    symbol: str  # fqme
 | 
			
		||||
    price: float
 | 
			
		||||
    price: Decimal
 | 
			
		||||
    size: float
 | 
			
		||||
 | 
			
		||||
    # TODO: if we instead rely on a +ve/-ve size to determine
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue