Skip to content

Commit c72da14

Browse files
committed
Fix percent issue in example, and small fixes
1 parent a20bb80 commit c72da14

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

examples/simpleStream.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from datetime import datetime
1313

14+
from alpaca_trade_api import StreamConn
15+
1416
# For some fun colors...
1517
from colorama import Fore, Style, init as ColoramaInit
1618

@@ -45,7 +47,7 @@ async def on_minute(conn, channel, bar):
4547
close = bar.close
4648

4749
try:
48-
percent = (bar.dailyopen - close)/close
50+
percent = (close - bar.dailyopen)/close * 100
4951
up = 1 if bar.open > bar.dailyopen else -1
5052
except: # noqa
5153
percent = 0
@@ -66,7 +68,7 @@ async def on_minute(conn, channel, bar):
6668

6769
async def on_tick(conn, channel, bar):
6870
try:
69-
percent = (bar.dailyopen - bar.close)/bar.close
71+
percent = (bar.close - bar.dailyopen)/bar.close * 100
7072
except: # noqa
7173
percent = 0
7274

@@ -111,18 +113,8 @@ async def watch_command():
111113
help="Prints debug messages",
112114
action='store_true')
113115

114-
parser.add_argument(
115-
"--polygon",
116-
help="Only import Polygon.StreamConn instead of Alpaca Wrapper (mainly for testing)",
117-
action='store_true')
118-
119116
opt = parser.parse_args()
120117

121-
if opt.polygon:
122-
from alpaca_trade_api.polygon import StreamConn
123-
else:
124-
from alpaca_trade_api import StreamConn
125-
126118
conn = StreamConn()
127119

128120
# This is another way to setup wrappers for websocket callbacks, handy if conn is not global.

0 commit comments

Comments
 (0)