better rotation
This commit is contained in:
parent
5488773d39
commit
96d2af4c3f
1 changed files with 16 additions and 15 deletions
|
|
@ -4,9 +4,9 @@
|
||||||
Reads a CSV of trades (timestamp, symbol, lots, price) and generates
|
Reads a CSV of trades (timestamp, symbol, lots, price) and generates
|
||||||
ESC/POS commands with 90° rotated text to emulate an old stock ticker tape.
|
ESC/POS commands with 90° rotated text to emulate an old stock ticker tape.
|
||||||
|
|
||||||
When the receipt paper is turned sideways:
|
Each character gets its own printed row. When the receipt paper is turned
|
||||||
- Symbol appears at the top of the tape
|
sideways, symbol characters read across the top and price characters read
|
||||||
- Price (and lot count) appears at the bottom
|
across the bottom — just like a real ticker tape.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
|
|
@ -18,21 +18,23 @@ from escpos.printer import Dummy
|
||||||
LINE_WIDTH = 42
|
LINE_WIDTH = 42
|
||||||
|
|
||||||
|
|
||||||
def format_trade(symbol, lots, price):
|
def print_trade(p, symbol, lots, price):
|
||||||
"""Format a trade line for the ticker tape.
|
"""Print a single trade as ticker tape characters, one per row."""
|
||||||
|
|
||||||
Symbol is placed at the start of the line, price info at the end.
|
|
||||||
With 90° rotation, start-of-line = top of tape, end-of-line = bottom.
|
|
||||||
"""
|
|
||||||
if lots > 1:
|
if lots > 1:
|
||||||
price_str = f"{lots}s{price:.2f}"
|
price_str = f"{lots}s{price:.2f}"
|
||||||
else:
|
else:
|
||||||
price_str = f"{price:.2f}"
|
price_str = f"{price:.2f}"
|
||||||
|
|
||||||
padding = LINE_WIDTH - len(symbol) - len(price_str)
|
# Symbol characters at the top (left-aligned)
|
||||||
if padding < 1:
|
for ch in symbol:
|
||||||
padding = 1
|
p.text(ch + "\n")
|
||||||
return symbol + " " * padding + price_str
|
|
||||||
|
# Price characters at the bottom (right-aligned)
|
||||||
|
for ch in price_str:
|
||||||
|
p.text(" " * (LINE_WIDTH - 1) + ch + "\n")
|
||||||
|
|
||||||
|
# Blank line separator between trades
|
||||||
|
p.text("\n")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -50,8 +52,7 @@ def main():
|
||||||
_timestamp, symbol, lots_str, price_str = row
|
_timestamp, symbol, lots_str, price_str = row
|
||||||
lots = int(lots_str)
|
lots = int(lots_str)
|
||||||
price = float(price_str)
|
price = float(price_str)
|
||||||
line = format_trade(symbol, lots, price)
|
print_trade(p, symbol, lots, price)
|
||||||
p.text(line + "\n")
|
|
||||||
|
|
||||||
p.cut()
|
p.cut()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue