Positions

This commit is contained in:
2026-07-25 01:57:27 +02:00
parent 2cbcdc7108
commit e61dd25e72
5 changed files with 54 additions and 7 deletions
+43 -1
View File
@@ -1,5 +1,6 @@
use std::sync::Arc;
use pulse_wire::terminal::ActivePosition;
use tokio::{sync::Mutex, task::JoinHandle};
use crate::{
@@ -41,12 +42,14 @@ impl Engine {
pub async fn run_broadcaster(&self) -> tokio::io::Result<()> {
let mut refresh = tokio::time::interval(tokio::time::Duration::from_secs(5));
let client = hypersdk::hypercore::mainnet();
loop {
refresh.tick().await;
let watch_list = &self.config.lock().await.watchlist.symbols;
match crate::fetch::fetch_watch_list(watch_list).await {
match crate::fetch::fetch_watch_list(&client, watch_list).await {
Ok(watch_list) => {
if let Err(error) = self
.terminal_server
@@ -75,6 +78,45 @@ impl Engine {
.await?
}
}
let accounts = self.accounts.lock().await;
if let Some(acc) = accounts.get_active() {
match client.clearinghouse_state(acc.address, None).await {
Ok(state) => {
self.terminal_server
.broadcast(
pulse_wire::terminal::TerminalServerMessage::PositionsUpdated(
state
.asset_positions
.into_iter()
.map(|position| ActivePosition {
symbol: position.position.coin,
size: position.position.szi.as_f64(),
entry_price: position
.position
.entry_px
.map(|px| px.as_f64())
.unwrap_or(0.0),
profit: position.position.unrealized_pnl.as_f64(),
})
.collect(),
),
)
.await?;
}
Err(e) => {
self.terminal_server
.error("orders", &format!("Unable to get open orders: {e}"))
.await?;
}
}
} else {
self.terminal_server.error(
"orders",
"Unable to get active account, make sure you have configured accounts properly",
).await?;
}
}
}