From 02f53d0c13d9cd5d3aea6e5ab8c484dfb313eacf Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 25 Aug 2022 17:06:53 -0400 Subject: [PATCH] Error on zero-size orders received by paper engine --- piker/clearing/_paper_engine.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/piker/clearing/_paper_engine.py b/piker/clearing/_paper_engine.py index ee3b998c..68eb15bf 100644 --- a/piker/clearing/_paper_engine.py +++ b/piker/clearing/_paper_engine.py @@ -23,6 +23,7 @@ from contextlib import asynccontextmanager from datetime import datetime from operator import itemgetter import itertools +from pprint import pformat import time from typing import ( Any, @@ -438,15 +439,21 @@ async def handle_order_requests( case {'action': ('buy' | 'sell')}: order = BrokerdOrder(**request_msg) account = order.account + + # error on bad inputs + reason = None if account != 'paper': - log.error( - 'This is a paper account,' - ' only a `paper` selection is valid' - ) + reason = f'Paper account only. No account found: `{account}` ?' + + elif order.size == 0: + reason = 'Invalid size: 0' + + if reason: + log.error(reason) await ems_order_stream.send(BrokerdError( oid=order.oid, symbol=order.symbol, - reason=f'Paper only. No account found: `{account}` ?', + reason=reason, )) continue