<script type="text/javascript" src="<?php echo base_url();?>/assets/js/bundle.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


<script type="text/javascript">
  // window.onload()
// let acted = function(){
// //   const options = {
// //   method: 'POST',
// //   headers: {
// //     'X-RapidAPI-Host': 'CoinMarketCapzakutynskyV1.p.rapidapi.com',
// //     'X-RapidAPI-Key': 'SIGN-UP-FOR-KEY'
// //   }
// // };

// let url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest",
// qString = "?CMC_PRO_API_KEY=" + apiKey + "&sort=market_cap&start=1&limit=10&cryptocurrency_type=tokens&convert=USD";

// fetch(url + qString, { mode: "no-cors" })
// .then(resp => {
// console.log(resp);
// // return resp.json();
// })
// .then(data => {
//   alert(data);
// console.log(data);
// });
// }();




//   let acted = function(){
//   const ws = new WebSocket('wss://stream.binance.com:9443/ws/!miniTicker@arr');
//   console.log(ws);


//   ws.onmessage = function (event) {
//     var data = JSON.parse(event.data);

//     var result = array();
//     // console.log(data['k']['h']);
//     // console.log(data['c']);
//      // $.ajax({
//      //  'method': 'POST',
//      //  'url': '<?php echo base_url("/update_high_price");?>',
//      //  data:{'price':data['k']['h']},
//      //  success:function(msg)
//      //  {
//      //    // var result = JSON.parse(msg);
//      //    console.log(msg['k']);
//      //    // console.log(result['k']['h']);
//      //  }
//      //  });
// }

// }();
</script>




<?php
$date = "2022-07-18";
$date = strtotime($date);
$seven_days = date('Y-m-d', strtotime('-7 days',$date));
$stepsize = "0.10000000";
$date = '2022-07-19 16:28:45';
$date1 = date('Y-m-d',strtotime($date));
$date2 = date('Y-m-d',time());
if($date1 == $date2)
   $output = 1;
else
  $output = 2;
echo"<pre>";
print_r($output);
echo"</pre>";
die;

$stepsize1 = fmod($stepsize, 1);
$total_no = str_replace('.', '', $stepsize1);
$count = strlen($total_no);

$now = time(); // or your date as well
$your_date = strtotime("2022-07-15");
$datediff = $now - $your_date;

echo round($datediff / (60 * 60 * 24));
die;


function truncate_number( $number, $precision = 2) {
    // Zero causes issues, and no need to truncate
    // if ( 0 == (int)$number ) {
    //  echo"<pre>";
    //  print_r("hi");
    //  echo"</pre>";
    //  die;
    //     return $number;
    // }
    // Are we negative?
    $negative = $number / abs($number);
    // Cast the number to a positive to solve rounding
    $number = abs($number);
    // Calculate precision number for dividing / multiplying
    $precision = pow(10, $precision);
    // Run the math, re-applying the negative value to ensure returns correctly negative / positive
  
    return floor( $number * $precision ) / $precision * $negative;
}

$result = truncate_number("0.0452145",$count);

echo"<pre>";
print_r($result);
echo"</pre>";
die;

// $json_url = "https://api.cryptonator.com/api/ticker/eth-btc";

//     $ch =  curl_init($json_url);
//         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//         curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//         curl_setopt($ch, CURLOPT_TIMEOUT, 3);
//         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
//         $payout_data = curl_exec($ch);
//         $json = json_decode($payout_data, true);

        // echo"<pre>";
        // print_r($json);
        // echo"</pre>";
        // die;

// $curl = curl_init();

// curl_setopt_array($curl, [
//   CURLOPT_URL => "",
//   CURLOPT_RETURNTRANSFER => true,
//   CURLOPT_FOLLOWLOCATION => true,
//   CURLOPT_ENCODING => "",
//   CURLOPT_MAXREDIRS => 10,
//   CURLOPT_TIMEOUT => 30,
//   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
//   CURLOPT_CUSTOMREQUEST => "POST",
//   CURLOPT_HTTPHEADER => [
//     "X-RapidAPI-Host: CoinMarketCapzakutynskyV1.p.rapidapi.com",
//     "X-RapidAPI-Key: SIGN-UP-FOR-KEY"
//   ],
// ]);

