-
-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CLI bugs and add back to support non-CLI workflow.
- Loading branch information
1 parent
024d696
commit afacd02
Showing
7 changed files
with
118 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from lib.cli.functions import * | ||
from lib.cli.RLTraderCLI import RLTraderCLI |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from lib.cli.functions.update_data import download_data_async |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
import ssl | ||
import pandas as pd | ||
import os | ||
|
||
final_date_format = '%Y-%m-%d %H:%M' | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
|
||
hourly_url = "https://www.cryptodatadownload.com/cdd/Coinbase_BTCUSD_1h.csv" | ||
daily_url = "https://www.cryptodatadownload.com/cdd/Coinbase_BTCUSD_d.csv" | ||
|
||
|
||
async def save_url_to_csv(url: str, date_format: str, file_name: str): | ||
csv = pd.read_csv(url, header=1) | ||
csv = csv.dropna(thresh=2) | ||
csv.columns = ['Date', 'Symbol', 'Open', 'High', 'Low', 'Close', 'VolumeFrom', 'VolumeTo'] | ||
csv['Date'] = pd.to_datetime(csv['Date'], format=date_format) | ||
csv['Date'] = csv['Date'].dt.strftime(final_date_format) | ||
|
||
final_path = os.path.join('data', 'input', file_name) | ||
csv.to_csv(final_path, index=False) | ||
|
||
return csv | ||
|
||
|
||
async def save_as_csv(hourly_url: str, daily_url: str): | ||
tasks = [save_url_to_csv(hourly_url, '%Y-%m-%d %I-%p', 'coinbase-1h-btc-usd.csv'), | ||
save_url_to_csv(daily_url, '%Y-%m-%d', 'coinbase-1d-btc-usd.csv')] | ||
# also FIRST_EXCEPTION and ALL_COMPLETED (default) | ||
done, pending = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED) | ||
print('>> done: ', done) | ||
print('>> pending: ', pending) # will be empty if using default return_when setting | ||
|
||
|
||
def download_data_async(): | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(save_as_csv(hourly_url, daily_url)) | ||
loop.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
download_async() |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import numpy as np | ||
|
||
import multiprocessing | ||
from lib.RLTrader import RLTrader | ||
|
||
np.warnings.filterwarnings('ignore') | ||
|
||
|
||
def optimize_code(params): | ||
trader = RLTrader(**params) | ||
trader.optimize() | ||
|
||
|
||
if __name__ == '__main__': | ||
n_process = multiprocessing.cpu_count() - 4 | ||
params = {} | ||
|
||
processes = [] | ||
for i in range(n_process): | ||
processes.append(multiprocessing.Process(target=optimize_code, args=(params,))) | ||
|
||
for p in processes: | ||
p.start() | ||
|
||
for p in processes: | ||
p.join() | ||
|
||
trader = RLTrader(**params) | ||
trader.train(test_trained_model=True, render_trained_model=True) |