-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💱 Feature: Add Crypto OHLC + 3 Retries 💱 (#52)
* making progress * try again function * iex div and splits retry * poly div and splits retry * iex ohlc retry * tests updated * fix try again * bugs * fix tests * fix retries for tests * add polygon key * timezone fix
- Loading branch information
Showing
13 changed files
with
410 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pandas == 1.1.2 | |
robin-stocks == 1.5.2 | ||
boto3 == 1.15.9 | ||
polygon-api-client == 0.1.8 | ||
pytz == 2020.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,75 @@ | ||
import os | ||
import sys | ||
from time import sleep | ||
from multiprocessing import Process | ||
sys.path.append('src') | ||
from DataSource import IEXCloud, Polygon # noqa autopep8 | ||
from Constants import CI, PathFinder # noqa autopep8 | ||
|
||
from Constants import PathFinder # noqa autopep8 | ||
import Constants as C # noqa autopep8 | ||
|
||
iex = IEXCloud() | ||
poly = Polygon() | ||
symbols = iex.get_symbols() | ||
|
||
poly_stocks = Polygon() | ||
poly_crypto = Polygon(os.environ['POLYGON']) | ||
stock_symbols = iex.get_symbols() | ||
crypto_symbols = C.POLY_CRYPTO_SYMBOLS | ||
# Double redundancy | ||
|
||
# 1st pass | ||
|
||
|
||
def update_iex_ohlc(): | ||
for symbol in symbols: | ||
for symbol in stock_symbols: | ||
try: | ||
iex.save_ohlc(symbol=symbol, timeframe='1d') | ||
iex.save_ohlc(symbol=symbol, timeframe='1d', | ||
retries=1 if C.TEST else C.DEFAULT_RETRIES) | ||
except Exception as e: | ||
print(f'IEX Cloud OHLC update failed for {symbol}.') | ||
print(e) | ||
finally: | ||
filename = PathFinder().get_ohlc_path( | ||
symbol=symbol, provider=iex.provider) | ||
if CI and os.path.exists(filename): | ||
if C.CI and os.path.exists(filename): | ||
os.remove(filename) | ||
# 2nd pass | ||
|
||
|
||
def update_poly_ohlc(): | ||
for symbol in symbols: | ||
def update_poly_stocks_ohlc(): | ||
for symbol in stock_symbols: | ||
try: | ||
poly_stocks.save_ohlc(symbol=symbol, timeframe='1d', | ||
retries=1 if C.TEST else C.DEFAULT_RETRIES) | ||
except Exception as e: | ||
print(f'Polygon.io OHLC update failed for {symbol}.') | ||
print(e) | ||
finally: | ||
filename = PathFinder().get_ohlc_path( | ||
symbol=symbol, provider=poly_stocks.provider) | ||
if C.CI and os.path.exists(filename): | ||
os.remove(filename) | ||
# Crypto pass | ||
|
||
|
||
def update_poly_crypto_ohlc(): | ||
for idx, symbol in enumerate(crypto_symbols): | ||
try: | ||
poly.save_ohlc(symbol=symbol, timeframe='1d') | ||
poly_crypto.save_ohlc(symbol=symbol, timeframe='1d', | ||
retries=1 if C.TEST else C.DEFAULT_RETRIES) | ||
except Exception as e: | ||
print(f'Polygon.io OHLC update failed for {symbol}.') | ||
print(e) | ||
finally: | ||
filename = PathFinder().get_ohlc_path( | ||
symbol=symbol, provider=poly.provider) | ||
if CI and os.path.exists(filename): | ||
symbol=symbol, provider=poly_crypto.provider) | ||
if C.CI and os.path.exists(filename): | ||
os.remove(filename) | ||
|
||
if idx != len(crypto_symbols) - 1: | ||
sleep(60 // len(crypto_symbols) + 5) | ||
|
||
|
||
p1 = Process(target=update_iex_ohlc) | ||
p2 = Process(target=update_poly_ohlc) | ||
p2 = Process(target=update_poly_stocks_ohlc) | ||
p3 = Process(target=update_poly_crypto_ohlc) | ||
p1.start() | ||
p2.start() | ||
p3.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.