Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update drift-rs v1.0.0-alpha.3 #87

Merged
merged 1 commit into from
Oct 24, 2024
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
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
Loading