// $response = curl_exec($curl);
// $err = curl_error($curl);

// curl_close($curl);

// if ($err) {
//   echo "cURL Error #:" . $err;
// } else {
//   echo $response;
// }

// function bitquery ($abruf) {
// $data_string= json_encode($abruf);
// $ch = curl_init('https://graphql.bitquery.io/');                                                                      
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
// curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
//     'Content-Type: application/json',                                                                                
//     'X-API-KEY: BQYxoqeQVH5m0cYF5JfVmR3wEhQA6Hib'                                                                      
// ));                                                                                                                   
// $result = curl_exec($ch);  
// return $result;
// } 
// $token  =  "0x78867bbeef44f2326bf8ddd1941a4439382ef2a7";
// $token1 =  "0x7ef95a0fee0dd31b22626fa2e10ee6a223f8a684";

// $token  =  "0x55d398326f99059fF775485246999027B3197955";
// $token1 =  "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82";
// $cur_date = date('Y-m-d',time());

//           $arr=array( "query" => "{\n ethereum(network: bsc_testnet){\n dexTrades(options: {limit: 1, desc: \"timeInterval.minute\"},\n date: {since:\"$cur_date\"}\n exchangeName: {in:[\"Pancake\",\"Pancake v2\"]},\n baseCurrency: {is: \"$token\"},\n quoteCurrency: {is: \"$token1\"}){\n timeInterval {\n minute(count: 1)\n }\n baseCurrency {\n symbol\n address\n }\n baseAmount\n quoteCurrency {\n symbol\n address\n }\n quoteAmount\n trades: count\n quotePrice\n maximum_price: quotePrice(calculate: maximum)\n minimum_price: quotePrice(calculate: minimum)\n open_price: minimum(of: block get: quote_price)\n close_price: maximum(of: block get: quote_price)\n count tradeAmount(in:USD)}}\n }\n ");

//           $chart = bitquery($arr);

//           $result=json_decode($chart,true);

          // echo"<pre>";
          // print_r($result);
          // echo"</pre>";
          // die;


 // $json_url="https://api.cryptonator.com/api/ticker/usd-btc";
 //        $ch3 = curl_init();  
 //        curl_setopt($ch3,CURLOPT_URL,$url3);
 //        curl_setopt($ch3,CURLOPT_RETURNTRANSFER,true);
 //        $getdata=curl_exec($ch3);
 //        curl_close($ch3);
 //        $hash_details = json_decode($getdata,true);

//         $ch =  curl_init($json_url);
//         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//         curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//         curl_setopt($ch, CURLOPT_TIMEOUT, 3);
//         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
//         $payout_data = curl_exec($ch);
//         if (curl_errno($ch)) {
//     $error_msg = curl_error($ch);
//     echo"<pre>";
//     print("hi");
//     print_r($error_msg);
//     echo"</pre>";
//     die;
// }
//         curl_close($ch);

//         echo"<pre>";
//         print_r(json_decode($payout_data,1));
//         echo"</pre>";
//         die;

// $this->db = db_connect();


//   function spil_chk($spilover,$table,$memberid)
//     {
//       $db = db_connect();
//         $find_next=$db->query("select * from $table where uusersid='".$spilover."'")->getRow();
//         if($find_next)
//         {
//             $spilloverid=$find_next->uusersid;
//             $spilover=$find_next->spillover_id;  

//             if($spilloverid > 0)
//             {
//                 $members_cnt=$find_next->members_cnt;
                
//                 if($members_cnt=='' || $members_cnt=='0')
//                 {
//                     $member_ads=$memberid;
//                 }
//                 else
//                 {
//                     $member_ads=$members_cnt.",".$memberid; 
//                 }
//                 $db->query("update $table set members_cnt='".$member_ads."' where uusersid='".$spilloverid."'");
//                 spil_chk($spilover,$table,$memberid);
//             }
//         }
//     }

