Skip to content

Commit

Permalink
fix typo on poloautos, implement bittrex auto buy, add bittrex automa…
Browse files Browse the repository at this point in the history
…tion to Cargo as bin
  • Loading branch information
dallyshalla committed Feb 26, 2017
1 parent c896970 commit 9d57904
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ path = "apps/poloautobuy.rs"
name = "poloautosell"
path = "apps/poloautosell.rs"

[[bin]]
name = "bittrexautobuy"
path = "apps/bittrexautobuy.rs"

[lib]
name = "tropix"
path = "src/lib.rs"
Expand Down
98 changes: 98 additions & 0 deletions apps/bittrexautobuy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
extern crate tropix;
extern crate rustc_serialize;
extern crate time;

use tropix::bittrex::bittrex::*;

use rustc_serialize::{Decodable, Decoder};
use rustc_serialize::json::{self, ToJson, Json};

use std::io;
use std::io::Read;
use std::thread::sleep;
use std::time::Duration;
use std::io::{BufRead};

fn main() {

let pair_vec = vec!["SEC", "ETH", "MAID", "ETC"];

println!("Enter Your Bittrex Api Key");
let mut input1 = String::new();
let stdin1 = io::stdin();
stdin1.lock().read_line(&mut input1).unwrap();

let next_string = &input1.trim_right_matches("\n");

let the_api_key = &next_string;
//secret Key
println!("Enter Your Bittrex Secret Key");
let mut input2 = String::new();
let stdin2 = io::stdin();
stdin2.lock().read_line(&mut input2).unwrap();

let the_secret_trimmed = input2.trim_right_matches("\n");

let mut intd = 0;
for pair in &pair_vec {
println!("{:?}, : {:?}", intd, pair);
intd += 1;
}

let firstcoin = "BTC".to_string();

println!("choose a currency to trade by its index., enter the number before the currency you want to trade");
let mut input5 = String::new();
let stdin5 = io::stdin();
stdin5.lock().read_line(&mut input5).unwrap();

let pair_ind = input5.trim_right_matches("\n");

let pair_ind2: usize = pair_ind.parse().ok().expect("currency index is not a number");

let secondcoin = pair_vec[pair_ind2];

println!("Enter a maximum position limit in the alt coin quantity \n the bot will buy only up to this much at a time");
let mut input3 = String::new();
let stdin3 = io::stdin();
stdin3.lock().read_line(&mut input3).unwrap();

let maxposition = input3.trim_right_matches("\n").to_string();
let position_clone = maxposition.clone().parse().ok().expect("max position turned out to not be a number either");


println!("Enter a buy frequency in seconds a value of 60 will mean 1 minute");
let mut input4 = String::new();
let stdin4 = io::stdin();
stdin4.lock().read_line(&mut input4).unwrap();

let frequency = input4.trim_right_matches("\n").to_string();

let frequency: u64 = frequency.parse().ok().expect("frequency is not a number");

println!("pair {} / {}", &firstcoin, &secondcoin);
println!("max position {}", &maxposition);
println!("frequency {} seconds", &frequency);
let mut xyz = 0;
while xyz == 0 {


let order_book = get_orderbook(&the_secret_trimmed, &firstcoin, &secondcoin, "500");
for sell in order_book.sell {

if sell.Quantity > position_clone {
let the_trade = buy_limit(&the_api_key, &the_secret_trimmed, &firstcoin, &secondcoin, &position_clone.to_string(), &sell.Rate.to_string());
println!("bought {}, {}", position_clone, the_trade);
break;
} else {
let the_trade = buy_limit(&the_api_key, &the_secret_trimmed, &firstcoin, &secondcoin, &sell.Quantity.to_string(), &sell.Rate.to_string());
println!("bought {}, {}", &sell.Quantity, the_trade);
break;
}
}

let the_seconds = Duration::new(frequency, 0);
sleep(the_seconds);

}
}
2 changes: 1 addition & 1 deletion apps/poloautobuy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn main() {
stdin3.lock().read_line(&mut input3).unwrap();

let maxposition = input3.trim_right_matches("\n").to_string();
let postion_clone = maxposition.clone();
let position_clone = maxposition.clone();


println!("Enter a buy frequency in seconds a value of 60 will mean 1 minute");
Expand Down
4 changes: 2 additions & 2 deletions apps/poloautosell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn main() {
stdin3.lock().read_line(&mut input3).unwrap();

let maxposition = input3.trim_right_matches("\n").to_string();
let postion_clone = maxposition.clone();
let position_clone = maxposition.clone();


println!("Enter a buy frequency in seconds a value of 60 will mean 1 minute");
Expand Down Expand Up @@ -114,7 +114,7 @@ fn main() {
let timespec = time::get_time();
let mut mills = timespec.sec * 100;

if bids_results[0].1 < postion_clone.parse().ok().expect("max position turned out to not be a number either") {
if bids_results[0].1 < position_clone.parse().ok().expect("max position turned out to not be a number either") {
if margin_ind == 0 {
sell(the_api_keyclone.to_string(), the_secret_trimmed, pair_vec[pair_ind2].to_string(), bids_results[0].0.to_string(), bids_results[0].1.to_string(), mills.to_string());
} else {
Expand Down

0 comments on commit 9d57904

Please sign in to comment.