-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from enarjord/v5.1.0_user_stream
V5.1.0 user stream
- Loading branch information
Showing
27 changed files
with
2,735 additions
and
3,530 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from procedures import create_binance_bot, create_binance_bot_spot, create_bybit_bot, load_exchange_key_secret\n", | ||
"from pure_funcs import get_template_live_config, ts_to_date, get_daily_from_income\n", | ||
"from njit_funcs import round_dynamic\n", | ||
"from time import time\n", | ||
"import pandas as pd\n", | ||
"import matplotlib.pyplot as plt" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plt.rcParams['figure.figsize'] = [21, 13]\n", | ||
"pd.set_option('precision', 10)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"config = get_template_live_config()\n", | ||
"config['market_type'] = 'futures'\n", | ||
"config['user'] = 'user_name'\n", | ||
"config['exchange'], _, _ = load_exchange_key_secret(config['user'])\n", | ||
"\n", | ||
"n_days = 30\n", | ||
"start_time = (time() - 60 * 60 * 24 * n_days) * 1000\n", | ||
"end_time = time() * 1000\n", | ||
"\n", | ||
"symbols = ['XRPUSDT', 'XLMUSDT', 'ADAUSDT', 'EOSUSDT', 'BNBUSDT', 'LINKUSDT', 'COMPUSDT', 'FILUSDT']\n", | ||
"\n", | ||
"incomes = []\n", | ||
"# binance fetches income for all symbols; bybit only one symbol at a time\n", | ||
"for symbol in (symbols if config['exchange'] == 'bybit' else symbols[:1]):\n", | ||
" config['symbol'] = symbol\n", | ||
" try:\n", | ||
" await bot.session.close()\n", | ||
" except:\n", | ||
" pass\n", | ||
" if config['exchange'] == 'binance':\n", | ||
" if config['market_type'] == 'spot':\n", | ||
" bot = await create_binance_bot_spot(config)\n", | ||
" else:\n", | ||
" bot = await create_binance_bot(config)\n", | ||
" elif config['exchange'] == 'bybit':\n", | ||
" bot = await create_bybit_bot(config)\n", | ||
"\n", | ||
" await bot.update_position()\n", | ||
" balance = bot.position['wallet_balance']\n", | ||
"\n", | ||
" income = await bot.get_all_income(start_time=start_time)\n", | ||
" incomes += income\n", | ||
"idf, bdf = get_daily_from_income(sorted(incomes, key=lambda x: x['timestamp']), bot.position['wallet_balance'], start_time=start_time, end_time=end_time)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(f'current balance {round_dynamic(balance, 5)}')\n", | ||
"print(f'abs sum {round_dynamic(idf.income.sum(), 4)} {idf.iloc[-1][\"token\"]}')\n", | ||
"print(f'abs adg {round_dynamic(idf.income.sum() / n_days, 4)} {idf.iloc[-1][\"token\"]}')\n", | ||
"print(f'pct sum {((balance + idf.income.sum()) / balance) - 1:.5f}')\n", | ||
"print(f'pct adg {((balance + idf.income.sum()) / balance) ** (1 / n_days) - 1:.5f}')\n", | ||
"\n", | ||
"idf.income.cumsum().plot()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"idf.tail(20)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"bdf" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"bdf.gain.plot()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# check income last x days\n", | ||
"x = 3\n", | ||
"since = (time() - 60 * 60 * 24 * x) * 1000\n", | ||
"idf[idf.timestamp > since].groupby('symbol').income.sum().sort_values()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
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,31 +1,44 @@ | ||
import subprocess | ||
|
||
import os | ||
import shutil | ||
from procedures import make_get_filepath | ||
|
||
def main(): | ||
kwargs_list = [ | ||
{'optimize_config_path': 'configs/optimize/scalp.hjson', | ||
'symbol': 'XMRUSDT', | ||
'starting_balance': 1000.0}, | ||
{'optimize_config_path': 'configs/optimize/scalp.hjson', | ||
'symbol': 'BTCUSD_PERP', | ||
'starting_balance': 0.1}, | ||
{'optimize_config_path': 'configs/optimize/vanilla.hjson', | ||
'symbol': 'ADABTC', | ||
'starting_balance': 0.1, | ||
'market_type': 'spot'}, | ||
{'optimize_config_path': 'configs/optimize/scalp.hjson', | ||
'user': 'ebybit', | ||
'symbol': 'EOSUSD', | ||
'starting_balance': 100.0}, | ||
] | ||
tokens = [ | ||
'BTS', 'LTC', 'STORJ', 'BAT', 'DASH', 'SOL', 'AVAX', 'LUNA', 'DYDX', 'COMP', | ||
'FIL', 'LINK', 'MATIC', 'LIT', 'NEO', 'OMG', 'XRP', 'HBAR', 'MANA', 'IOTA', | ||
'ADA', 'QTUM', 'SXP', 'XEM', 'EOS', 'XMR', 'ETC', 'XLM', 'MKR', 'BNB', | ||
'AAVE', 'ALGO', 'TRX', 'ZEC','XTZ', 'BCH'] | ||
start_from = 'BTS' | ||
symbols = tokens[tokens.index(start_from):] + tokens[:tokens.index(start_from)] | ||
|
||
quote = 'USDT' | ||
cfgs_dir = make_get_filepath('cfgs_batch_optimize/') | ||
exchange = 'binance' | ||
|
||
symbols = [e + quote for e in symbols] | ||
kwargs_list = [{ | ||
'start': cfgs_dir, | ||
'symbol': symbol, | ||
#'starting_balance': 10000.0, | ||
#'end_date': '2021-09-20T15:00', | ||
#'start_date': '2021-03-01', | ||
} for symbol in symbols] | ||
for kwargs in kwargs_list: | ||
formatted = f"python3 optimize.py {kwargs['optimize_config_path']}" | ||
for key in [k for k in kwargs if k != 'optimize_config_path']: | ||
formatted = f"python3 optimize.py " | ||
for key in kwargs: | ||
formatted += f' --{key} {kwargs[key]}' | ||
print(formatted) | ||
subprocess.run([formatted], shell=True) | ||
try: | ||
d = f'backtests/{exchange}/{kwargs["symbol"]}/plots/' | ||
ds = sorted([f for f in os.listdir(d) if '20' in f]) | ||
for d1 in ds: | ||
print(f'copying resulting config to {cfgs_dir}', d + d1) | ||
shutil.copy(d + d1 + '/live_config.json', f'{cfgs_dir}{kwargs["symbol"]}_{d1}.json') | ||
except Exception as e: | ||
print('error', kwargs['symbol'], e) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
main() |
Oops, something went wrong.