Sample random trade_infos for success (#4043)

Just looking at a single trade_info which may or may not succeed
can fail often.
This commit is contained in:
sakridge
2019-04-28 11:00:16 -07:00
committed by GitHub
parent acba1d6f9e
commit 4e5677f116
3 changed files with 6 additions and 1 deletions

1
Cargo.lock generated
View File

@ -2257,6 +2257,7 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -16,6 +16,7 @@ itertools = "0.8.0"
log = "0.4.6" log = "0.4.6"
num-traits = "0.2" num-traits = "0.2"
num-derive = "0.2" num-derive = "0.2"
rand = "0.6.5"
rayon = "1.0.3" rayon = "1.0.3"
serde = "1.0.87" serde = "1.0.87"
serde_derive = "1.0.87" serde_derive = "1.0.87"

View File

@ -3,6 +3,7 @@
use crate::order_book::*; use crate::order_book::*;
use itertools::izip; use itertools::izip;
use log::*; use log::*;
use rand::{thread_rng, Rng};
use rayon::prelude::*; use rayon::prelude::*;
use solana::cluster_info::FULLNODE_PORT_RANGE; use solana::cluster_info::FULLNODE_PORT_RANGE;
use solana::contact_info::ContactInfo; use solana::contact_info::ContactInfo;
@ -384,8 +385,9 @@ fn swapper<T>(
'outer: loop { 'outer: loop {
if let Ok(trade_infos) = receiver.try_recv() { if let Ok(trade_infos) = receiver.try_recv() {
let mut tries = 0; let mut tries = 0;
let mut trade_index = 0;
while client while client
.get_balance(&trade_infos[0].trade_account) .get_balance(&trade_infos[trade_index].trade_account)
.unwrap_or(0) .unwrap_or(0)
== 0 == 0
{ {
@ -399,6 +401,7 @@ fn swapper<T>(
} }
debug!("{} waiting for trades batch to clear", tries); debug!("{} waiting for trades batch to clear", tries);
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
trade_index = thread_rng().gen_range(0, trade_infos.len());
} }
trade_infos.iter().for_each(|info| { trade_infos.iter().for_each(|info| {