// $db = db_connect();
// $result = $db->table('uusers as t1,history as t2')->select('t1.uusersid as userid')->distinct('uusersid')->where('t2.uusersid = t1.uusersid')->where('t2.type','activation')->where('t2.status',1)->get()->getResult();

//   $new_res = $this->db->table('uusers_matrix')->get()->getResult();

//   foreach ($new_res as $key => $value) {
//    spil_chk($value->spillover_id,"uusers_matrix",$value->uusersid);
//   }

  // die;

        // $ch = curl_init();

        //   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        //   curl_setopt($ch, CURLOPT_URL,"https://api.binance.com/api/v3/ticker/price");
        //   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        //   $result=curl_exec ($ch);
        //   $getresponse = json_decode($result,true);
        //   curl_close ($ch);

        //   echo"<pre>";
        //   print_r($getresponse);
        //   echo"</pre>";
        //   die;


// namespace WebSocket;

// /**
//  * Class Server
//  * @author Jakub Pas
//  * @package WebSocket
//  */
// class Server
// {
//     private $host = 'wss://stream.binance.com';
//     private $port = 9943;
//     public function __construct($host, $port)
//     {
//         $this->host = $host;
//         $this->port = $port;
//         $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
//         socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);
//         socket_bind($sock, 0, $this->port);
//         socket_listen($sock);
//         $clients = array($sock);
        
//         while (true) {
//             $read = $clients;
//             if (socket_select($read, $write = null, $except = null, 0) < 1) {
//                 continue;
//             }
//             if (in_array($sock, $read)) {
//                 $clients[] = $newSocket = socket_accept($sock);
//                 $this->handShake($newSocket);
//                 socket_getpeername($newSocket, $ip);
//                 $this->send(array('type' => 'system', 'message' => $ip . ' Connected'), $clients);
//                 echo "New client connected: {$ip}\n";
//                 $key = array_search($sock, $read);
//                 unset($read[$key]);
//             }
//             foreach ($read as $read_sock) {
//                 while (socket_recv($read_sock, $buf, 1024, 0) >= 1) {
//                     $msg = json_decode($this->unmask($buf), true);
//                     $this->send($msg, $clients);
//                 }
//             }
//         }
//         socket_close($sock);
//     }
//     private function handShake($socket)
//     {
//         $header = socket_read($socket, 1024);
//         $headers = array();
//         $lines = preg_split("/\r\n/", $header);
//         foreach ($lines as $line) {
//             $line = chop($line);
//             if (preg_match('/\\A(\\S+): (.*)\\z/', $line, $matches)) {
//                 $headers[$matches[1]] = $matches[2];
//             }
//         }
//         $secKey = isset($headers['Sec-WebSocket-Key']) ? $headers['Sec-WebSocket-Key'] : '';
//         $secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
//         $upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . "Upgrade: websocket\r\n" . "Connection: Upgrade\r\n" . "WebSocket-Origin: {$this->host}\r\n" . "WebSocket-Location: ws:` {$this->host}:{$this->port}/shout.php\r\n" . "Sec-WebSocket-Accept:{$secAccept}\r\n\r\n";
//         socket_write($socket, $upgrade, strlen($upgrade));
//     }
//     /**
//      * Unmask incoming framed message
//      * @param $text
//      * @return string
//      */
//     public function unmask($text)
//     {
//         $length = ord($text[1]) & 127;
//         if ($length == 126) {
//             $masks = substr($text, 4, 4);
//             $data = substr($text, 8);
//         } elseif ($length == 127) {
//             $masks = substr($text, 10, 4);
//             $data = substr($text, 14);
//         } else {
//             $masks = substr($text, 2, 4);
//             $data = substr($text, 6);
//         }
//         $text = '';
//         for ($i = 0; $i < strlen($data); ++$i) {
//             $text .= $data[$i] ^ $masks[$i % 4];
//         }
//         return $text;
//     }
//     /**
//      * Encode message for transfer to client.
//      * @param $text
//      * @return string
//      */
//     public function mask($text)
//     {
//         $header = '';
//         $b1 = 0x80 | 0x1 & 0xf;
//         $length = strlen($text);
//         if ($length <= 125) {
//             $header = pack('CC', $b1, $length);
//         } elseif ($length > 125 && $length < 65536) {
//             $header = pack('CCn', $b1, 126, $length);
//         } elseif ($length >= 65536) {
//             $header = pack('CCNN', $b1, 127, $length);
//         }
//         return $header . $text;
//     }
//     public function read($buf)
//     {
//         $received_text = $this->unmask($buf);
//         return json_decode($received_text);
//     }
//     public function send($message, $clients)
//     {
//         $msg = $this->mask(json_encode($message));
//         foreach ($clients as $socket) {
//             @socket_write($socket, $msg, strlen($msg));
//         }
//         return true;
//     }
// }
// $host = 'wss://stream.binance.com';
// $port = 9943;
// $x = new Server($host,$port);

