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

Create autotrade table #628

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10.8"
python-version: "3.11"
- name: Install pipenv
run: |
python3 -m pip install pipenv
Expand All @@ -177,7 +177,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10.8"
python-version: "3.11"
- name: Install pipenv
run: python3 -m pip install pipenv
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ WORKDIR /app
COPY /terminal/ /app/
RUN npm install && npm run build

FROM nginx/unit:1.28.0-python3.10
RUN apt-get update && apt-get install -y --no-install-recommends build-essential python3-dev python-setuptools libpq-dev
FROM unit:python3.11
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing build-essential python3-dev libpq-dev
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY api api
WORKDIR api
Expand Down
2 changes: 1 addition & 1 deletion api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ coverage = "*"
ruff = "*"

[requires]
python_version = "3.10.8"
python_version = "3.11"

[pipenv]
allow_prereleases = false
4 changes: 2 additions & 2 deletions api/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/database/api_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from alembic import command

# This allows testing/Github action dummy envs
db_url = f'postgresql://{os.getenv("POSTGRES_USER", "postgres")}:{os.getenv("POSTGRES_PASSWORD", "postgres")}@localhost/{os.getenv("POSTGRES_DB", "postgres")}'
db_url = f'postgresql://{os.getenv("POSTGRES_USER", "postgres")}:{os.getenv("POSTGRES_PASSWORD", "postgres")}@{os.getenv("POSTGRES_HOSTNAME", "localhost")}/{os.getenv("POSTGRES_DB", "postgres")}'
engine = create_engine(
url=db_url,
)
Expand Down
35 changes: 35 additions & 0 deletions api/database/models/autotrade_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from time import time
from typing import Optional
from uuid import UUID, uuid4
from sqlmodel import Field, SQLModel
from tools.enum_definitions import BinanceKlineIntervals


class AutotradeTable(SQLModel, table=True):
__tablename__ = "autotrade"

id: Optional[UUID] = Field(
default_factory=uuid4, primary_key=True, index=True, nullable=False, unique=True
)
autotrade: bool = Field(default=False)
updated_at: float = Field(default=time() * 1000)
# Assuming 10 USDC is the minimum, adding a bit more to avoid MIN_NOTIONAL fail
base_order_size: float = Field(default=15)
candlestick_interval: BinanceKlineIntervals = Field(
default=BinanceKlineIntervals.fifteen_minutes
)
test_autotrade: bool = Field(default=False)
trailling: bool = Field(default=False)
trailling_deviation: float = Field(default=3)
trailling_profit: float = Field(default=2.4)
stop_loss: float = Field(default=0)
take_profit: float = Field(default=2.3)
balance_to_use: str = Field(default="USDC")
balance_size_to_use: float = Field(default=100)
max_request: int = Field(default=950)
system_logs: list[str] = Field(default=[])
telegram_signals: bool = Field(default=True)
max_active_autotrade_bots: int = Field(default=1)

class Config:
arbitrary_types_allowed = True
7 changes: 5 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
from pymongo.errors import ServerSelectionTimeoutError
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request, status
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi.logger import logger

from account.routes import account_blueprint
from autotrade.routes import autotrade_settings_blueprint
Expand All @@ -27,11 +29,12 @@ async def lifespan(app: FastAPI):
api_db = ApiDb()
api_db.init_db()
api_db.create_dummy_bot()
api_db.select_bot("BTCUSDT")
result = api_db.select_bot("BTCUSDT")
logging.info("Added dummy bot: ", result)
except ServerSelectionTimeoutError:
pass
except Exception as e:
print("Error", e)
logging.error("Error", e)

finally:
yield
Expand Down
2 changes: 1 addition & 1 deletion binquant
Submodule binquant updated from 32bb90 to 7c9b62
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
],
"applications": {
"api": {
"type": "python 3.10",
"type": "python 3.11",
"path": "/api",
"module": "main",
"callable": "app",
"processes": 6
}
}
},
"access_log": "/dev/stdout"
}
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ services:
- ./pg_data:/var/lib/postgresql/data
env_file:
- .env
environment:
POSTGRES_USER: "carkod"
POSTGRES_PASSWORD: "2FUd56b3a39Y"
POSTGRES_DB: "binbot"
ports:
- "5432:5432"
healthcheck:
Expand Down Expand Up @@ -116,7 +112,8 @@ services:
# restart: on-failure
# container_name: binbot
# depends_on:
# - db
# - api_db
# - data_db
# env_file:
# - .env
# environment:
Expand Down
Loading