Skip to content

Commit

Permalink
s/posty/internal_coms/g
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel-Jacobsen committed Dec 29, 2023
1 parent b47a0c3 commit d1dfaf1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/bots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ pub trait Bot {
async fn run(&mut self, rx: broadcast::Receiver<manifold_types::Bet>);
fn get_id(&self) -> String;
fn close(&self);
fn botbet_to_posty_packet(&self, bet: manifold_types::BotBet)
-> market_handler::InternalPacket;
fn botbet_to_internal_coms_packet(
&self,
bet: manifold_types::BotBet,
) -> market_handler::InternalPacket;
}

pub struct ArbitrageBot {
Expand Down Expand Up @@ -81,7 +83,7 @@ impl ArbitrageBot {
async fn make_bets(&mut self, bets: Vec<manifold_types::BotBet>) {
for bet in bets {
self.bot_to_mh_tx
.send(self.botbet_to_posty_packet(bet))
.send(self.botbet_to_internal_coms_packet(bet))
.await
.unwrap();

Expand Down Expand Up @@ -154,7 +156,7 @@ impl Bot for ArbitrageBot {
}
}

fn botbet_to_posty_packet(
fn botbet_to_internal_coms_packet(
&self,
bet: manifold_types::BotBet,
) -> market_handler::InternalPacket {
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ async fn run() {

info!("Found market {}", arb_market.lite_market.question);

let (bot_to_mh_tx, rx_bot) = market_handler.posty_init("bawt".to_string()).await.unwrap();
let (bot_to_mh_tx, rx_bot) = market_handler
.internal_coms_init("bawt".to_string())
.await
.unwrap();
let mut bot = ArbitrageBot::new("bawt".to_string(), arb_market.clone(), bot_to_mh_tx, rx_bot);

let rx = market_handler
Expand Down
34 changes: 17 additions & 17 deletions src/market_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,28 @@ impl MarketHandler {
) {
while !halt_flag.load(Ordering::SeqCst) {
// why a Option instead of a Result here?
let posty_packet = match bots_to_mh_rx.recv().await {
let internal_coms_packet = match bots_to_mh_rx.recv().await {
Some(packet) => packet,
None => continue,
};

debug!("got posty packet {:?}", posty_packet);
debug!("got internal_coms packet {:?}", internal_coms_packet);

let maybe_res = match posty_packet.method {
let maybe_res = match internal_coms_packet.method {
Method::Get => {
rate_limited_get_endpoint(
read_rate_limiter.clone(),
posty_packet.endpoint.clone(),
&posty_packet.query_params,
internal_coms_packet.endpoint.clone(),
&internal_coms_packet.query_params,
)
.await
}
Method::Post => {
rate_limited_post_endpoint(
write_rate_limiter.clone(),
posty_packet.endpoint.clone(),
&posty_packet.query_params,
posty_packet.data.clone(),
internal_coms_packet.endpoint.clone(),
&internal_coms_packet.query_params,
internal_coms_packet.data.clone(),
)
.await
}
Expand All @@ -182,17 +182,17 @@ impl MarketHandler {
Err(e) => {
error!("api error {e}");
let packet = InternalPacket::response_from_existing(
&posty_packet,
&internal_coms_packet,
format!("api error {e}"),
);

bot_out_channel
.lock()
.unwrap()
.get(&posty_packet.bot_id)
.get(&internal_coms_packet.bot_id)
.unwrap()
.send(packet)
.expect("couldn't send posty packet");
.expect("couldn't send internal_coms packet");

continue;
}
Expand All @@ -201,12 +201,12 @@ impl MarketHandler {
.await
.unwrap();

let bot_id = posty_packet.bot_id;
let bot_id = internal_coms_packet.bot_id;
let packet = InternalPacket {
bot_id: bot_id.clone(),
method: posty_packet.method,
endpoint: posty_packet.endpoint,
query_params: posty_packet.query_params,
method: internal_coms_packet.method,
endpoint: internal_coms_packet.endpoint,
query_params: internal_coms_packet.query_params,
data: None,
response: Some(res),
};
Expand All @@ -217,7 +217,7 @@ impl MarketHandler {
.get(&bot_id)
.unwrap()
.send(packet)
.expect("couldn't send posty packet");
.expect("couldn't send internal_coms packet");
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ impl MarketHandler {
/// bots send bets to the MarketHandler, and is many-to-one. The Reciever
/// channel is used by the MarketHandler to send the responses, and is
/// one-to-one. Each channel
pub async fn posty_init(
pub async fn internal_coms_init(
&mut self,
bot_id: String,
) -> Result<
Expand Down

0 comments on commit d1dfaf1

Please sign in to comment.