Skip to content

Commit

Permalink
refactor: invaas notebook init and main task usage
Browse files Browse the repository at this point in the history
  • Loading branch information
daneisburgh committed Dec 3, 2023
1 parent 067935c commit c85172e
Showing 1 changed file with 89 additions and 24 deletions.
113 changes: 89 additions & 24 deletions notebooks/invaas-notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "58a7fbc0-7d3d-4d5c-987a-409bcaa91e37",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2023-11-13 17:22:05 WARNING No DBUtils defined in the runtime\n",
"2023-11-13 17:22:05 INFO Initializing task for local environment\n",
"2023-11-13 17:22:05 INFO Products to trade: ['BTC-USD', 'ETH-USD']\n"
"Defaulting to user installation because normal site-packages is not writeable\n",
"\u001b[31mERROR: Invalid requirement: '/Workspace/Shared/.bundle/prod/invaas/files'\n",
"Hint: It looks like a path. File '/Workspace/Shared/.bundle/prod/invaas/files' does not exist.\u001b[0m\u001b[31m\n",
"\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.1\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
Expand All @@ -22,39 +26,100 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "2fd2ae83",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2023-12-03 21:21:19 WARNING No DBUtils defined in the runtime\n",
"2023-12-03 21:21:19 INFO Initializing task for local environment\n",
"2023-12-03 21:21:19 INFO Products to trade: ['ATOM-USD', 'BTC-USD', 'DOT-USD', 'ETH-USD', 'SOL-USD']\n",
"2023-12-03 21:21:19 INFO Minimum fear greed index to buy: 60\n",
"2023-12-03 21:21:19 INFO Current fear greed index: 73\n",
"2023-12-03 21:21:19 INFO Min buy amount: $2\n",
"2023-12-03 21:21:19 INFO Max buy amount: $100\n",
"2023-12-03 21:21:19 INFO Max owned amount: $1000\n"
]
}
],
"source": [
"import os\n",
"import sys\n",
"\n",
"sys.path.append(\"/Workspace/Shared/.bundle/prod/invaas/files\")\n",
"from dotenv import load_dotenv, find_dotenv\n",
"\n",
"load_dotenv(find_dotenv())\n",
"app_env = os.getenv(\"APP-ENV\")\n",
"\n",
"sys.path.append((\n",
" \"/Workspace/Shared/.bundle/prod/invaas/files\"\n",
" if app_env != \"local\"\n",
" else os.path.abspath(os.path.join(\"..\"))\n",
"))\n",
"\n",
"from invaas.main import Task\n",
"\n",
"task = Task()"
"task = Task(env=app_env)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "f81dfce2",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2023-12-03 21:21:19 INFO Running process for ATOM-USD\n",
"2023-12-03 21:21:19 INFO Owned ATOM: 0.0000000000\n",
"2023-12-03 21:21:19 INFO Current ATOM spot price: $9.47\n",
"2023-12-03 21:21:20 INFO Available cash: $100.02\n",
"2023-12-03 21:21:20 INFO Order side: BUY\n",
"2023-12-03 21:21:20 INFO Buy amount: $2.00\n",
"2023-12-03 21:21:20 INFO Placing market buy order for ATOM-USD: 336c04f1-ea77-410d-859c-085191839612\n",
"\n",
"2023-12-03 21:21:20 INFO Running process for BTC-USD\n",
"2023-12-03 21:21:20 INFO Owned BTC: 0.0000000000\n",
"2023-12-03 21:21:21 INFO Current BTC spot price: $39657.52\n",
"2023-12-03 21:21:21 INFO Available cash: $98.02\n",
"2023-12-03 21:21:21 INFO Order side: BUY\n",
"2023-12-03 21:21:21 INFO Buy amount: $2.00\n",
"2023-12-03 21:21:21 INFO Placing market buy order for BTC-USD: b98e2d6a-69f1-4254-bfe5-8e2fdbe1d396\n",
"\n",
"2023-12-03 21:21:21 INFO Running process for DOT-USD\n",
"2023-12-03 21:21:22 INFO Owned DOT: 0.0000000000\n",
"2023-12-03 21:21:22 INFO Current DOT spot price: $5.49\n",
"2023-12-03 21:21:22 INFO Available cash: $96.02\n",
"2023-12-03 21:21:22 INFO Order side: BUY\n",
"2023-12-03 21:21:22 INFO Buy amount: $2.00\n",
"2023-12-03 21:21:22 INFO Placing market buy order for DOT-USD: 563d8a0a-d302-47a2-b544-d46ce6a06f45\n",
"\n",
"2023-12-03 21:21:23 INFO Running process for ETH-USD\n",
"2023-12-03 21:21:23 INFO Owned ETH: 0.0000000034\n",
"2023-12-03 21:21:23 INFO Current ETH spot price: $2171.93\n",
"2023-12-03 21:21:23 INFO Available cash: $94.02\n",
"2023-12-03 21:21:23 INFO Order side: BUY\n",
"2023-12-03 21:21:23 INFO Buy amount: $2.00\n",
"2023-12-03 21:21:23 INFO Placing market buy order for ETH-USD: 13eda918-4c04-4214-8d22-c18f71b6a90a\n",
"\n",
"2023-12-03 21:21:24 INFO Running process for SOL-USD\n",
"2023-12-03 21:21:24 INFO Owned SOL: 0.0000000000\n",
"2023-12-03 21:21:24 INFO Current SOL spot price: $62.86\n",
"2023-12-03 21:21:24 INFO Available cash: $92.02\n",
"2023-12-03 21:21:24 INFO Order side: BUY\n",
"2023-12-03 21:21:24 INFO Buy amount: $2.00\n",
"2023-12-03 21:21:24 INFO Placing market buy order for SOL-USD: 91d8e78d-27d2-4a2e-a702-faad1f9f8b89\n",
"\n"
]
}
],
"source": [
"for product_id in task.product_ids:\n",
" task.logger.info(f\"Running process for {product_id}\")\n",
" product_history_df = task.get_product_history_df(product_id)\n",
" product_next_open_pct_change = task.get_product_next_open_pct_change(product_history_df)\n",
" task.logger.info(f\"Predicted change for {product_id}: {product_next_open_pct_change:.3f}%\")\n",
"\n",
" min_pct_change = 1.5\n",
"\n",
" if product_next_open_pct_change < min_pct_change:\n",
" task.sell_product(product_id)\n",
" else:\n",
" task.buy_product(product_id)\n",
"\n",
" print()"
"task.create_orders()"
]
}
],
Expand Down

0 comments on commit c85172e

Please sign in to comment.