remove odd lots from output printing
This commit is contained in:
parent
a22cd6d9e0
commit
b1f9ea514a
1 changed files with 5 additions and 17 deletions
|
|
@ -66,22 +66,10 @@ def flatten_and_sort(data):
|
||||||
return trades
|
return trades
|
||||||
|
|
||||||
|
|
||||||
def format_tape_line(trade):
|
def format_tape_line(sym, lots, price):
|
||||||
"""Format a trade like an old ticker tape: SYM shares price"""
|
"""Format a trade like an old ticker tape: SYM lots price.
|
||||||
sym = trade["sym"]
|
A bare price means 1 round lot. '2s' means 2 lots (200 shares)."""
|
||||||
size = trade["s"]
|
vol = f"{lots}s" if lots > 1 else ""
|
||||||
price = trade["p"]
|
|
||||||
|
|
||||||
# Old tickers showed round lots (100s). "2s" meant 200 shares.
|
|
||||||
# A bare price meant 100 shares (1 round lot).
|
|
||||||
if size < 100:
|
|
||||||
vol = f"{size}sh"
|
|
||||||
elif size % 100 == 0:
|
|
||||||
lots = size // 100
|
|
||||||
vol = f"{lots}s" if lots > 1 else ""
|
|
||||||
else:
|
|
||||||
vol = f"{size}sh"
|
|
||||||
|
|
||||||
parts = [sym]
|
parts = [sym]
|
||||||
if vol:
|
if vol:
|
||||||
parts.append(vol)
|
parts.append(vol)
|
||||||
|
|
@ -165,7 +153,7 @@ def main():
|
||||||
print(f"{trade['t']},{trade['sym']},{lots},{trade['p']:.2f}")
|
print(f"{trade['t']},{trade['sym']},{lots},{trade['p']:.2f}")
|
||||||
else:
|
else:
|
||||||
ts = trade["t"][:19].replace("T", " ")
|
ts = trade["t"][:19].replace("T", " ")
|
||||||
line = format_tape_line(trade)
|
line = format_tape_line(trade["sym"], lots, trade["p"])
|
||||||
print(f"{ts} {line}")
|
print(f"{ts} {line}")
|
||||||
total += 1
|
total += 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue