Skip to content

Commit

Permalink
Update drift-rs v1.0.0-alpha.3 (#87)
Browse files Browse the repository at this point in the history
Better debug msgs for missing market subs with --verbose
Make calculations just work when markets are not subscribed (fallback to network fetch)
  • Loading branch information
jordy25519 authored Oct 24, 2024
1 parent 577f709 commit 32b31af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "drift-gateway"
version = "1.1.0"
version = "1.1.1"
edition = "2021"

[dependencies]
actix-web = "*"
argh = "*"
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.2" }
drift-rs = { git = "https://github.com/drift-labs/drift-rs", tag = "v1.0.0-alpha.3" }
env_logger = "*"
futures-util = "*"
log = "*"
Expand Down
17 changes: 7 additions & 10 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,34 +335,31 @@ impl AppState {
let sub_account = self.resolve_sub_account(ctx.sub_account_id);
let user = self.client.get_user_account(&sub_account).await?;

let oracle_price = self
.client
.oracle_price(MarketId::perp(market.market_index))
.await?;
let perp_position = user
.perp_positions
.iter()
.find(|p| p.market_index == market.market_index && !p.is_available());

if let Some(perp_position) = perp_position {
let result = calculate_liquidation_price_and_unrealized_pnl(
let calc = calculate_liquidation_price_and_unrealized_pnl(
&self.client,
&user,
market.market_index,
)?;
)
.await?;
let unsettled_pnl = Decimal::from_i128_with_scale(
perp_position
.get_unrealized_pnl(oracle_price)
.get_unrealized_pnl(calc.oracle_price)
.unwrap_or_default(),
PRICE_DECIMALS,
);

let mut p: PerpPosition = (*perp_position).into();
p.set_extended_info(PerpPositionExtended {
liquidation_price: Decimal::new(result.liquidation_price, PRICE_DECIMALS),
unrealized_pnl: Decimal::new(result.unrealized_pnl as i64, PRICE_DECIMALS),
liquidation_price: Decimal::new(calc.liquidation_price, PRICE_DECIMALS),
unrealized_pnl: Decimal::new(calc.unrealized_pnl as i64, PRICE_DECIMALS),
unsettled_pnl: unsettled_pnl.normalize(),
oracle_price: Decimal::new(oracle_price, PRICE_DECIMALS),
oracle_price: Decimal::new(calc.oracle_price, PRICE_DECIMALS),
});

Ok(p)
Expand Down
17 changes: 10 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ async fn get_collateral(
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let config: GatewayConfig = argh::from_env();
let log_level = if config.verbose {
log::LevelFilter::Debug

let mut logger = env_logger::Builder::from_default_env();
if config.verbose {
logger
.filter_module(LOG_TARGET, log::LevelFilter::Debug)
.filter_module("rpc", log::LevelFilter::Debug)
} else {
log::LevelFilter::Info
};
env_logger::Builder::from_default_env()
.filter_module(LOG_TARGET, log_level)
.init();
logger.filter_module(LOG_TARGET, log::LevelFilter::Info)
}
.init();

let secret_key = std::env::var("DRIFT_GATEWAY_KEY");
let delegate = config
.delegate
Expand Down

0 comments on commit 32b31af

Please sign in to comment.