// test keys

$testkey    = "HMe6lwdRC4zYJgBQCpNyRhDBhZ599vAfIMypN2y40Jaig6eGOCqSvTDhn7PC3V34";
$testsecret = "rdb6STvzehRZGOl4lOyZtZFJvI2XQAGep49WRL8bg5KGZFVM4VcxesCT43SCBa12";

// echo"<pre>";
// print_r($x);
// echo"</pre>";
// die;
// $key = "sFlTSc2Y56NQpdTBcjFw2vxESWXyeWBozax5gP3CoRQx8n70XgPw960G2pQWUeFg";
// $secret = "BZZswPqHBAYkY9Oz8YQIe9afnqEmY6VxfJLF44TI8rNDDaB6EuyWa6cN3Hy32pQG";
$key    = "tJuR6dN9AZp9KiAn41avxq64KsyDxa8FIaRjxTf0k1qplZIv1MRnHrS3zQIqHuzZ";
$secret = "GlRLQS2VGYfa1sOUaS3NIgGmszJOAuxu7Xk0anY1r4ifRmGYVYxoG25LOBnESE67";

$key1    = "gxxSsPQWdAXtLc7h5l2lhipLfyxCJiq5ecX0PZT9rKZ6t5sNVRzuDtwqDhPPZxTO";
$secret1 = "9rQLyr46HnefZ24rKdEHtajtCNCeT6BMZJqAaR7fcUxU2ReFmT9pbbgCPYO3LQf7";

$key2    = "Qye7jPdhnEtbX8XByFTdmxCHccEZX4tqRixh8iLy0LS8Xg6749dD6jNTg5sktlrB";
$secret2 = "UweluVIi6KW1oPOXsxoTNkGcwWJjyN6ApelUp6U6gRQ2lTH5ldh1lNSIY4vED50j";

$key3    = "9lwWdJkjnylQfdMpx1c9nF4cDJnBAk8waYSIjPTpSJspcJNfxIK7pUQxpnHMD9VT";
$secret3 = "pkROvqmHXin0sT1k7B0NspsoXtQoXr1imrkEF0AaAxUdMjUXTGq8mUSDTwNe9qmt";

$key4    = "qq7lumIexjRFqBbQlneG68iciy28nI1Lrv9bDtHYYS6Cj7vOVLS4ReQLchkNWbQO";
$secret4 = "HkRDpT3e3PbVbY3tgosPnOcwMKuspVIprdHo1BHERaEyntqj3WV0bhTRduEmZgzW";


$key5    = "u5FisQNDZgMVeRNzZyLD1CMGQYD03lbbtwTb8W87L0FCoMjTYlzh1XUDWfBzcwVA";
$secret5 = "KyMTcukdNVCsUQYtv286pEhS6ChbYUclf6AdgxDlHPQ9ZNae8MLBoP0FuAaaKOz7";

