Skip to content

Commit 2d8ef09

Browse files
static table done
1 parent 42a8037 commit 2d8ef09

File tree

3 files changed

+579
-22
lines changed

3 files changed

+579
-22
lines changed

crates/brontes-types/src/db/cex/quotes/cex_quotes.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ use crate::{
4242
FastHashMap,
4343
};
4444

45-
pub enum SecuritiesClass {
45+
pub enum CommodityClass {
4646
Spot,
47-
Derivative,
47+
Futures,
48+
Options
4849
}
4950

5051
/// Centralized exchange price map organized by exchange.
@@ -334,7 +335,7 @@ impl CexPriceMap {
334335
let volume_weighted_bid = volume_price.0 / &cumulative_bbo.0;
335336
let volume_weighted_ask = volume_price.1 / &cumulative_bbo.1;
336337

337-
let fees = exchange.fees(&pair, &SecuritiesClass::Spot);
338+
let fees = exchange.fees(&pair, &CommodityClass::Spot);
338339

339340
let fee_adjusted_maker = (
340341
&volume_weighted_bid * (Rational::ONE - &fees.0),
@@ -1021,34 +1022,32 @@ impl CexExchange {
10211022
///
10221023
/// TODO: Account for special fee pairs & stableswap rates
10231024
/// TODO: Account for futures & spot fee deltas
1024-
pub fn fees(&self, pair: &Pair, trade_type: &SecuritiesClass) -> (Rational, Rational) {
1025+
pub fn fees(&self, pair: &Pair, trade_type: &CommodityClass) -> (Rational, Rational) {
10251026
let (maker, taker) = match self {
10261027
CexExchange::Binance => {
10271028
match trade_type {
1028-
SecuritiesClass::Spot =>
1029+
CommodityClass::Spot =>
10291030
if Self::BINANCE_SPOT_PROMO_FEE_TYPE1_PAIRS.iter().any(|p| p.eq_ordered(pair)) {
10301031
("0.0", "0.0") // https://www.binance.com/en/fee/tradingPromote
10311032
} else if Self::BINANCE_SPOT_PROMO_FEE_TYPE2_PAIRS.iter().any(|p| p.eq_ordered(pair)) {
10321033
("0.0", "0.00024") // https://www.binance.com/en/fee/tradingPromote
1033-
10341034
} else if pair.0 == USDC_ADDRESS || pair.1 == USDC_ADDRESS {
10351035
("0.00012", "0.0001425") // https://www.binance.com/en/fee/trading
10361036
} else {
10371037
("0.00012", "0.00024") // https://www.binance.com/en/fee/trading
10381038
},
1039-
SecuritiesClass::Derivative => ("0.0003", "0.0003"), // https://www.binance.com/en/fee/optionsTrading
1039+
CommodityClass::Derivative => ("0.0003", "0.0003"), // https://www.binance.com/en/fee/optionsTrading
10401040
}
10411041
},
10421042
CexExchange::Bitmex =>
10431043
match trade_type {
1044-
SecuritiesClass::Spot => ("0.001", "0.001"), // https://www.bitmex.com/wallet/fees/spot
1045-
SecuritiesClass::Derivative => ("-0.000125", "0.000175"), // https://www.bitmex.com/wallet/fees/derivatives
1046-
1044+
CommodityClass::Spot => ("0.001", "0.001"), // https://www.bitmex.com/wallet/fees/spot
1045+
CommodityClass::Derivative => ("-0.000125", "0.000175"), // https://www.bitmex.com/wallet/fees/derivatives
10471046
}
10481047
CexExchange::Deribit =>
10491048
match trade_type {
1050-
SecuritiesClass::Spot => ("0.0", "0.0"), // https://www.deribit.com/kb/fees
1051-
SecuritiesClass::Derivative => ("-0.0001", "0.0005"), // https://www.deribit.com/kb/fees
1049+
CommodityClass::Spot => ("0.0", "0.0"), // https://www.deribit.com/kb/fees
1050+
CommodityClass::Derivative => ("-0.0001", "0.0005"), // https://www.deribit.com/kb/fees
10521051
}
10531052
CexExchange::Okex => ("-0.0001", "0.00015"), // https://tr.okx.com/fees
10541053
CexExchange::Coinbase =>
@@ -1061,14 +1060,14 @@ impl CexExchange {
10611060
},
10621061
CexExchange::Kraken =>
10631062
match trade_type {
1064-
SecuritiesClass::Spot => ("0.0", "0.001"), // https://www.kraken.com/features/fee-schedule#spot-crypto
1065-
SecuritiesClass::Derivative => ("0.0", "0.0001"), // https://www.kraken.com/features/fee-schedule#futures
1063+
CommodityClass::Spot => ("0.0", "0.001"), // https://www.kraken.com/features/fee-schedule#spot-crypto
1064+
CommodityClass::Derivative => ("0.0", "0.0001"), // https://www.kraken.com/features/fee-schedule#futures
10661065
},
10671066
CexExchange::BybitSpot =>
10681067
// https://www.bybit.com/en/help-center/article/Trading-Fee-Structure
10691068
match trade_type {
1070-
SecuritiesClass::Spot => ("0.00005", "0.00015"),
1071-
SecuritiesClass::Derivative => if USDC_ADDRESS == pair.0 || USDC_ADDRESS == pair.1 {
1069+
CommodityClass::Spot => ("0.00005", "0.00015"),
1070+
CommodityClass::Derivative => if USDC_ADDRESS == pair.0 || USDC_ADDRESS == pair.1 {
10721071
("0.0", "0.0001")
10731072
} else {
10741073
("0.0", "0.00025")
@@ -1077,7 +1076,7 @@ impl CexExchange {
10771076
CexExchange::Kucoin =>
10781077
// https://www.kucoin.com/vip/privilege
10791078
match trade_type {
1080-
SecuritiesClass::Spot =>
1079+
CommodityClass::Spot =>
10811080
if Self::KUCOIN_CLASS_C_BASE_COINS.iter().any(|a| pair.0 == *a) {
10821081
("-0.00005", "0.00075")
10831082
} else if Self::KUCOIN_CLASS_B_BASE_COINS.iter().any(|a| pair.0 == *a) {
@@ -1089,13 +1088,13 @@ impl CexExchange {
10891088
} else {
10901089
("-0.00005", "0.00025")
10911090
},
1092-
SecuritiesClass::Derivative => ("-0.00008", "0.00025"),
1091+
CommodityClass::Derivative => ("-0.00008", "0.00025"),
10931092
},
10941093
CexExchange::Upbit => ("0.0002", "0.0002"), // https://sg.upbit.com/service_center/guide
10951094
CexExchange::Huobi =>
10961095
match trade_type {
1097-
SecuritiesClass::Spot => ("0.000097", "0.000193"), // https://www.htx.com/zh-cn/support/360000312282
1098-
SecuritiesClass::Derivative => ("-0.00005", "0.0002"), // https://www.htx.com/zh-cn/support/360000113122
1096+
CommodityClass::Spot => ("0.000097", "0.000193"), // https://www.htx.com/zh-cn/support/360000312282
1097+
CommodityClass::Derivative => ("-0.00005", "0.0002"), // https://www.htx.com/zh-cn/support/360000113122
10991098
}
11001099
CexExchange::GateIo => ("0.0", "0.0002"), // https://www.gate.io/fee (curl, search for spot_feelist)
11011100
CexExchange::Bitstamp => ("0", "0.0003"), // https://www.bitstamp.net/fee-schedule/

crates/brontes-types/src/db/cex/trades/time_window_vwam.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::{
1717
};
1818
use crate::{
1919
constants::{USDC_ADDRESS, USDT_ADDRESS},
20-
db::cex::{CexExchange, SecuritiesClass},
20+
db::cex::{CexExchange, CommodityClass},
2121
normalized_actions::NormalizedSwap,
2222
pair::Pair,
2323
FastHashMap, FastHashSet,
@@ -308,7 +308,7 @@ impl<'a> TimeWindowTrades<'a> {
308308
let trades = walker.get_trades_for_window();
309309
for trade in trades {
310310
let trade = trade.get();
311-
let (m_fee, t_fee) = trade.exchange.fees(&pair, &SecuritiesClass::Spot);
311+
let (m_fee, t_fee) = trade.exchange.fees(&pair, &CommodityClass::Spot);
312312
let weight = calculate_weight(block_timestamp, trade.timestamp);
313313

314314
let (

0 commit comments

Comments
 (0)