Skip to content

Commit 993397f

Browse files
authored
Merge pull request #94 from alpacahq/fix/example_messages
Fix/example messages
2 parents db47082 + 7053212 commit 993397f

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

alpaca_trade_api/common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,26 @@ def get_data_url():
1414
def get_credentials(key_id=None, secret_key=None):
1515
key_id = key_id or os.environ.get('APCA_API_KEY_ID')
1616
if key_id is None:
17-
raise ValueError('Key ID must be given to access Alpaca trade API')
17+
raise ValueError('Key ID must be given to access Alpaca trade API',
18+
' (env: APCA_API_KEY_ID)')
1819

1920
secret_key = secret_key or os.environ.get('APCA_API_SECRET_KEY')
2021
if secret_key is None:
21-
raise ValueError('Secret key must be given to access Alpaca trade API')
22+
raise ValueError('Secret key must be given to access Alpaca trade API'
23+
' (env: APCA_API_SECRET_KEY')
2224

2325
return key_id, secret_key
2426

2527

2628
def get_polygon_credentials(alpaca_key=None):
2729
try:
28-
alpaca_key, _ = get_credentials(alpaca_key)
30+
alpaca_key, _ = get_credentials(alpaca_key, 'ignored')
2931
except ValueError:
3032
pass
3133
key_id = os.environ.get('POLYGON_KEY_ID') or alpaca_key
3234
if key_id is None:
33-
raise ValueError('Key ID must be given to access Polygon API')
35+
raise ValueError('Key ID must be given to access Polygon API'
36+
' (env: APCA_API_KEY_ID or POLYGON_KEY_ID)')
3437
return key_id
3538

3639

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .rest import REST # noqa
22
from .stream import Stream # noqa
3-
from .stream2 import StreamConn # noqa
3+
from .streamconn import StreamConn # noqa
File renamed without changes.

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.

tests/test_stream2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from alpaca_trade_api.stream2 import StreamConn
2-
from alpaca_trade_api.polygon.stream2 import StreamConn as PolyStream
2+
from alpaca_trade_api.polygon import StreamConn as PolyStream
33
from alpaca_trade_api.entity import Account
44
import asyncio
55
import json

0 commit comments

Comments
 (0)