$key6    = "v7DavD7LKlFkPAY4Vj6V4njhw3EsjL4aywn5oNp1zcLzWNm9xMdPttfk5sUyDJpI";
$secret6 = "vlvXzlMzC7qbgO51ilkev8vsrUy2XsH1ZETdqEO1FCF87sLg3rOavT1ShF88bqYv";

$key7 = "L1Gqyisx112oYQfAK0eZuDWYx20g1dDhCWm952BMUBRJKzX8SHzl4XFbEYbWolsV";
$secret7 = "sCGxwUEh8QtSrNyw6TOLB0eHDbn3PJFPLAEhd4HUmsUptfu1tNsb2x5ZiFz8UdCo";



//test key:
//   $key = "wcYWabBn1sHWzvVmYjwQrF8JMbh8ngCUW3oA1IbEJrghBgqmB1U9BMMQUGmU42hv";
// $secret = "1cSiCLlNnfKhcaX0wyIhXB1QLFtckdzKxR7Lqq2TlB0CQB31xdNoeGbwx39NjDra";

// $key = "Or6sOpYXXNMiareCRgLzp5Ma0mQ7gonaNNDg0yE4d4XUX0ObM8NVSvwiqBqJLkQX";
// $secret = "TppjuWrtw41TkyihPbrUY5nTR2sZlGn3ImyIWAKoXO3sjnPObqgOCWVwzcTAYtjR";

$testkey = "GBjPRpX5kqLsW5Usvz5BJUDVixIolEc8wSYYOb85w7SDVyBBoqGkvnVkDN2tq8tr";
$testsecret = "lYai9MeqZLBgsLAyPWpvzuIsNEZnNAz8zkvy7BcypmfP5ymV84vbNVGx0mORbMjc";
// $api = new Binance\API($key,$secret);
$this->db = db_connect();
$this->session = session();
  // $referral1=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$this->session->get('uusersid')."'");
  //       $ref=$referral1->getRow();
  //       $key = $ref->api_key;
  //       $secret = $ref->secret_key;
// $api = new Binance\API($testkey,$testsecret,true);
$api = new Binance\API($key7,$secret7);
// $marketpair = $api->prevDay();

// echo"<pre>";
// print_r($api->balance());
// echo"</pre>";
// die;
// $flags['isQuoteOrder'] = true;
// $result = $api->buy("BTCUSDT", '0.00049000');
// echo"<pre>";
// print_r($api->orders("MDXUSDT"));
// echo"</pre>";
// die;

// die;
// $orderid = "1649699672";
// $orderstatus = $api->orderStatus("SUNUSDT", "206882870");
// echo"<pre>";
// print_r($orderstatus);
// echo"</pre>";
// die;
// $trades = $api->orders("MDXUSDT");
// echo"<pre>";
// print_r($api->exchangeInfo("MDXUSDT"));
// echo"</pre>";
// die;
// $exchange_info = $api->openOrders();
// echo"<pre>";
// print_r($exchange_info);
// echo"</pre>";
// die;
// $order = $api->sell("LTCUSDT","2.41387",0,"MARKET");
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;

// $orders = $api->openorders('BNBUSDT');

// echo"<pre>";
// print_r($api->exchangeInfo('BNBUSDT'));
// echo"</pre>";
// die;

// echo"<pre>";
// print_r($orders);
// echo"</pre>";
$ticker = $api->prices(); 

$balances = $api->balances($ticker);
echo"<pre>";
print_r($balances);
echo"</pre>";
die;
// echo"<pre>";

// $order = $api->orderStatus("XRPUSDT","4532551744");


