Skip to content

Commit fec9392

Browse files
authored
Merge pull request #92 from alpacahq/feature/polygon_reconnect
updated example for CI, long lines, etc
2 parents 63addf7 + 7c1e3a7 commit fec9392

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

examples/simpleStream.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
from datetime import datetime
1313

1414
# For some fun colors...
15-
from colorama import Fore, Back, Style, init as ColoramaInit
15+
from colorama import Fore, Style, init as ColoramaInit
16+
17+
1618
ColoramaInit(autoreset=True)
1719

1820
# Make this global
1921
opt = None
2022

23+
2124
def ts():
2225
return pd.Timestamp.now()
2326

@@ -55,7 +58,9 @@ async def on_minute(conn, channel, bar):
5558
else:
5659
bar_color = f'{Style.BRIGHT}{Fore.WHITE}'
5760

58-
print(f'{channel:<6} {ms2date(bar.end)} {bar_color}{symbol:<10s} {percent:>8.2f} {bar.open:>8.2f} {bar.close:>8.2f} {bar.volume:<10d}'
61+
print(f'{channel:<6s} {ms2date(bar.end)} {bar.symbol:<10s} '
62+
f'{percent:>8.2f}% {bar.open:>8.2f} {bar.close:>8.2f} '
63+
f' {bar.volume:<10d}'
5964
f' {(Fore.GREEN+"above VWAP") if close > bar.vwap else (Fore.RED+"below VWAP")}')
6065

6166

@@ -65,15 +70,16 @@ async def on_tick(conn, channel, bar):
6570
except: # noqa
6671
percent = 0
6772

68-
print(f'{channel:<6s} {ms2date(bar.end)} {bar.symbol:<10s} {percent:>8.2f}% {bar.open:>8.2f} {bar.close:>8.2f} {bar.volume:<10d}')
73+
print(f'{channel:<6s} {ms2date(bar.end)} {bar.symbol:<10s} '
74+
f'{percent:>8.2f}% {bar.open:>8.2f} {bar.close:>8.2f} '
75+
f' {bar.volume:<10d}')
6976

7077

7178
async def on_data(conn, channel, data):
7279
if opt.debug or not (channel in ('AM', 'Q', 'A', 'T')):
7380
debug("debug: ", pprint.pformat(data))
7481

7582

76-
7783
def reloadWatch(prog, cmd):
7884
async def watch_command():
7985
startingmodtime = os.path.getmtime(prog)
@@ -130,6 +136,8 @@ async def watch_command():
130136

131137
try:
132138
if opt.all:
139+
# Note to see all these channels, you'd need to add a handler
140+
# above or use --debug!
133141
conn.run(['Q.*', 'T.*', 'AM.*', 'A.*'])
134142
else:
135143
conn.run(['AM.*'])

0 commit comments

Comments
 (0)