Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. /**
  2. * @Route("/auto", name="auto")
  3. */
  4. public function auto(Request $request){
  5.  
  6. $market = $request->query->get('market');
  7. $total = floatval($request->query->get('total'));
  8.  
  9. $book = "https://bittrex.com/api/v1.1/public/getorderbook?market=$market&type=both&depth=50";
  10.  
  11. $book = json_decode(file_get_contents($book))->result->sell;
  12.  
  13. $sum = 0;
  14. $price = 0;
  15.  
  16. foreach($book as $k=>$v){
  17. $sum += floatval($v->Quantity)*floatval($v->Rate);
  18.  
  19. if($sum >= $total){
  20. $price = floatval($v->Rate);
  21. break;
  22. }
  23. }
  24.  
  25. $quantity = $total/$price;
  26.  
  27. echo "Q:$quantity P:$price";
  28.  
  29. $buy = "https://bittrex.com/api/v1.1/market/buylimit?apikey=API_KEY&market=$market&quantity=$quantity&rate=$price";
  30.  
  31.  
  32. $apikey='';
  33. $apisecret='';
  34. $nonce=time();
  35. $uri='https://bittrex.com/api/v1.1/'.$command.'?market='.$market.'&apikey='.$apikey.'&nonce='.$nonce."&quantity=$quantity&rate=$price";
  36. $sign=hash_hmac('sha512',$uri,$apisecret);
  37. $ch = curl_init($uri);
  38. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  39. curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
  40. $execResult = curl_exec($ch);
  41. $obj = json_decode($execResult);
  42.  
  43.  
  44. return new JsonResponse(array());
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement