Error on zero-size orders received by paper engine

size_in_shm_token
Tyler Goodlet 2022-08-25 17:06:53 -04:00
parent 8792c97de6
commit 02f53d0c13
1 changed files with 12 additions and 5 deletions

View File

@ -23,6 +23,7 @@ from contextlib import asynccontextmanager
from datetime import datetime from datetime import datetime
from operator import itemgetter from operator import itemgetter
import itertools import itertools
from pprint import pformat
import time import time
from typing import ( from typing import (
Any, Any,
@ -438,15 +439,21 @@ async def handle_order_requests(
case {'action': ('buy' | 'sell')}: case {'action': ('buy' | 'sell')}:
order = BrokerdOrder(**request_msg) order = BrokerdOrder(**request_msg)
account = order.account account = order.account
# error on bad inputs
reason = None
if account != 'paper': if account != 'paper':
log.error( reason = f'Paper account only. No account found: `{account}` ?'
'This is a paper account,'
' only a `paper` selection is valid' elif order.size == 0:
) reason = 'Invalid size: 0'
if reason:
log.error(reason)
await ems_order_stream.send(BrokerdError( await ems_order_stream.send(BrokerdError(
oid=order.oid, oid=order.oid,
symbol=order.symbol, symbol=order.symbol,
reason=f'Paper only. No account found: `{account}` ?', reason=reason,
)) ))
continue continue