// if($order) { 
//           $buy_record_update = $this->db->table('trade_process')->set('flag','0')->where("id",$trade_process_id)->update();
//           $buy_record_update_c1 = $this->db->table('trade_process')->set('flag_buy','0')->where("id",$trade_process_id)->update();
//           $buy_record_update_c2 = $this->db->table('trade_process')->set('sell_limit','')->where("id",$trade_process_id)->update();
//           $buy_record_update_c3 = $this->db->table('trade_process')->set('buy_limit','')->where("id",$trade_process_id)->update();
//     $trade_process = $this->db->table('trade_process')->where('uusersid',$userid)->where('trade_status','1')->where('id',$trade_process_id)->get()->getRow();
//      $db = db_connect();
//      $admin_settings = $db->table('adminsettings')->orderBy('id','DESC')->get()->getRow();
//      $fuel_fee_percent = $admin_settings->min_fuel_fee;

//      if($subsell_status != 1)
//        $avg_price1 = $order['cummulativeQuoteQty'] - $avg_price->quantity; 
//        else
//        $avg_price1 = $order['cummulativeQuoteQty'] - $avg_price; 
//        $reverse_percent = 100 - $fuel_fee_percent;
//        $avg_price = $avg_price1 * ($reverse_percent / 100);
//        $comm_price = $avg_price1 * ($fuel_fee_percent / 100);

//        $profit1 = $avg_price / $order['cummulativeQuoteQty'];
//        $profit = $profit1 * 100;

//      $order_history = array(
//       'pair' => $pair,
//       'order_id' => $order['orderId'],
//       'trade_process_id' => $trade_process_id,
//       'uuserid' => $userid,
//       'type' => '2',
//       'quantity' => $order['cummulativeQuoteQty'],
//       ' original_quantity' => $order['cummulativeQuoteQty'],
//       'time' => $order['transactTime'],
//       'received_amount' => $order['executedQty'],
//       'live_price' => $stopPrice,
//       'avg_price' => $avg_price1,
//       'comm_price' => $comm_price,
//       'profit_percentage' => $profit,
//       'margin_call_drops' => $k,
//       'date' => date('Y-m-d',time()),
//       'strategy_mode' => $trade_process->strategy_mode,
//       'subsell_status' => $subsell_status,
//       'status' => 0,

//     );

//   echo"<pre>";
//   print_r("avg price ".$avg_price1);
//   print_r("comm price ".$comm_price);
//   print_r("profit percentage ".$profit);
//   print_r($order_history);
//   echo"</pre>";
//   die;
// }
// print_r($ticker);
// print_r($balances);
// echo"</pre>";
// echo"</pre>";
// print_r($api->orders("BTCUSDT"));
// echo"<pre>";
// die;
// $exchange_info = $api->exchangeInfo();

// echo"<pre>";
// print_r($ticker);

// print_r($trades);
// echo"</pre>";
// $trades = $api->orders("ADAUSDT");
// echo"<pre>";
// print_r($trades);
// echo"</pre>";
// die;

// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;


// die;

// $flags['isQuoteOrder'] = true;


// // $order = $api->buy("BTCUSDT","50",0,"MARKET");
// echo"<pre>";
// print_r($order['sapi']['code']);
// echo"</pre>";
// die;




$orders = $api->orders();



echo"<pre>";
print_r($orders);
echo"</pre>";



// $api->miniTicker(function($api, $ticker) {
//   print_r($ticker);
// });
// die;






// $i=0;
//   foreach ($exchange_info['symbols'] as $key => $value) {
//       if( strcasecmp( $value['symbol'], 'ADAUSDT' ) == 0){
//         $stepsize = $value['filters'][2]['stepSize'];
//       break;
//       }
//     }
// // $stepsize = explode('.', $stepsize)[1];
// $current = log(1.00000000, 0.1);

// $res = round("27.40000157",1);
// echo"<pre>";
// print_r($res);
// echo"</pre>";
// die;

// foreach ($stepsize as $key => $value) {
//   # code...
// }

// $prevdetails = $api->prevDay("LTCUSDT");
// echo"<pre>";
// print_r($prevdetails);
// echo"</pre>";
// die;

// $order = $api->buy("LTCUSDT","1","115");
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;





// $balance_update = function($api, $balances) {
//   print_r($balances);
//   echo "Balance update".PHP_EOL;
// };

// die;





