Advertisement
Guest User

btc-e script

a guest
Feb 17th, 2017
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var balance_btc = 0.4345, balance_usd = 0;
  2. var min_diff = 1;
  3. var last_bid_price = parseFloat($('#max_price').html());
  4. var last_ask_price = null;
  5. var is_selling = false;
  6.  
  7. sell(last_bid_price,balance_btc);
  8. setInterval(function(){
  9.     if(is_selling){
  10.         var curr_bid_price = parseFloat($('#max_price').html());
  11.         if((curr_bid_price-last_ask_price)>=min_diff){
  12.             is_selling = false;
  13.             sell(curr_bid_price,balance_btc);
  14.         }
  15.     }else {
  16.         var curr_ask_price = parseFloat($('#min_price').html());
  17.         if((curr_ask_price-last_bid_price)<=-min_diff){
  18.             is_selling = true;
  19.             buy(curr_ask_price,balance_usd);
  20.         }
  21.     }
  22.     console.log("BALANCE BTC: "+balance_btc+"\nBALANCE USD: "+balance_usd+"\nLAST BID PRICE: "+
  23.         last_bid_price+"\nLAST ASK PRICE: "+last_ask_price+"\n");
  24. },1000);
  25.  
  26. function sell(price, amount){
  27.     balance_btc = 0;
  28.     balance_usd = parseFloat((amount * price).toFixed(2));
  29.     last_bid_price = price;
  30.     $('#b_btc').val(amount);
  31.     $('#b_price').val(price);
  32.     ex_trade("sell",1);
  33. }
  34. function buy(price, amount){
  35.     balance_usd = 0;
  36.     balance_btc = parseFloat((amount / price).toFixed(8));
  37.     last_ask_price = price;
  38.     $('#s_btc').val(amount);
  39.     $('#s_price').val(price);
  40.     ex_trade("buy",1);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement