Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel-Jacobsen committed Dec 11, 2023
1 parent 8644636 commit 98c7e0a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/bots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use log::{debug, info, warn};
use tokio::sync::broadcast::Receiver;

use crate::manifold_types;
use crate::market_handler;

#[async_trait]
pub trait Bot {
Expand Down Expand Up @@ -44,6 +45,25 @@ impl ArbitrageBot {
}
tot_prob
}

fn bet_amount(&self) -> f64 {
let mut bet_map: HashMap<String, manifold_types::BotBet> = HashMap::new();
let inverse_sum: f64 = self.answers.values().map(|a| 1.0 / a.probability).sum();

for answer in self.answers.values() {
let bb = manifold_types::BotBet {
amount: 100. * (1. / answer.probability) / inverse_sum,
contract_id: self.market.lite_market.id.clone(),
outcome: manifold_types::MarketOutcome::Other(answer.id.clone()),
};
bet_map.insert(answer.id.clone(), bb);
};
info!("BET MAP{:?}", bet_map);

assert!((bet_map.values().map(|bb| bb.amount).sum::<f64>() - 100.).abs() < 1e-5, "sum of bets {} != 100", bet_map.values().map(|bb| bb.amount).sum::<f64>());

0.
}
}

#[async_trait]
Expand All @@ -57,6 +77,7 @@ impl Bot for ArbitrageBot {
} else {
info!("NOT ARB OPPORTUNITY {tot_prob}");
}
self.bet_amount();

let mut i: u64 = 0;
loop {
Expand Down Expand Up @@ -93,6 +114,8 @@ impl Bot for ArbitrageBot {
info!("NOT ARB OPPORTUNITY {tot_prob}");
}

self.bet_amount();

i += 1;
}
Err(e) => {
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ async fn main() {

assert!(market_handler.check_alive().await, "Manifold API is down");

let whoami = market_handler.whoami().await;
let me = market_handler.whoami().await;

info!("Logged in as {} (balance {})", whoami.name, whoami.balance);
info!("Logged in as {} (balance {})", me.name, me.balance);

let arb_market = {
let market = market_handler
.market_search("How many Twitter followers will @Mira have? (unlinked)".to_string());
.market_search("Which video game confirmed for released in Q1 2024 will average the highest score on Opencritic.com by 4/1/24?".to_string());

match market.await {
Ok(market) => market,
Expand All @@ -39,7 +39,7 @@ async fn main() {
serde_json::to_string_pretty(&arb_market).unwrap()
);

let mut bot = ArbitrageBot::new(arb_market.clone());
let mut bot = ArbitrageBot::new(me.clone(), arb_market.clone());

let rx = market_handler
.get_bet_stream_for_market_id(arb_market.lite_market.id)
Expand Down

0 comments on commit 98c7e0a

Please sign in to comment.