Skip to content

Commit

Permalink
liquidate positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel-Jacobsen committed Dec 19, 2023
1 parent 0245a81 commit e00b42d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/manifold_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum MarketOutcomeType {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct User {
/// from <https://docs.manifold.markets/api#get-v0users>
id: String,
pub id: String,

#[serde(rename = "createdTime")]
created_time: u64,
Expand Down
40 changes: 40 additions & 0 deletions src/market_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,46 @@ impl MarketHandler {
resp.json::<manifold_types::User>().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(), &params).await;

let bets = match bets_response {
Ok(bets_response) => bets_response
.json::<Vec<manifold_types::Bet>>()
.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,
Expand Down

0 comments on commit e00b42d

Please sign in to comment.