// $order = $api->buy("MDXUSDT", "0.23", 1);

echo"<pre>";
print_r($order);
echo"</pre>";
die;

// $order = $api->marketQuoteBuy("SUNUSDT","11",$flags);
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;


// $ticks = $api->candlesticks("MDXUSDT", "5m");
// exit();




// $api->miniTicker(function($api, $ticker) {
//   print_r($ticker);
// });

// exit();

// $flags['isQuoteOrder'] = true;
// $order = $api->marketQuoteBuy("MDXUSDT", "12",$flags);
//     echo"<pre>";
//     print_r($order);
//     echo"</pre>";
//     die;


// die;


// When the stop is reached, a stop order becomes a market order
// $type = "STOP_LOSS_LIMIT"; // Set the type STOP_LOSS (market) or STOP_LOSS_LIMIT, and TAKE_PROFIT (market) or TAKE_PROFIT_LIMIT
// $quantity = 1.3;
// $price = 9; // Try to sell it for 0.5 btc
// $stopPrice = 8.15; // Sell immediately if price goes below 0.4 btc
// $order = $api->order("SELL","CAKEUSDT", $quantity, $price, $type, ["stopPrice"=>$stopPrice]);
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;

 // $trades = $api->historicalTrades('TRXUSDT',500);
 // echo"<pre>";
 // print_r($trades);
 // echo"</pre>";
 // die;
  // $ticker = $api->prices(); // Make sure you have an updated ticker object for this to work
  // echo"<pre>";
  // print_r($ticker);
  // echo"</pre>";
  // die;


// $balances = $api->balances($ticker);
// echo"<pre>";
// print_r($balances);
// // print_r($order);
// echo"</pre>";
// die;





// 
// die;
// // echo"<pre>";
// // print_r($trades);
// // print_r($balances);
// // print_r($ticker);
// // echo"</pre>";
// // die;

// $quantity = 1;
// $price = 300;
// // $order = $api->buy("BNBUSDT", $quantity, $price);
// // echo"<pre>";
// // print_r($order);
// // echo"</pre>";
// $order1 = $api->sell("BNBUSDT",$quantity,$price);
// echo"<pre>";
// print_r($order1);
// echo"</pre>";
// die;

// $order = $api->sell("TRXUSDT","0.06","300")
// $id = "TRXUSDT";
// $quantity = 13;
 

//           echo"<pre>";
//           print_r($getresponse[0]->price);
//           echo"</pre>";
//           die;


//                     echo"<pre>";
//                     print_r($calbtc);
//                     echo"</pre>";
//                     die;
//                     $quantity = $calbtc * $quantity; 
//                     echo"<pre>";
//                     print_r($quantity);
//                     echo"</pre>";
//                     die;
// $flags['isQuoteOrder'] = true;

// $order = $api->sell("TRXUSDT","183.6",0,"MARKET");
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;

$balances = $api->balances($ticker);
echo"<pre>";
print_r($balances);
echo"</pre>";
die;

$order = $api->marketQuoteSell("BNBUSDT","12","350","LIMIT",$flags);
echo"<pre>";
print_r($order);
echo"</pre>";
$trades = $api->orders("TRXUSDT");
echo"<pre>";
print_r($trades);
echo"</pre>";
die;
$balances = $api->balances($ticker);
echo"<pre>";
print_r($balances);
echo"</pre>";
die;
// die;
$exchangeInfo = $api->exchangeInfo();
// echo"<pre>";
// print_r($exchangeInfo);
// echo"</pre>";
// die;

// echo"<pre>";
// print_r($balances);
// echo"</pre>";
// die;
// echo"<pre>";
// print_r($balances);
// echo"</pre>";
// die;
// // die;
// $trades1 = $api->exchangeInfo();
// echo"<pre>";
// print_r($trades1);
// echo"</pre>";

// // die;
// $order = $api->sell("XEMUSDT","194",0,"MARKET");
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;


