Skip to content
Merged
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
2 changes: 0 additions & 2 deletions api/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def get_listen_key(self):
"""
No security endpoints
"""

def ticker_24(self, type: str = "FULL", symbol: str | None = None):
"""
Weight 40 without symbol
Expand Down Expand Up @@ -174,7 +173,6 @@ def get_raw_klines(
"""
USER_DATA endpoints
"""

def get_account_balance(self):
"""
Get account balance
Expand Down
24 changes: 23 additions & 1 deletion api/charts/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from charts.models import MarketDominationSeriesStore
from apis import BinbotApi
from database.db import Database, setup_db, setup_kafka_db

from pandas import DataFrame

class KlinesSchema(Database):
"""
Expand Down Expand Up @@ -259,3 +259,25 @@ def top_gainers(self):
reverse=True,
)
return fiat_market_data[:10]


class BtcCorrelation(Database, BinbotApi):
"""
CRUD operations for BTC correlation
"""

def __init__(self) -> None:
super().__init__()
self.collection = Candlestick()

def get_btc_correlation(self, asset_symbol: str):
"""
Get BTC correlation data
TODO: wait for BTCUSDC data to populate by Binquant
"""
asset_data = self.collection.get_timeseries(asset_symbol)
btc_data = self.collection.get_timeseries("BTCUSDT")
asset_df = DataFrame(asset_data, columns=["close"])
btc_df = DataFrame(btc_data, columns=["close"])
p_correlation = asset_df["close"].corr(btc_df["close"], method="pearson")
return p_correlation
21 changes: 20 additions & 1 deletion api/charts/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
json_response_error,
json_response_message,
)
from charts.controllers import Candlestick, MarketDominationController
from charts.controllers import Candlestick, MarketDominationController, BtcCorrelation

charts_blueprint = APIRouter()

Expand Down Expand Up @@ -118,3 +118,22 @@ def top_gainers():

except Exception as error:
return json_response_error(f"Failed to retrieve top gainers data: {error}")


@charts_blueprint.get("/btc-correlation", tags=["charts"])
def get_btc_correlation(symbol: str):
try:
response = BtcCorrelation().get_btc_correlation(asset_symbol=symbol)
if response:
return json_response(
{
"data": response,
"message": "Successfully retrieved BTC correlation data.",
"error": 0,
}
)
else:
raise HTTPException(404, detail="No data found")

except Exception as error:
return json_response_error(f"Failed to retrieve BTC correlation data: {error}")
6 changes: 3 additions & 3 deletions api/database/api_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def create_dummy_bot(self):
time_in_force="GTC",
timestamp=0,
order_side="buy",
pair="BTCUSDT",
pair="BTCUSDC",
qty=0.000123,
status="filled",
price=1.222,
Expand All @@ -138,7 +138,7 @@ def create_dummy_bot(self):
time_in_force="GTC",
timestamp=0,
order_side="sell",
pair="BTCUSDT",
pair="BTCUSDC",
qty=0.000123,
status="filled",
price=1.222,
Expand Down Expand Up @@ -195,7 +195,7 @@ def create_dummy_bot(self):
total_commission=0,
)
paper_trading_bot = PaperTradingTable(
pair="BTCUSDT",
pair="BTCUSDC",
balance_size_to_use=1,
balance_to_use=1,
base_order_size=15,
Expand Down
6 changes: 3 additions & 3 deletions api/tests/model_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
id = "02031768-fbb9-4cc7-b549-642f15ab787b"
ts = 1733973560249.0

active_pairs = ["BTCUSDT", "ETHUSDT", "ADAUSDT"]
active_pairs = ["BTCUSDC", "ETHUSDT", "ADAUSDT"]

deal_model = DealModel(
opening_price=1.3,
Expand Down Expand Up @@ -61,7 +61,7 @@
time_in_force="GTC",
timestamp=0,
order_side="buy",
pair="BTCUSDT",
pair="BTCUSDC",
qty=0.000123,
status="filled",
price=1.222,
Expand All @@ -75,7 +75,7 @@
time_in_force="GTC",
timestamp=0,
order_side="sell",
pair="BTCUSDT",
pair="BTCUSDC",
qty=0.000123,
status="filled",
price=1.222,
Expand Down
4 changes: 2 additions & 2 deletions api/tests/table_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
time_in_force="GTC",
timestamp=0,
order_side="buy",
pair="BTCUSDT",
pair="BTCUSDC",
qty=0.000123,
status="filled",
price=1.222,
Expand All @@ -29,7 +29,7 @@
time_in_force="GTC",
timestamp=0,
order_side="sell",
pair="BTCUSDT",
pair="BTCUSDC",
qty=0.000123,
status="filled",
price=1.222,
Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def patch_total_fiat(monkeypatch):

monkeypatch.setattr(Assets, "get_wallet_balance", lambda self: account_data)
monkeypatch.setattr(
Assets, "ticker", lambda self, symbol="BTCUSDT", json=False: {"price": "20000"}
Assets, "ticker", lambda self, symbol="BTCUSDC", json=False: {"price": "20000"}
)


Expand Down
2 changes: 1 addition & 1 deletion binquant
Submodule binquant updated from 0b286f to b6d7e0
62 changes: 30 additions & 32 deletions terminal/src/app/components/BotCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { computeSingleBotProfit } from "../../features/bots/profits";
import { roundDecimals } from "../../utils/math";
import { BotStatus } from "../../utils/enums";
import { formatTimestamp, renderDuration } from "../../utils/time";
import { getQuoteAsset } from "../../utils/api";

type handleCallback = (id: string) => void;

Expand Down Expand Up @@ -97,6 +98,18 @@ const BotCard: FC<BotCardProps> = ({
</p>
</Col>
</Row>
{bot.deal?.opening_timestamp > 0 && (
<Row>
<Col md="6" xs="7">
<p className="small">Open time</p>
</Col>
<Col md="6" xs="5">
<p className="small">
{formatTimestamp(bot.deal.opening_timestamp)}
</p>
</Col>
</Row>
)}
<Row>
<Col md="6" xs="7">
<p className="small">Take profit</p>
Expand Down Expand Up @@ -143,54 +156,39 @@ const BotCard: FC<BotCardProps> = ({
{bot.deal?.total_interests > 0 && (
<Row>
<Col md="6" xs="7">
<p className="small">Comissions</p>
<p className="small">Interests</p>
</Col>
<Col md="6" xs="5">
<p className="small">{`${bot.deal.total_interests} BNB`}</p>
<p className="small">{`${bot.deal.total_interests} ${getQuoteAsset(bot)}`}</p>
</Col>
</Row>
)}
{Boolean(bot.deal?.opening_timestamp) && (

{bot.deal?.closing_timestamp > 0 && (
<Row>
<Col md="6" xs="7">
<p className="small">Buy time</p>
<p className="small">Close time</p>
</Col>
<Col md="6" xs="5">
<p className="small">
{formatTimestamp(bot.deal.opening_timestamp)}
{formatTimestamp(bot.deal.closing_timestamp)}
</p>
</Col>
</Row>
)}
{bot.status === BotStatus.COMPLETED &&
Boolean(bot.deal?.closing_timestamp) && (
<Row>
<Col md="6" xs="7">
<p className="small">Sell time</p>
</Col>
<Col md="6" xs="5">
<p className="small">
{formatTimestamp(bot.deal.closing_timestamp)}
</p>
</Col>
</Row>
)}
{bot.status === BotStatus.COMPLETED &&
Boolean(
bot.deal?.opening_timestamp && bot.deal?.closing_timestamp,
) && (
<Row>
<Col md="6" xs="7">
<p className="small">Duration</p>
</Col>
<Col md="6" xs="5">
<p className="small">{renderDuration(bot)}</p>
</Col>
</Row>
)}
{bot.deal?.closing_timestamp > 0 && (
<Row>
<Col md="6" xs="7">
<p className="small">Duration</p>
</Col>
<Col md="6" xs="5">
<p className="small">{renderDuration(bot)}</p>
</Col>
</Row>
)}
</Container>
</Card.Body>
<hr />
<hr className="hr-compact" />
<Card.Footer className="d-flex flex-row justify-content-between">
<Button
variant="info"
Expand Down
58 changes: 20 additions & 38 deletions terminal/src/app/components/BotInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { renderDuration, formatTimestamp } from "../../utils/time";

export default function BotInfo({ bot }) {
const [showOrderInfo, toggleOrderInfo] = useState<boolean>(
bot.orders?.length > 0,
bot.orders?.length > 0
);
return (
<Card>
Expand Down Expand Up @@ -80,44 +80,26 @@ export default function BotInfo({ bot }) {
</Row>
<ListGroup className="list-group-flush">
{Object.keys(bot.deal).map((k, i) => {
if (typeof bot.deal[k] !== "object") {
let dealData = bot.deal[k];
if (k === "opening_timestamp" || k === "closing_timestamp") {
dealData =
bot.deal[k] === 0 || formatTimestamp(bot.deal[k]);
}
return (
<ListGroup.Item
action
as="h5"
key={i}
className="d-flex justify-content-between align-items-start"
>
<small>{k}</small>
{dealData || dealData > 0 ? (
<Badge bg="secondary">{dealData}</Badge>
) : (
<small>{dealData}</small>
)}
</ListGroup.Item>
);
} else {
return (
<ListGroup key={i} variant="flush">
{Object.keys(bot.deal[k]).map((l, j) => (
<ListGroup.Item
key={j}
as="h5"
className="d-flex justify-content-between align-items-start"
>
<div className="ms-2 me-auto">
{l}:{bot.deal[k][l]}
</div>
</ListGroup.Item>
))}
</ListGroup>
);
let dealData = bot.deal[k];
if (k === "opening_timestamp" || k === "closing_timestamp") {
dealData =
bot.deal[k] === 0 || formatTimestamp(bot.deal[k]);
}
return (
<ListGroup.Item
action
as="h5"
key={i}
className="d-flex justify-content-between align-items-start"
>
<small>{k}</small>
{dealData || dealData > 0 ? (
<Badge bg="secondary">{dealData}</Badge>
) : (
<small>{dealData}</small>
)}
</ListGroup.Item>
);
})}
<ListGroup.Item
as="h5"
Expand Down
1 change: 0 additions & 1 deletion terminal/src/app/components/SymbolSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe("Search symbols", () => {
const baseAsset = "USDC";
const listSymbols = [
"USDCBNB",
"BTCUSDT",
"BTCUSDC",
"BTCETH",
"ETHUSDT",
Expand Down
2 changes: 1 addition & 1 deletion terminal/src/app/components/SymbolSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const SymbolSearch: FC<{
if (value) {
setState(value);
}
// BTCUSDT, BTCUSDC, BTCETH, ETHUSDT, ETHUSDC -> BTCUSDC
// BTCUSDC, BTCUSDC, BTCETH, ETHUSDT, ETHUSDC -> BTCUSDC
// check test for examples
if (options && options.length > 0) {
let updatedOptions = options;
Expand Down
2 changes: 1 addition & 1 deletion terminal/src/app/pages/Bots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const BotsPage: FC<{}> = () => {
</Stack>
</div>
</div>
<Row md="4">
<Row md="3" xs="1" lg="4">
{props?.bots?.ids.length > 0
? Object.values(props?.bots?.entities).map((x, i) => (
<Col key={i}>
Expand Down
4 changes: 2 additions & 2 deletions terminal/src/app/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const DashboardPage: FC<{}> = () => {
if (benchmark) {
if (benchmark.benchmarkData) {
const { revenue, percentage } = calculateTotalRevenue(
benchmark.benchmarkData,
benchmark.benchmarkData
);
setRevenue(revenue);
setPercentageRevenue(percentage);
Expand Down Expand Up @@ -143,7 +143,7 @@ export const DashboardPage: FC<{}> = () => {
<p>(Current - Last balance)</p>
</Col>
<Col>
<p className=" text-end">{roundDecimals(revenue)} USDC</p>
<p className="text-end">{roundDecimals(revenue)} USDC</p>
</Col>
</Row>
</Card.Footer>
Expand Down
6 changes: 6 additions & 0 deletions terminal/src/assets/scss/paper-dashboard/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ a {
color: $primary-color;
}
}

.hr-compact {
color: $black-hr;
margin: $margin-base-vertical 0;
}

h1,
.h1 {
font-size: $font-size-h1;
Expand Down
Loading
Loading