Skip to content

Commit

Permalink
Fix percent issue in example, and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdowling committed Jul 15, 2019
1 parent a20bb80 commit c72da14
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions examples/simpleStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from datetime import datetime

from alpaca_trade_api import StreamConn

# For some fun colors...
from colorama import Fore, Style, init as ColoramaInit

Expand Down Expand Up @@ -45,7 +47,7 @@ async def on_minute(conn, channel, bar):
close = bar.close

try:
percent = (bar.dailyopen - close)/close
percent = (close - bar.dailyopen)/close * 100
up = 1 if bar.open > bar.dailyopen else -1
except: # noqa
percent = 0
Expand All @@ -66,7 +68,7 @@ async def on_minute(conn, channel, bar):

async def on_tick(conn, channel, bar):
try:
percent = (bar.dailyopen - bar.close)/bar.close
percent = (bar.close - bar.dailyopen)/bar.close * 100
except: # noqa
percent = 0

Expand Down Expand Up @@ -111,18 +113,8 @@ async def watch_command():
help="Prints debug messages",
action='store_true')

parser.add_argument(
"--polygon",
help="Only import Polygon.StreamConn instead of Alpaca Wrapper (mainly for testing)",
action='store_true')

opt = parser.parse_args()

if opt.polygon:
from alpaca_trade_api.polygon import StreamConn
else:
from alpaca_trade_api import StreamConn

conn = StreamConn()

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

0 comments on commit c72da14

Please sign in to comment.