diff --git a/src/manifold_types.rs b/src/manifold_types.rs index 90e8124..c7e1303 100644 --- a/src/manifold_types.rs +++ b/src/manifold_types.rs @@ -71,7 +71,7 @@ pub enum MarketOutcomeType { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct User { /// from - id: String, + pub id: String, #[serde(rename = "createdTime")] created_time: u64, diff --git a/src/market_handler.rs b/src/market_handler.rs index acced60..023821a 100644 --- a/src/market_handler.rs +++ b/src/market_handler.rs @@ -215,6 +215,46 @@ impl MarketHandler { resp.json::().await.unwrap() } + pub async fn liquidate_all_positions(&self) -> Result<(), String> { + let me = self.whoami().await; + let params = [("userId".to_string(), me.id.clone())]; + + let bets_response = utils::get_endpoint("bets".to_string(), ¶ms).await; + + let bets = match bets_response { + Ok(bets_response) => bets_response + .json::>() + .await + .unwrap(), + Err(e) => { + error!("couldn't get bets: {e}"); + return Err(format!("couldn't get bets: {e}")); + } + }; + + for bet in bets { + let data = Some(serde_json::json!({ + "contractId": bet.contract_id, + "answerId": bet.answer_id, + })); + + let sell_response = utils::post_endpoint("sell-shares".to_string(), &[], data).await; + + match sell_response { + Ok(resp) => { + info!( + "successfully sold shares for bet {} contract id {} answer id {:?}", + bet.id, bet.contract_id, bet.answer_id + ); + debug!("full response {:?} for bet id {}", resp, bet.id); + } + Err(e) => error!("couldn't sell shares: {e}"), + }; + } + + Ok(()) + } + pub async fn market_search( &self, term: String,