Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var balance_btc = 0.4345, balance_usd = 0;
- var min_diff = 1;
- var last_bid_price = parseFloat($('#max_price').html());
- var last_ask_price = null;
- var is_selling = false;
- sell(last_bid_price,balance_btc);
- setInterval(function(){
- if(is_selling){
- var curr_bid_price = parseFloat($('#max_price').html());
- if((curr_bid_price-last_ask_price)>=min_diff){
- is_selling = false;
- sell(curr_bid_price,balance_btc);
- }
- }else {
- var curr_ask_price = parseFloat($('#min_price').html());
- if((curr_ask_price-last_bid_price)<=-min_diff){
- is_selling = true;
- buy(curr_ask_price,balance_usd);
- }
- }
- console.log("BALANCE BTC: "+balance_btc+"\nBALANCE USD: "+balance_usd+"\nLAST BID PRICE: "+
- last_bid_price+"\nLAST ASK PRICE: "+last_ask_price+"\n");
- },1000);
- function sell(price, amount){
- balance_btc = 0;
- balance_usd = parseFloat((amount * price).toFixed(2));
- last_bid_price = price;
- $('#b_btc').val(amount);
- $('#b_price').val(price);
- ex_trade("sell",1);
- }
- function buy(price, amount){
- balance_usd = 0;
- balance_btc = parseFloat((amount / price).toFixed(8));
- last_ask_price = price;
- $('#s_btc').val(amount);
- $('#s_price').val(price);
- ex_trade("buy",1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement