Created
November 8, 2020 05:28
-
-
Save jayhuang75/e1d98df74e59687c378c60ed52dd0c12 to your computer and use it in GitHub Desktop.
place_buy.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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