Skip to content

Commit

Permalink
Update console output
Browse files Browse the repository at this point in the history
  • Loading branch information
ttt733 committed Feb 1, 2019
1 parent 16a1a79 commit ba3b1f7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
risk = 0.001

def get_1000m_history_data(symbols):
print('Getting historical data...')
minute_history = {}
c = 0
for symbol in symbols:
minute_history[symbol] = api.polygon.historic_agg(
size="minute", symbol=symbol, limit=1000
).df
c+=1
print('{}/{}'.format(c, len(symbols)))
print('Success.')
return minute_history

def get_tickers():
print('Getting current ticker data...')
tickers = api.polygon.all_tickers()['tickers']
print('got tickers')
print('Success.')
assets = api.list_assets()
symbols = [asset.symbol for asset in assets if asset.tradable]
return [ticker for ticker in tickers
Expand Down Expand Up @@ -135,7 +137,6 @@ async def handle_trade_update(conn, channel, data):
@conn.on(r'A\..*')
async def handle_second_bar(conn, channel, data):
symbol = data.symbol
print('reading for {}'.format(symbol))

# First, aggregate 1s bars for up-to-date MACD calculations
ts = data.start
Expand Down Expand Up @@ -180,9 +181,8 @@ async def handle_second_bar(conn, channel, data):
since_market_open = ts - get_market_open()
if (
since_market_open.seconds // 60 > 15
#and since_market_open.seconds // 60 < 120
and since_market_open.seconds // 60 < 60
):
print('reading symbol {}'.format(symbol))
# Check for buy signals

# See if we've already bought in first
Expand All @@ -205,7 +205,6 @@ async def handle_second_bar(conn, channel, data):
):
# check for a positive, increasing MACD
hist = macd(minute_history[symbol]['close'].dropna(), n_fast=12, n_slow=26)
print(hist)
if (
hist[-1] < 0
or not (hist[-3] < hist[-2] < hist[-1])
Expand Down Expand Up @@ -295,6 +294,7 @@ async def handle_minute_bar(conn, channel, data):
for symbol in symbols:
symbol_channels = ['A.{}'.format(symbol), 'AM.{}'.format(symbol)]
channels += symbol_channels
print('Watching {} symbols.'.format(len(symbols)))
run_ws(conn, channels)

# Handle failed websocket connections by reconnecting
Expand Down

0 comments on commit ba3b1f7

Please sign in to comment.