Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Genius Yield’s Trading Strategies Competition - Combined rsi bollinger strategy (incl. optional Fear & Greed Index + extras) #57

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cSpell.words": [
"addstrategy",
"ALTCOINS",
"arange",
"backtrader",
"Bollinger",
"Cardano",
"cerebro",
"Doji",
"fgcior",
"fgis",
"Keltner",
"lovelaces",
"talipp",
"tgens"
],
"pylint.args": ["--max-line-length=120", "--disable=missing-module-docstring"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to setup pylint for the CI. Thanks for taking the initiative and starting to address this issue.

}
28 changes: 24 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,35 @@ ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Install dependencies
RUN apt-get update && apt-get install -y \
dos2unix \
wget \
unzip \
curl \
gnupg \
--no-install-recommends

# Install Chrome
RUN curl -fsSL https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
apt-get update && \
apt-get install -y google-chrome-stable && \
rm -rf /var/lib/apt/lists/*

# Download ChromeDriver
RUN CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
wget -O /tmp/chromedriver.zip "https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip" && \
unzip /tmp/chromedriver.zip -d /usr/local/bin/ && \
rm /tmp/chromedriver.zip

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser

Expand All @@ -33,15 +53,15 @@ RUN --mount=type=cache,target=/root/.cache/pip \

# Copy the source code into the container.
COPY *.py .
COPY strategies/* strategies/
COPY src/ src/
COPY bot-api.yaml .
COPY requirements.txt .
COPY .flaskenv .

# Copy the bash scripts into the container.
COPY *.sh .
RUN dos2unix *.sh
RUN chmod +x *.sh

RUN /bin/bash -c /app/generate_client.sh

# Expose the port that the application listens on.
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ start-b:
docker compose up -d --build strategy_b
docker compose logs -f strategy_b

start-c:
docker compose up -d --build strategy_c
docker compose logs -f strategy_c

start-fgis:
docker compose up -d --build fear_and_greed_index_strategy
docker compose logs -f fear_and_greed_index_strategy

start-bb:
docker compose up -d --build bollinger_bands_strategy
docker compose logs -f bollinger_bands_strategy

start-crbs:
docker compose up -d --build combined_rsi_bollinger_strategy
docker compose logs -f combined_rsi_bollinger_strategy

server-logs:
docker compose logs -f server

Expand Down
28 changes: 14 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from client import AuthenticatedClient
from client.models import ErrorResponse, Settings
from client.api.settings import get_settings
from client.types import Response
from typing import cast, Union
from flask import Flask, jsonify
import threading
import time
import importlib
import logging
import os
import sys
import importlib
import yaml
import threading
import time
from api import Api
from api import ApiException
from datetime import datetime
import logging
from typing import Union, cast

import yaml
from client import AuthenticatedClient
from client.api.settings import get_settings
from client.models import ErrorResponse, Settings
from client.types import Response
from flask import Flask, jsonify
from flask_wtf.csrf import CSRFProtect

from api import Api, ApiException

# Spin up Flask Application
app = Flask(__name__)

Expand Down Expand Up @@ -48,7 +48,7 @@ def health_check():
return jsonify(status='healthy', message='Service is up and running!')

def load_strategy(strategy_class):
module = importlib.import_module(f".{strategy_class}", ".strategies")
module = importlib.import_module(f".{strategy_class}", ".src.strategies")
if hasattr(module, 'init'):
module.init()
strategy_class_ref = getattr(module, strategy_class)
Expand Down
76 changes: 72 additions & 4 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
coreProvider:
maestroToken: <<CORE_MAESTRO_API_KEY>>
turboSubmit: false
networkId: "mainnet" # supported: mainnet ot preprod
networkId: "mainnet" # supported: mainnet or preprod
logging:
- type: {tag: stderr}
severity: "Debug" # Options: Debug, Info, Warning or Error
Expand All @@ -33,7 +33,7 @@ services:
environment:
BACKEND_URL: http://server:8082
SERVER_API_KEY: ${SERVER_API_KEY}
EXECUTION_DELAY: 90 # Time period in seconds to wait between strategy exeuctions
EXECUTION_DELAY: 90 # Time period in seconds to wait between strategy executions
STARTUP_DELAY: 1 # Time period in seconds to wait for the backend to start
RETRY_DELAY: 20 # Time period in seconds to wait before retrying to reach the backend
CONFIRMATION_DELAY: 90
Expand All @@ -49,7 +49,7 @@ services:
environment:
BACKEND_URL: http://server:8082
SERVER_API_KEY: ${SERVER_API_KEY}
EXECUTION_DELAY: 15 # Time period in seconds to wait between strategy exeuctions
EXECUTION_DELAY: 15 # Time period in seconds to wait between strategy executions
STARTUP_DELAY: 1 # Time period in seconds to wait for the backend to start
RETRY_DELAY: 20 # Time period in seconds to wait before retrying to reach the backend
CONFIRMATION_DELAY: 90
Expand All @@ -59,13 +59,54 @@ services:
setting_2: 567 ms
depends_on:
- server
strategy_c:
build:
context: .
environment:
BACKEND_URL: http://server:8082
SERVER_API_KEY: ${SERVER_API_KEY}
EXECUTION_DELAY: 30 # Time period in seconds to wait between strategy executions
STARTUP_DELAY: 1 # Time period in seconds to wait for the backend to start
RETRY_DELAY: 20 # Time period in seconds to wait before retrying to reach the backend
CONFIRMATION_DELAY: 90
STRATEGY: strategy_c
CONFIG: |
ASSET_PAIR: "asset1266q2ewhgul7jh3xqpvjzqarrepfjuler20akr-asset1xdz4yj4ldwlpsz2yjgjtt9evg9uskm8jrzjwhj"
START_TIME: "2023-06-15T19:19:56.462Z"
END_TIME: "2024-06-15T19:19:56.462Z"
BIN_INTERVAL: "1d"
depends_on:
- server
fear_and_greed_index_strategy:
build:
context: .
environment:
BACKEND_URL: http://server:8082
SERVER_API_KEY: ${SERVER_API_KEY}
EXECUTION_DELAY: 60 # Time period in seconds to wait between strategy executions
STARTUP_DELAY: 1 # Time period in seconds to wait for the backend to start
RETRY_DELAY: 20 # Time period in seconds to wait before retrying to reach the backend
CONFIRMATION_DELAY: 90
STRATEGY: fear_and_greed_index_strategy
CONFIG: |
BASE_ASSET: lovelace
# GENS for MAINNET:
TARGET_ASSET: dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53
# tGENS for PRERPOD:
# TARGET_ASSET: c6e65ba7878b2f8ea0ad39287d3e2fd256dc5c4160fc19bdf4c4d87e.7447454e53
POSITION_SIZE_LOVELACES: 1000000
STD_DEV_MULTIPLIER: 1.5
PERIOD: 5
FEAR_AND_GREED_INDEX_THRESHOLD: 60
depends_on:
- server
bollinger_bands_strategy:
build:
context: .
environment:
BACKEND_URL: http://server:8082
SERVER_API_KEY: ${SERVER_API_KEY}
EXECUTION_DELAY: 20 # Time period in seconds to wait between strategy exeuctions
EXECUTION_DELAY: 20 # Time period in seconds to wait between strategy executions
STARTUP_DELAY: 1 # Time period in seconds to wait for the backend to start
RETRY_DELAY: 20 # Time period in seconds to wait before retrying to reach the backend
CONFIRMATION_DELAY: 90
Expand All @@ -81,3 +122,30 @@ services:
PERIOD: 5
depends_on:
- server
combined_rsi_bollinger_strategy:
build:
context: .
environment:
BACKEND_URL: http://server:8082
SERVER_API_KEY: ${SERVER_API_KEY}
EXECUTION_DELAY: 60 # Time period in seconds to wait between strategy executions
STARTUP_DELAY: 1 # Time period in seconds to wait for the backend to start
RETRY_DELAY: 20 # Time period in seconds to wait before retrying to reach the backend
CONFIRMATION_DELAY: 90
STRATEGY: combined_rsi_bollinger_strategy
CONFIG: |
BASE_ASSET: lovelace
# GENS for MAINNET:
TARGET_ASSET: dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53
# tGENS for PRERPOD:
# TARGET_ASSET: c6e65ba7878b2f8ea0ad39287d3e2fd256dc5c4160fc19bdf4c4d87e.7447454e53
POSITION_SIZE_LOVELACES: 1000000
RSI_PERIOD: 10 # Shorter period for quicker signals
RSI_OVERBOUGHT: 65 # Lower threshold for overbought
RSI_OVERSOLD: 35 # Higher threshold for oversold
BB_PERIOD: 20 # Standard period
BB_STD_DEV: 1.8 # Tighter bands for volatility
USE_FEAR_AND_GREED: true
FEAR_AND_GREED_INDEX_THRESHOLD: 60
depends_on:
- server
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
backtrader==1.9.78.123
beautifulsoup4==4.12.3
flask==3.0
Flask-WTF==1.2.1
gunicorn==22.0.0
openapi-python-client==0.19.1
selenium==4.21.0
talipp==2.2.0
Flask-WTF==1.2.1
webdriver-manager==4.0.1
File renamed without changes.
Empty file added src/data_extraction/__init__.py
Empty file.
Loading