Skip to content

Commit

Permalink
Setup new top gainers endpoiont
Browse files Browse the repository at this point in the history
  • Loading branch information
carkod committed Dec 7, 2024
1 parent ff73e07 commit acb826a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ db.dump
__pycache__
kafka_data
pg_data
!terminal/.env
!terminal/.env
!.python-version
2 changes: 1 addition & 1 deletion api/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def ticker_24(self, type: str = "FULL", symbol: str | None = None):
params["symbol"] = symbol

# mongo_cache = self.setup_mongocache()
# expire_after = 15m because candlesticks are 15m
# # because candlesticks are 15m
# session = CachedSession('ticker_24_cache', backend=mongo_cache, expire_after=15)
data = self.request(url=self.ticker24_url, params=params)
return data
Expand Down
4 changes: 4 additions & 0 deletions api/autotrade/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ def edit_settings(self, data):
AsyncBaseProducer().update_required("UPDATE_AUTOTRADE_SETTINGS")
self.session.close()
return settings

def get_fiat(self):
data = self.get_settings()
return data.fiat
16 changes: 15 additions & 1 deletion api/charts/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class MarketDominationController(Database, BinbotApi):
def __init__(self) -> None:
super().__init__()
self.collection = self.kafka_db.market_domination
self.autotrade_settings = AutotradeSettingsController().get_settings()
self.autotrade_db = AutotradeSettingsController()
self.autotrade_settings = self.autotrade_db.get_settings()

def mkdm_migration(self):
"""
Expand Down Expand Up @@ -236,3 +237,16 @@ def get_market_domination(self, size=7):
]
)
return list(result)

def top_gainers(self):
"""
Get market top gainers of the day
ATTENTION - This is a very heavy weight operation
ticker_24() retrieves all tokens
"""
fiat = self.autotrade_db.get_fiat()
ticket_data = self.ticker_24()

fiat_market_data = sorted((item for item in ticket_data if item["symbol"].endswith(fiat) and float(item["priceChangePercent"]) > 0), key=lambda x: x["priceChangePercent"], reverse=True)
return fiat_market_data
21 changes: 20 additions & 1 deletion api/charts/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter
from fastapi import APIRouter, HTTPException
from tools.round_numbers import format_ts
from charts.models import (
GetMarketDominationResponse,
Expand Down Expand Up @@ -99,3 +99,22 @@ def md_migration():
return json_response_error(
f"Failed to migrate market domination data: {error.args[0]}"
)


@charts_blueprint.get("/top-gainers", tags=["assets"])
def top_gainers():
try:
response = MarketDominationController().top_gainers()
if response:
return json_response(
{
"data": response,
"message": "Successfully retrieved top gainers data.",
"error": 0,
}
)
else:
raise HTTPException(404, detail="No data found")

except Exception as error:
return json_response_error(f"Failed to retrieve top gainers data: {error}")
1 change: 1 addition & 0 deletions api/database/models/autotrade_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AutotradeTable(SQLModel, table=True):
stop_loss: float = Field(default=0)
take_profit: float = Field(default=2.3)
balance_to_use: str = Field(default="USDC")
fiat: str = Field(default="USDC")
max_request: int = Field(default=950)
telegram_signals: bool = Field(default=True)
max_active_autotrade_bots: int = Field(default=1)
Expand Down
2 changes: 1 addition & 1 deletion binquant
Submodule binquant updated from 6a4ca1 to 1c3bcd

0 comments on commit acb826a

Please sign in to comment.