// $trades = $api->orders("REEFUSDT");
// echo"<pre>";
// print_r($trades);
// echo"</pre>";
// die;
// $ticks = $api->candlesticks("BTCUSDT", "1m");
// echo"<pre>";
// print_r($ticks);
// echo"</pre>";
// die;
// $api->chart(["LTCUSDT"], "15m", function($api, $symbol, $chart) {
//   echo "{$symbol} chart update\n";
//   echo"<pre>";
//   print_r($chart);
//   echo"</pre>";
// });
$api->kline(["BTCUSDT", "EOSBTC"], "5m", function($api, $symbol, $chart) {
  //echo "{$symbol} ({$interval}) candlestick update\n";
  $interval = $chart->i;
  $tick = $chart->t;
  $open = $chart->o;
  $high = $chart->h;
  $low = $chart->l;
  $close = $chart->c;
  $volume = $chart->q; // +trades buyVolume assetVolume makerVolume
  echo "{$symbol} price: {$close}\t volume: {$volume}\n";
});
die;
$orders = $api->orders("LTCUSDT");
echo"<pre>";
print_r($orders);
echo"</pre>";
die;

// $ticker = $api->history("TRXUSDT"); // Make sure you have an updated ticker object for this to work
// $openorders = $api->openOrders("BNBUSDT");

// $balances = $api->balances($ticker);
// $total_asset = $balances['USDT']['available'];
// echo"<pre>";
// print_r();
// echo"</pre>";
// die;
// $quantity = 1;
// $price = 500;
// $order = $api->marketBuyTest("XRPUSDT", 1);
// echo"<pre>";
// print_r($order);
// echo"</pre>";
// die;
// $prevdetails = $api->prevDay();
// $balances = $api->balances('BNB');
// $ticker = $api->prices(); // Make sure you have an updated ticker object for this to work
// $balances = $api->balances($ticker);
// print_r($balances);
// echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL;
// echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL;
// echo "Estimated Value: ".$api->btc_value." BTC".PHP_EOL;
// die;

// $ticker = $api->prices(); // Make sure you have an updated ticker object for this to work
// $balances = $api->balances();
// print_r($balances);
// die;
// echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL;
// echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL;
// echo "Estimated Value: ".$api->btc_value." BTC".PHP_EOL;
// die;

// $marketpair = $api->prevDay();
// $i=0;
// foreach ($marketpair as $key => $value) {

//   if(substr($value['symbol'], -4) == "USDT"){
//       $output[$i]['symbol'] = $value['symbol'];
//       $output[$i]['price'] = $value['lastPrice'];
//       $output[$i]['change'] = $value['priceChangePercent'];
//       $i++;
//   }
// }

// $i=0;
// echo "<pre>";
// print_r($prevdetails);
// echo "</pre>";
// die;
// foreach ($marketpair as $key => $value) {

//   if(substr($key, -4) == "USDT"){
//       $output[$i]['symbol'] = $value;
//       $prevdetails = $api->prevDay($key);
//       $output[$i]['change'] = $prevdetails['priceChangePercent'];
//       $i++;
//   }
// }
// $exchangeInfo = $api->exchangeInfo();
// $results = [];
// $outputs = [];
// $j=0;
// foreach($exchangeInfo['symbols'] as $info) {
//     $results[] = $info;      // or maybe baseAsset or maybe both
//     }
 
//     foreach ($results as $key => $value) {
//     	if(substr($value['symbol'], -4) == "USDT" && count($value['permissions']) == 2){
//             $outputs[] = $value;
//             echo"<pre>";
// print_r($outputs);
// print_r($api->price("BTCUSDT"));
// print_r($api->prevDay("BTCUSDT"));
// echo"</pre>";
// die;
//             // $outputs['live_price'] = $api->price($value['symbol'];
//     	}
//     	$j++;
//     }

    // foreach ($outputs as $key => $value) {
    // 	echo"<pre>";
    // 	print_r($va);
    // 	echo"</pre>";
    // 	die;
    // 	$price = $api->price($value['symbol']);     
    // }
// json_response($results);

?>