Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created November 8, 2020 05:28
Show Gist options
  • Select an option

  • Save jayhuang75/e1d98df74e59687c378c60ed52dd0c12 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/e1d98df74e59687c378c60ed52dd0c12 to your computer and use it in GitHub Desktop.
place_buy.rs
// get the buy point
// buy action
async fn try_to_buy(&mut self, diff: f32) -> Result<f32, Box<dyn Error>> {
if diff >= self.trading_config.upward_trend_threshold
|| diff <= self.trading_config.dip_threshold {
let current_balance = self.get_balances().await?;
info!(
"[BALANCE] current account balance {:?} $ USD",
current_balance
);
self.trading_config.last_operation_price = self.place_buy_order(current_balance).await?;
// set to the next action to sell
self.trading_config.next_operation = State::SELL;
info!(
"[BUY] Bought 0.002 BTC for {:?} $ USD",
self.trading_config.last_operation_price
);
}
Ok(self.trading_config.last_operation_price)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment