Skip to content

Commit

Permalink
Fix volume ranking graph proportions
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Wu Fei authored and Carlos Wu Fei committed Jan 15, 2024
1 parent 5d33bab commit e748ccc
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 62 deletions.
24 changes: 19 additions & 5 deletions api/account/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Assets(BaseDeal):
def __init__(self):
self.db = setup_db()
self.usd_balance = 0
self.exception_list = []

def get_raw_balance(self, asset=None):
"""
Expand Down Expand Up @@ -346,20 +347,33 @@ def clean_balance_assets(self):
"""
data = self.signed_request(url=self.account_url)
assets = []
exception_list = ["USDT", "NFT", "BNB"]
self.exception_list = ["USDT", "NFT", "BNB"]

active_bots = list(self.db.bots.find({"status": Status.active}))
for bot in active_bots:
quote_asset = bot["pair"].replace(bot["balance_to_use"], "")
exception_list.append(quote_asset)
self.exception_list.append(quote_asset)

for item in data["balances"]:
if item["asset"] not in exception_list and float(item["free"]) > 0:
if item["asset"] not in self.exception_list and float(item["free"]) > 0:
assets.append(item["asset"])

if len(assets) > 5:
self.transfer_dust(assets)
resp = json_response_message("Sucessfully cleaned balance.")
try:
self.transfer_dust(assets)
resp = json_response_message("Sucessfully cleaned balance.")
except BinanceErrors as error:
msg, code = error
if code == -5005:
for item in assets:
for string in msg:
if string in item:
self.exception_list = item
break

self.clean_balance_assets()
else:
resp = json_response_error(f"Failed to clean balance: {error}")
else:
resp = json_response_error("Amount of assets in balance is low. Transfer not needed.")

Expand Down
1 change: 0 additions & 1 deletion api/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ def setup_db():
password=os.getenv("MONGO_AUTH_PASSWORD"),
)
db = mongo[os.getenv("MONGO_APP_DATABASE")]
db.bots.create_index("id", unique=True)
return db
10 changes: 1 addition & 9 deletions api/streaming/streaming_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,7 @@ def update_order_data(self, result, db_collection: str = "bots"):
if float(result["p"]) > 0:
update["$set"]["orders.$.price"] = float(result["p"])
else:
total_qty = 0
weighted_avg = 0
for item in result["fills"]:
weighted_avg += float(item["price"]) * float(item["qty"])
total_qty += float(item["qty"])

weighted_avg_price = weighted_avg / total_qty
result["p"] = weighted_avg_price
update["$set"]["orders.$.price"] = float(result["L"])

query = self.streaming_db[db_collection].update_one(
{"orders": {"$elemMatch": {"order_id": order_id}}},
Expand All @@ -224,7 +217,6 @@ def on_user_data_message(self, socket, message):

if "e" in res:
if "executionReport" in res["e"]:
logging.info(f'executionReport {res}')
query = self.update_order_data(res)
if query.raw_result["nModified"] == 0:
logging.debug(
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/BarChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { listCssColors } from "../validations";
function computerPercent(data) {
const gainers = [];
const losers = [];

for (let i = 0; i < data.gainers_percent.length; i++) {
const totalCount = data.gainers_count[i] + data.losers_count[i];
const gainersCount =
Expand Down Expand Up @@ -58,15 +59,15 @@ export default function BarChart({
data={[
{
x: data.dates,
y: data.total_volume,
y: data.gainers_percent,
type: "bar",
marker: { color: listCssColors[8] },
name: line1name,
text: gainers,
},
{
x: data.dates,
y: data.total_volume,
y: data.losers_percent,
type: "bar",
marker: { color: listCssColors[2] },
name: line2name,
Expand Down
58 changes: 26 additions & 32 deletions web/src/components/VolumesRanking.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,41 @@ const computeTotalVolume = (data) => {

const average = (data) => {
const total = data.reduce((acc, x) => {
return (acc + parseFloat(x.quoteVolume) + parseFloat(x.volume));
return acc + parseFloat(x.quoteVolume) + parseFloat(x.volume);
}, 0);

return (total / data.length - 1).toLocaleString();
}
};

export default function VolumesRankingCard({ data, title }) {
const sortedData = computeTotalVolume(data);
return (
<div>
<Card border="success">
<div className="p-line-chart"></div>
<Row>
<Col>
<Card.Body>
<Card.Title>{`Volume market average: ${average(data)}`}</Card.Title>
<Card.Title>{title}</Card.Title>
<ListGroup className="list-group-flush">
{sortedData.map((x, i) => (
<ListGroup.Item key={i}>
<Row>
<Col>
<Card.Link href={`/admin/bots/new/${x.symbol}`}>
{x.symbol}
</Card.Link>
</Col>
<Col>
<Badge
bg="success"
className="u-float-right"
>
{(parseFloat(x.quoteVolume) + parseFloat(x.volume)).toLocaleString()}
</Badge>
</Col>
</Row>
</ListGroup.Item>
))}
</ListGroup>
</Card.Body>
</Col>
</Row>
<Card.Body>
<Card.Title>{`Volume market average: ${average(data)}`}</Card.Title>
<Card.Title>{title}</Card.Title>
<ListGroup className="list-group-flush">
{sortedData.map((x, i) => (
<ListGroup.Item key={i}>
<Row>
<Col>
<Card.Link href={`/admin/bots/new/${x.symbol}`}>
{x.symbol}
</Card.Link>
</Col>
<Col>
<Badge bg="success" className="u-float-right">
{(
parseFloat(x.quoteVolume) + parseFloat(x.volume)
).toLocaleString()}
</Badge>
</Col>
</Row>
</ListGroup.Item>
))}
</ListGroup>
</Card.Body>
</Card>
</div>
);
Expand Down
28 changes: 15 additions & 13 deletions web/src/pages/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,21 @@ class Dashboard extends React.Component {
</Row>
<Row>
<Col md="12">
{this.state.netWorth && (
<NetWorthChart data={this.state.netWorth} />
)}
{this.state.dailyPnL && (
<ProfitLossBars data={this.state.dailyPnL} />
)}
</Col>
</Row>
<Row>
<Col lg="6" md="12">
{this.props.gainersLosersData && this.props.gainersLosersData.length > 0 && (
<VolumesRankingCard data={this.props.gainersLosersData} title="Today's highest volumes in USDT market"/>
)}
<Row>
<Col md="6">
{this.state.netWorth && (
<NetWorthChart data={this.state.netWorth} />
)}
{this.props.gainersLosersData && this.props.gainersLosersData.length > 0 && (
<VolumesRankingCard data={this.props.gainersLosersData} title="Today's highest volumes in USDT market"/>
)}
</Col>
<Col md="6">
{this.state.dailyPnL && (
<ProfitLossBars data={this.state.dailyPnL} />
)}
</Col>
</Row>
</Col>
</Row>
</>
Expand Down

0 comments on commit e748ccc

Please sign in to comment.