Skip to content

Commit

Permalink
support lising data in binance locked savings (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn authored Apr 26, 2024
1 parent c2a91d7 commit 3583afc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src-tauri/src/binance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use binance::{
account::Account, api::Binance as BinanceApi, futures::account::FuturesAccount, wallet::Wallet,
account::Account, api::Binance as BinanceApi, futures::account::FuturesAccount,
util::build_signed_request, wallet::Wallet,
};
use std::collections::HashMap;

Expand All @@ -8,6 +9,17 @@ pub struct Binance {
secret_key: String,
}

#[derive(Debug, serde::Deserialize)]
struct LockedSavingResponse {
rows: Vec<LockedSavingRowItem>,
}

#[derive(Debug, serde::Deserialize)]
struct LockedSavingRowItem {
asset: String,
amount: String,
}

impl Binance {
pub fn new(api_key: String, secret_key: String) -> Self {
Self {
Expand All @@ -34,7 +46,7 @@ impl Binance {
acc
});

// funding
// funding: it includes flexible savings
let wallet_funding = funding.funding_wallet(None, None).await?;
wallet_funding
.iter()
Expand All @@ -48,6 +60,28 @@ impl Binance {
}
});

// locked savings in simple earn
let locked_savings_req = build_signed_request([("size", "100")], funding.recv_window)?;
let locked_savings: LockedSavingResponse = funding
.client
.get_signed(
"/sapi/v1/simple-earn/locked/position",
locked_savings_req.as_str(),
)
.await?;
print!("{:?}", locked_savings);

locked_savings.rows.iter().for_each(|row| {
let asset = row.asset.clone();
let amount = row.amount.parse::<f64>().unwrap_or(0.0);
if res.contains_key(&asset) {
let val = res.get(&asset).unwrap();
res.insert(asset.to_owned(), val + amount);
} else {
res.insert(asset.to_owned(), amount);
}
});

// futures
let futures_balances = futures.account_balance().await?;
futures_balances
Expand Down
2 changes: 1 addition & 1 deletion src/middlelayers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function loadPortfoliosByConfig(config: CexConfig & TokenConfig, addProgre
if (userInfo.isPro) {
console.debug("pro license, use pro analyzers")
anas = [ERC20ProAnalyzer, CexAnalyzer, SOLAnalyzer, OthersAnalyzer, BTCAnalyzer, DOGEAnalyzer, TRC20ProUserAnalyzer, TonAnalyzer]
// anas = [TonAnalyzer]
// anas = [CexAnalyzer]
} else {
console.debug("not pro license, fallback to normal analyzers")
}
Expand Down

0 comments on commit 3583afc

Please sign in to comment.