<!-- <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>

<html lang="en">
<?php 
use App\Helpers\site_helper;
$validation =  \Config\Services::validation();
$this->db = db_connect();
$this->session = session();
$uusersid = $this->session->get('uusersid');
$uri = service('uri');
$this->common_model = model('CommonModel');
$this->session->set('pair',$id);
$base_curr = substr($this->session->get('pair'), 0,-4);

$buy_bal=curbalance($uusersid);


   
 $tradSets = $this->common_model->GetResults('adminsettings','');
 $tradSet = $tradSets[0];
 // $fuel_amount1 = $this->db->query("SELECT SUM(amount)as amt from history where type IN('fuel','bonus') AND  status='1' and uusersid ='".$this->session->get('uusersid')."'")->getRow();
 // $fuel_amount2 = $this->db->query("SELECT SUM(amount)as amt from history where type = ('penalty') AND  status='1' and uusersid ='".$this->session->get('uusersid')."'")->getRow();


if(!isset($this->data) && empty($this->data)) {
        $activation =  $this->db->query("SELECT * FROM history WHERE type='activation' and uusersid='".$uusersid."' AND status='1' ")->getRow();
        $bind_api =$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."'")->getRow();


        if(!empty($bind_api))
         $bind_api = true;
        else
         $bind_api = false;

        if(!empty($b))
        if($activation)
        {
   $activation = true;
        }
        else
        {
        $activation = false;
        }
          // get trading settings
}
echo view('user/common_style1');?>
</head>

<style type="text/css">
.form-switch .form-check-input {
width: 55px;
height: 22px;
}
.input-group>:not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: -1px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    margin-bottom: 4px;
}
</style>

<link rel="stylesheet" href="<?php echo base_url('styles/css/table.css');?>">

    <style type="text/css">
.table-responsive {
    overflow-x: visible !important;
}
 @media only screen and (max-width:768px){
.buysell-table,#DataTables_Table_0_wrapper{
  overflow: auto !important;
  overflow-y: hidden !important; 
}
}
.next_border{
  border-right: 1px solid #e7e8ea !important;
}
table tr th {
    background: #203c9d none repeat scroll 0 0;
    color: #fff;
    font-size: 13px;
    font-weight: 300;
    padding: 16px 20px;
    text-align: left;
    text-transform: capitalize;
    white-space: nowrap;
}
input[type="text"], input[type="email"], input[type="password"], input[type="search"] {
    background-color: #fff;
    border: 1px solid #e1e1e1;
    color: #000;
    font-size: 14px;
    height: 42px;
    margin: 5px 0;
    padding: 10px 7px 10px 10px;
    width: 100%;
}
    </style>

<body>
<?php
     $uusersid =$this->session->get("uusersid");
        $referral1=$this->db->query("SELECT * FROM bind_process WHERE uusersid='".$uusersid."'");
        $ref=$referral1->getRow();
        $key = $ref->api_key;
        $secret = $ref->secret_key;
if(empty($ref)){
      $key = "tJuR6dN9AZp9KiAn41avxq64KsyDxa8FIaRjxTf0k1qplZIv1MRnHrS3zQIqHuzZ";
      $secret = "GlRLQS2VGYfa1sOUaS3NIgGmszJOAuxu7Xk0anY1r4ifRmGYVYxoG25LOBnESE67";
      $api = new Binance\API($key,$secret);
      $marketpair = $api->prevDay($id);
      $output['symbol'] = $marketpair['symbol'];
      $output['price'] = $marketpair['lastPrice'];
      $output['change'] = $marketpair['priceChangePercent'];
}else{
      $api = new Binance\API($key,$secret);
      $marketpair = $api->prevDay($id);
      $output['symbol'] = $marketpair['symbol'];
      $output['price']  = $marketpair['lastPrice'];
      $output['change'] = $marketpair['priceChangePercent'];
    }

    $live_price = $output['price'];
    $pair =$this->db->query("SELECT * FROM trade_process WHERE uusersid='".$uusersid."' and pair ='".$id."' and trade_status != 2 order by id desc")->getRow();
    $manual_buy = $this->db->table('api_manual_trade')->where('trade_process_id',$pair->id)->where('type',1)->where('status','1')->get()->getRow();
    $manual_sell = $this->db->table('api_manual_trade')->where('trade_process_id',$pair->id)->where('type',2)->where('status','1')->get()->getRow();


if(!empty($pair)) { 

        $api_trade_data = array(
          'trade_process_id' => $pair->id,
          'uuserid' => $uusersid,
          'type' => '1',
          'status' => 0
        );

        $api_trade_data1 = array(
          'trade_process_id' => $pair->id,
          'uuserid' => $uusersid,
          'type' => '2',
          'description' => 'manual_sell'
        );

        $api_trade_data2 = array(
          'trade_process_id' => $pair->id,
          'uuserid' => $uusersid,
          'type' => '1',
          'margin_call_drops != ' => 0
        );

         $profit_where = array(
            'uuserid' => $uusersid,
            'type' => '3',
            'trade_process_id' => $pair->id,
            'status' => 0
        );


       

      //   $current_buy = $this->db->table('api_trade_history')->where($api_trade_data)->get()->getResult();
      //           $total_amount_bought = 0;

      //   if(!empty($current_buy)){        
      //   foreach ($current_buy as $key => $value) {
      //         $total_amount_bought1 = $value->received_amount * $value->quantity;
      //         $total_amount_bought = $total_amount_bought + $total_amount_bought1;
      //   }
      // }
  if($pair->strategy_mode == 1){
        $total_contract = $this->db->table('api_trade_history')->selectSum('received_amount')->where($api_trade_data)->get()->getRow();
        $total_usdt  = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data)->get()->getRow();
        if($total_contract->received_amount && $total_usdt->quantity)
          $avg_position_amount = $total_usdt->quantity / $total_contract->received_amount;
        else
          $avg_position_amount = 0;
  }else{
        if($pair->strategy_mode == 3) {
        $total_contract = $this->db->table('api_trade_history')->selectSum('received_amount')->where($api_trade_data)->where('margin_call_drops <=',4)->get()->getRow();
        $total_usdt = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data)->where('margin_call_drops <=',4)->get()->getRow();
        if($total_contract->received_amount && $total_usdt->quantity)
          $avg_position_amount = $total_usdt->quantity / $total_contract->received_amount;
        else
          $avg_position_amount = 0;
      }else{
        $total_contract = $this->db->table('api_trade_history')->selectSum('received_amount')->where($api_trade_data)->where('margin_call_drops <=',4)->get()->getRow();
        $total_usdt = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data)->where('margin_call_drops <=',4)->get()->getRow();
        $total_contract2 = $this->db->table('api_trade_history')->selectSum('received_amount')->where($profit_where)->get()->getRow();
        $total_contract = $total_contract->received_amount + $total_contract2->received_amount;
        $total_usdt2 = $this->db->table('api_trade_history')->selectSum('quantity')->where($profit_where)->get()->getRow();
        $total_usdt = $total_usdt->quantity + $total_usdt2->quantity;
        if($total_contract && $total_usdt)
          $avg_position_amount = $total_usdt / $total_contract;
        else
          $avg_position_amount = 0;
      }
      }
    
      




        if($pair->strategy_mode == 1){
        $last_call_drop = $this->db->table('api_trade_history')->where($api_trade_data)->orderBy('id','DESC')->get()->getRow();
        $last_average = $avg_position_amount;
        }
        else{
        
        $last_call_drop = $this->db->table('api_trade_history')->where($api_trade_data2)->where('margin_call_drops <=',4)->orderBy('id','DESC')->get()->getRow();
        if(empty($last_call_drop) || $last_call_drop == 0)
        $last_call_drop = $this->db->table('api_trade_history')->where($api_trade_data)->where('description','first_buy')->orderBy('id','DESC')->get()->getRow();
        $last_average = $avg_position_amount;
        }

       

 
  

        $avg_price = round($last_average,8) * $pair->whole_profit_ratio / 100;

              $max_increase_price = $last_average + $avg_price ;
              
              $max_increase_price = round($max_increase_price,8);

              $max_down_percentage = $max_increase_price * $pair->whole_profit_callback / 100;

              $max_down_price = $max_increase_price - $max_down_percentage;

              $max_down_price = round($max_down_price,8);

              $tradeupdate['take_profit_trigger'] = "> ".number_format($max_increase_price,5);

              $trade_where_new = array(
                  'uuserid' => $uusersid,
                  'type' => '1',
                  'status' => 0,
                  'trade_process_id' => $pair->id,
              );

       $last_buy_recheck = $this->db->table('api_trade_history')->where($trade_where_new)->orderBy('margin_call_drops','DESC')->get()->getRow();
       $last_margin_call_drop = $last_buy_recheck->margin_call_drops;

              // if($last_call_drop->margin_call_drops == "")
              //       $next_call = 0;
              // else
              //       $next_call = $last_call_drop->margin_call_drops;  

      
       

        $call_perc = explode(',', $pair->margincall_drop)[$last_margin_call_drop];

        if(empty($last_call_drop)){

        }

        $tradeupdate['margin_call_drops'] = $call_perc;

        $price_down = $last_call_drop->live_price * $call_perc / 100;

        $down_price = $last_call_drop->live_price - $price_down;

        $tradeupdate['down_price']  = "< ".number_format($down_price,5);

        $total_position_amount = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data)->get()->getRow();
        $total_sell_amount = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data1)->get()->getRow();

      

        $total_position_amount->quantity = $total_position_amount->quantity - $total_sell_amount->quantity;


        $tradeupdate['current_position_amount'] = $last_call_drop->quantity;
   
              $total_position_quantity = $this->db->table('api_trade_history')->selectSum('received_amount')->where($api_trade_data)->get()->getRow();
        $total_sell_quantity = $this->db->table('api_trade_history')->selectSum('received_amount')->where($api_trade_data1)->get()->getRow();
        $total_position_quantity->received_amount = $total_position_quantity->received_amount - $total_sell_quantity->received_amount;

        if ($total_position_amount->quantity > 0) {
          
          $tradeupdate['trade_position_amount'] = number_format($total_position_amount->quantity,5);  
        }else{
          $tradeupdate['trade_position_amount'] = 0.00;
        }

            if ($total_position_quantity->received_amount > 0) {

        $tradeupdate['trade_position_quantity'] = number_format($total_position_quantity->received_amount,5);

          }else{

          $tradeupdate['trade_position_quantity'] = 0.00;

        }
        
      //   $avg_position_amount = $this->db->table('api_trade_history')->selectAvg('live_price')->where($api_trade_data)->get()->getRow();

      //   $total_contract = $this->db->table('api_trade_history')->selectSum('received_amount')->where($api_trade_data)->get()->getRow();

      //   $current_buy = $this->db->table('api_trade_history')->where($api_trade_data)->get()->getResult();
      //           $total_amount_bought = 0;

      //   if(!empty($current_buy)){        
      //   foreach ($current_buy as $key => $value) {
      //         $total_amount_bought1 = $value->received_amount * $value->quantity;
      //         $total_amount_bought = $total_amount_bought + $total_amount_bought1;
      //   }
      // }
        
      //   $avg_position_amount = $total_amount_bought / $total_contract->received_amount ;

                 // $avg_position_amount = $this->db->table('api_trade_history')->selectAvg('live_price')->where($api_trade_data)->get()->getRow();

        if ($avg_position_amount > 0) {
          $tradeupdate['trade_avg_position'] = number_format($avg_position_amount,5);
        }else{
          $tradeupdate['trade_avg_position'] = 0.00;
        }

        $call_drop = $this->db->table('api_trade_history')->where($api_trade_data2)->where('margin_call_drops !=',0)->orderBy('id','DESC')->get()->getRow();
        if($call_drop->margin_call_drops == $trade_process->margin_column_limit){
            $tradeupdate['down_price'] = "Limit Reached";
            $tradeupdate['margin_call_drops'] = "0";
        }

        
    
        if ($call_drop->margin_call_drops != '' || $call_drop->margin_call_drops != '0') {
          $tradeupdate['trade_number_of_call'] = $call_drop->margin_call_drops;
        }else{
          $tradeupdate['trade_number_of_call'] = '0';
        }

            $api_trade_data = array(
            'trade_process_id' => $pair->id,
            'uuserid' => $uusersid,
            'type' => '1',
          );

          $tradeupdate['live_price'] = $live_price;
          // $first_buy =  $this->db->table('api_trade_history')->where($api_trade_data)->like('description','first_buy')->get()->getRow();


          // $first_buy_live_price = $first_buy->live_price;

          if($avg_position_amount == 0 &&  $tradeupdate['trade_position_amount'] == 0){
            $check_percentage = '0';
          }

          else if ($avg_position_amount > $live_price) {
            
            // echo "first_buy = ".$first_buy_live_price.'  -  ';
            // echo "live_price  = ".$live_price;
            // echo "<br>";
            // echo "decrease";
            
            $check_percentage = ($avg_position_amount - $live_price);
            $check_percentage = $check_percentage  / $avg_position_amount;
            $check_percentage = $check_percentage  * 100 ;
            $check_percentage = '-'.number_format($check_percentage,2).'%';
          }elseif ($avg_position_amount == $live_price) {
            
            // echo "first_buy = ".$avg_position_amount.'  -  ';
            // echo "live_price  = ".$live_price;
            // echo "<br>";

            // echo "same";
            $check_percentage = '0';
          }else{
            
            // echo "first_buy = ".$avg_position_amount.'  -  ';
            // echo "live_price  = ".$live_price;
            // echo "<br>";

            // echo "increase";
            $check_percentage = $live_price - $avg_position_amount;
            $check_percentage = $check_percentage  / $live_price;
            $check_percentage = $check_percentage  * 100 ;
          }

          $tradeupdate['trade_rate_percentage'] = number_format($check_percentage,2).'%';



          if ($avg_position_amount > $live_price) {
            
            // echo "first_buy = ".$avg_position_amount.'  -  ';
            // echo "live_price  = ".$live_price;
            // echo "<br>";
            // echo "decrease";
            
          $check_percentage1 = ($avg_position_amount - $live_price) / $avg_position_amount;
          $check_percentage1 = $check_percentage1  * 100 ;
                $check_percentage1 = '-'.number_format($check_percentage1,2).'%';
          }elseif ($avg_position_amount == $live_price) {
            
            // echo "first_buy = ".$avg_position_amount.'  -  ';
            // echo "live_price  = ".$live_price;
            // echo "<br>";

            // echo "same";
            $check_percentage1 = '0.00';
          }else{
            // echo "first_buy = ".$avg_position_amount.'  -  ';
            // echo "live_price  = ".$live_price;
            // echo "<br>";

            // echo "increase";
            $check_percentage1 = ($live_price - $avg_position_amount) / $live_price;
            $check_percentage1 = $check_percentage1  * 100 ;
          }


          $tradeupdate['trade_estimate_price'] = number_format($check_percentage1,2).'%';
          

                            $total_sell_amount = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data1)->get()->getRowArray();
$total_position_amount1 = $this->db->table('api_trade_history')->selectSum('quantity')->where($api_trade_data)->get()->getRowArray();

$total_position_amount = $total_position_amount1['quantity'] - $total_sell_amount['quantity'];
$total_position_amount = number_format($total_position_amount,4);

$tradeupdate['trade_remain_amount'] = $tradeupdate['trade_position_amount'];

// if($tradeupdate['trade_estimate_price'] > 0){
//   $trade_remain_pending  = ($tradeupdate['trade_position_amount'] * $tradeupdate['trade_estimate_price'])/100;;
//   $tradeupdate['trade_remain_amount'] = $tradeupdate['trade_position_amount'] + $trade_remain_pending;
// }else{
//     $trade_remain_pending  = ($tradeupdate['trade_position_amount'] * $tradeupdate['trade_estimate_price'])/100;
//     $tradeupdate['trade_remain_amount'] = $tradeupdate['trade_position_amount'] - $trade_remain_pending;
// }
}

  echo view('user/common_header');
?>

<section class="bg-primary inner-bg">
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-4">
        <div class="d-lg-flex">
          <div class="crypto-ico bg-white icon-square"> <img src="<?php echo base_url('/styles/images/tradingpair_images/'.$output['symbol'].'.png');?>" class="img-fluid"> </div>
          <div class="crypto-title">
            <h6 class="text-white text-uppercase fw-light mont"><?php echo $output['symbol'];?></h6>
            <a href="" class="btn btn-info"><span id="crypto-strategy">Cycle Strategy</span></a> <a href="" id="crypto-strategy_mode" class="btn btn-info">Sub-bin mode </a> </div>
        </div>
      </div>
      <div class="col-lg-8">
        <div class="inner-head-btn">

   <button type="button" class="btn btn-outline-primary" class="btn btn-primary waves-effect waves-light" data-bs-toggle="modal" data-bs-target="#staticBackdrop" >First Preset Start Price</button>

          <button type="button" id="exampleModal1_clr" class="btn btn-outline-primary" data-bs-toggle="modal" data-bs-target="#exampleModal1" data-bs-whatever="@fat">Transaction settings </button>
    <?php 
    if(!empty($pair)) {
        if($pair->trade_status == 0) { 
     ?>
             <button type="button" id="start_button" class="btn btn-success">Resume</button>
           <?php } else  if($pair->trade_status == 1) { ?>
          <button type="button" id="pause_button" class="btn btn-outline-primary">Pause</button>
        <?php } else if($pair->trade_status == 2) { ?>
          <button type="button" id="start_button" class="btn btn-success">Start</button>
        <?php } 
   if($pair->trade_status == 0 || $pair->trade_status == 1) { ?>
<button type="button" id="stop_button" class="btn btn-danger">Stop</button>
  <?php }   

      }
         else { ?>
<button type="button" id="start_button" class="btn btn-success">Start</button>
      <?php } ?>
          <button type="button" class="btn btn-outline-primary" data-bs-toggle="modal" data-bs-target="#exampleModal4" id="logModal" data-bs-whatever="@getbootstrap">Log</button>
        </div>
      </div>
    </div>
  </div>
</section>
<?php 

$qury = $this->db->query("SELECT * FROM trade_process WHERE uusersid='".$uusersid."' AND  pair = '".$output['symbol']."' and trade_status != 2 ")->getResult();
$qry=$qury[0];


if(!$qry)
{
$qury = $this->db->query("SELECT * FROM user_strategy WHERE uusersid='".$uusersid."'")->getResult();
$qry=$qury[0];
}
?>
<form class="modal fade" id="exampleModal1" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" method="post" action="<?php echo base_url().'/tradedetails/'.$id;?>" enctype="multipart/form-data">
 <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Transaction Setting</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
   
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-3">
            <div class="modal-form mb-4">
              <label class="">First order amount</label>
              <input type="text" class="form-control mt-1" placeholder="" name="first_buy_amount" id="first_buy_amount" value="<?php echo $qry->first_buy_amount;?>">
            </div>
             <div class="modal-form mb-4">
              <label class="">Double open position</label>
            <div class="form-check form-switch form-switch-lg mb-3" dir="ltr">
            <input type="checkbox" class="form-check-input" data-on-text="<?php echo $on?>" data-off-text="<?php echo $off; ?>" data-on-color="primary" data-off-color="default" name="open_position_doubled" <?php if($qry->open_position_doubled==='on'){ echo 'checked="checked"'; } ?>>
            </div>
            </div>
            <div class="modal-form mb-4">
              <label class="">Replenishment times</label>
              <input type="text" class="form-control mt-1" id="replenishment_time" name="replenishment_time" placeholder="" value="<?php echo $qry->margin_column_limit;?>">
            </div>
            <div class="modal-form mb-4">
              <label class="">Whole position take profit ratio</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="whole_profit_ratio" value="<?php echo $qry->whole_profit_ratio;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
            <div class="modal-form mb-4">
              <label class="">Whole position take profit Callback</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="whole_profit_callback" value="<?php echo $qry->whole_profit_callback;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
            
                <div class="modal-form mb-4">
              <label class="">Buy in callback</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="buyin_callback" value="<?php echo $qry->buyin_callback;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
            <div class="modal-form mb-4" id="subposition">
              <label class="">Sub-Position take-profit callback</label>
              <div class="input-group">
                <input type="text" class="form-control mt-1" placeholder="" name="sub_position_callback" value="<?php echo $qry->sub_position_callback;?>">
                <span class="input-group-text mt-1">% </span> </div>
            </div>
          </div>
          <div class="col-lg-6">
            <div class="modal-head">
              <h6 class="mont">Margin Configuration</h6>
            </div>
            <div class="row">
              <div class="col-lg-6">
                <div class="modal-head">
                  <h5 class="text-black mont">Margin Call drop</h5>
                </div>

                  <span id="ex_demo1"></span>

              </div>
              <div class="col-lg-6">
                <div class="modal-head">
                  <h5 class="text-black mont">Multiply Buy in ratio</h5>
                </div>

                <span id="ex_demo2"></span>

              </div>
            </div>
          </div>
          <div class="col-lg-3">
            <div class="modal-head">
              <h6 class="mont">Distributed and take profit Allocation</h6>
              <h5 class="text-black mont">Percentage of spilt-to-profit</h5>
            </div>
            <span id="ex_demo"></span>
          </div>
        </div>
      </div>
      <div class="modal-footer" style="float:left;">
        <button type="submit" class="btn btn-primary" name="strategy" value="strategy">Get a Suggested Strategy</button>
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" id="submit_button" class="btn btn-primary" name="sub" value="sub">Submit</button>
      </div>
    </div>
  </div>
</form>


<div class="modal fade" id="exampleModal4" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Log</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
          <div id="logModals"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>



<section class="bg-white pb-5">
  <div class="container-fluid">
       <div class="row">
            <div class="col-lg-12">
              <ul class="buysell-list list-unstyled ps-0 mb-0 text-center bg-white inner-box">
                <li>
                  <h6 id="trade_position_amount" ><?php echo $tradeupdate['trade_position_amount'] ? $tradeupdate['trade_position_amount'] : 0;?></h6>
                  <span class="color-1">Position amount(USDT)</span> </li>
                  <li>
                    <h6 id="trade_avg_position" ><?php echo $tradeupdate['trade_avg_position'] ? $tradeupdate['trade_avg_position'] : 0;?></h6>
                    <span class="color-1">Average position price</span> </li>
                    <li>
                      <h6 id="trade_number_of_call"><?php echo $tradeupdate['trade_number_of_call'] ? $tradeupdate['trade_number_of_call'] : 0;?></h6>
                      <span class="color-1">Numbers of call margin</span> 
                    </li>
          <li>
<h6 id="trade_position_quantity"><?php echo $tradeupdate['trade_position_quantity'] ? $tradeupdate['trade_position_quantity'] : 0;?></h6>
            <span class="color-1">Position quantity(<?php echo substr($id,0,-4);?>)</span> </li>
            <li> 
              <h6 class="all_list_price"><?php if(intval($output['price']) > 999) 
              echo number_format($output['price'],2);
              else
               echo number_format($output['price'],5);?></h6>
             <span class="color-1">Current Price</span> </li>
             <li>
              <h6 id="trade_rate_percentage"><?php echo $tradeupdate['trade_rate_percentage'] ? $tradeupdate['trade_rate_percentage'] : 0;?></h6>
              <span  class="color-1">Rate of return</span> </li>
            </ul>
          </div>
        </div>
    <div class="row">
      <div class="col-lg-4">
        <div class="buysell-con bg-white inner-box mt-3">
          <h6 class="color-2 position-relative">Operation reminder</h6>
          <p class="color-1">When the tradingbot intelligent robot is operating, please do not operate the currency account by yourself, and check whether there are related settings such as fixed deposit, freezing, etc., so as to avoid abnormal judgments caused by the system and affect your rights and interests.</p>
        </div>
      </div>
      <div class="col-lg-8">
<?php if($qry->strategy_mode == 1) { ?>
        <div class="buysell-link bg-white inner-box mt-3">
          <ul class="ps-0 list-unstyled mb-0">
            <li id="Cstartegy" style="cursor: pointer;" ><a onclick="doalert(this); return false";>
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico1.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0"  id="Cstartegy_Name">Cycle Strategy</h6>
                  <span class="color-1">Switch to One-shot strategy</span> </div>
              </div>
              </a></li>

              <li id="Ostartegy"  style="display: none;cursor: pointer;"><a onclick="Ooalert(this); return false";>
              <div class="d-md-flex">
              <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico1.png" class="img-fluid me-2"></div>
              <div>
              <h6 class="color-2 mb-0" id="Ostartegy_Name">One-shot strategy</h6>
              <span class="color-1">Switch to Cycle strategy</span> </div>
              </div>
              </a></li>

           <li style="cursor: pointer;">
<?php 
if(!empty($pair) && $pair->trade_status != 2)
{
?>
  <a href="" id="sell_popup" data-bs-toggle="modal" data-bs-target="#SellModal" data-bs-whatever="@fat">
  <div class="d-md-flex">
  <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico2.png" class="img-fluid me-2"></div>
  <div>
  <h6 class="color-2 mb-0">Sell</h6>
  <span class="color-1">Sell all currencies in hand </span> </div>
  </div>
  </a>
<?php
}
else
{
?>
  <a id="sellModels" data-bs-whatever="@fat">
  <div class="d-md-flex">
  <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico2.png" class="img-fluid me-2"></div>
  <div>
  <h6 class="color-2 mb-0">Sell</h6>
  <span class="color-1">Sell all currencies in hand </span> </div>
  </div>
  </a>
<?php
}
?>
</li>
<li style="cursor: pointer;"> 

<?php 
if(!empty($pair) &&  $pair->trade_status != 2)
{
?>
<a href="" id="buy_popup" data-bs-toggle="modal" data-bs-target="#BuyModal" data-bs-whatever="@fat">
<div class="d-md-flex">
<div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico3.png" class="img-fluid me-2"></div>
<div>
<h6 class="color-2 mb-0">Buy</h6>
<span class="color-1">When locked up,you can<br>
Take a one-click to cover <br>
the position
</span>
</div>
</div>
</a>
<?php
}
else
{
?>
<a id="buyModels" >
<div class="d-md-flex">
<div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico3.png" class="img-fluid me-2"></div>
<div>
<h6 class="color-2 mb-0">Buy</h6>
<span class="color-1">When locked up,you can<br>
Take a one-click to cover <br>
the position
</span>
</div>
</div>
</a>
<?php
}
?>

</li>
            <li style="cursor: pointer;"> <a id="Margin_Clk">
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico4.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0 smc"  id="mc" >Stop margin call</h6>
                </div>
              </div>
              </a></li>
            <li> <a href="" href="" data-bs-toggle="modal" data-bs-target="#staticBackdrop1" data-bs-whatever="@fat"  >
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico5.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0">Strategy mode</h6>
                </div>
              </div>
              </a></li>
        <li id="oneshot_limit_section" style="display: none;"> <a href="" href="" data-bs-toggle="modal" data-bs-target="#staticBackdrop2" data-bs-whatever="@fat"  >
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico5.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0">Oneshot hit</h6>
                </div>
              </div>
              </a></li>
          </ul>
        </div>
        <?php if(!empty($manual_buy)) { ?>
          <div class="buysell-table bg-white inner-box mt-3">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <tr>

                  <td> Buy </td>
                  <td><a style="float: right;" href="javascript:void(0);" onclick="javascript:cancel(<?php echo $manual_buy->id;?>);" >Cancel an order</a></td>

                </tr>
           <!--      <tr>
                  <td> First preset start price </td>
                  <td> 0 </td>
                  <td></td>
                  <td></td>
                </tr> -->
                <tr>
                  <td> Trigger price </td>
                  <td> <?php echo "<=".$manual_buy->trigger_price;?></td>
                  <td> Amount of margin call </td>
                  <td> <?php echo $manual_buy->amount;?> </td>
                </tr>
                
              </tbody>
            </table>
          </div>
        </div>
      <?php } ?>
       <?php if(!empty($manual_sell)) { ?>
          <div class="buysell-table bg-white inner-box mt-3">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <tr>

                  <td> Sell</td>
                   <td><a style="float: right;" href="javascript:void(0);" onclick="javascript:cancel(<?php echo $manual_sell->id;?>);" >Cancel an order</a></td>
                </tr>
           <!--      <tr>
                  <td> First preset start price </td>
                  <td> 0 </td>
                  <td></td>
                  <td></td>
                </tr> -->
                <tr>
                  <td> Trigger price </td>
                  <td> <?php echo ">=".$manual_sell->trigger_price;?> </td>
                  <td> Amount of margin call </td>
                  <td> <?php echo $manual_sell->amount;?> </td>
                </tr>
                
              </tbody>
            </table>
          </div>
        </div>
      <?php } ?>
        <div class="buysell-table bg-white inner-box mt-3">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <tr>
                  <td> Transaction Overview </td>
                </tr>
           <!--      <tr>
                  <td> First preset start price </td>
                  <td> 0 </td>
                  <td></td>
                  <td></td>
                </tr> -->
                <tr>
                  <td> First order amount </td>
                  <td> <?php echo $trade_process->first_buy_amount ? $trade_process->first_buy_amount : 0;?> </td>
                  <td> Margin call limit </td>
                  <td> <?php echo $trade_process->margin_column_limit ? $trade_process->margin_column_limit : 0;?> </td>
                </tr>
                <tr>
                  <td> Take profit ratio </td>
                  <td> <?php echo $trade_process->whole_profit_ratio ? $trade_process->whole_profit_ratio."%" : "0%";?> </td>
                  <td> Take profit Callback </td>
                  <td> <?php echo $trade_process->whole_profit_callback ? $trade_process->whole_profit_callback."%" : "0%";?>  </td>
                </tr>
                <tr>
                  <td> Margin call drop </td>
            <td><?php echo $tradeupdate['margin_call_drops'] ? $tradeupdate['margin_call_drops']."%" : "0%";?>  </td>
                  <td> Sub Position Call back </td>
                  <td><?php echo $trade_process->sub_position_callback ? $trade_process->sub_position_callback."%" : "0%";?> </td>
                </tr>
            <tr>
                  <td> Call Margin Trigger Price </td>
            <td><span id="down_price"><?php echo $tradeupdate['down_price'] ? $tradeupdate['down_price'] : " ";?></span></td>
                  <td> Take Profit Trigger Price </td>
                  <td><span id="take_profit_trigger"><?php echo $tradeupdate['take_profit_trigger'] ? $tradeupdate['take_profit_trigger'] : " ";?></span></td>
                </tr>
                <tr>
                  <td> Status </td>
                  <td><span id="margin_status"><?php echo $trade_process->margin_call ? "Waiting For Trigger" : "Stop Margin Call";?></span></td>
                  <td> Buy In Call Back</td>
                  <td><?php echo $trade_process->buyin_callback ? $trade_process->buyin_callback."%" : "0 %";?></td>
                </tr>
               <!--  <tr>
                  <td> Margin trigger price </td>
                  <td> 2.075 </td>
                  <td> Take Profit Trigger Price </td>
                  <td> 2.075 </td>
                </tr>
                <tr>
                  <td> Margin call drop </td>
                  <td> 4.00% </td>
                  <td></td>
                  <td></td>
                </tr> -->
              </tbody>
            </table>
          </div>
        </div>
    <?php } else { ?>
          
              <div class="pair-tab" style="margin-top: 14px;">
              <div class="trading-tab">
              <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
              <li class="nav-item" role="presentation">
                <button class="nav-link active" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="false">Strategy Information</button>
              </li>
        <li class="nav-item" role="presentation">
          <button class="nav-link" id="pills-sell-tab" data-bs-toggle="pill" data-bs-target="#pills-sell" type="button" role="tab" aria-controls="pills-sell" aria-selected="false">Sub-ware house</button>
              </li>
            </ul>
          </div>
        </div>
         <div class="tab-content trading-mar" id="pills-tabContent">
         <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
          <div class="buysell-link bg-white inner-box mt-3">
          <ul class="ps-0 list-unstyled mb-0">
            <li id="Cstartegy" style="cursor: pointer;" ><a onclick="doalert(this); return false";>
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico1.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0"  id="Cstartegy_Name">Cycle Strategy</h6>
                  <span class="color-1">Switch to One-shot strategy</span> </div>
              </div>
              </a></li>

              <li id="Ostartegy"  style="display: none;cursor: pointer;"><a onclick="Ooalert(this); return false";>
              <div class="d-md-flex">
              <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico1.png" class="img-fluid me-2"></div>
              <div>
              <h6 class="color-2 mb-0" id="Ostartegy_Name">One-shot strategy</h6>
              <span class="color-1">Switch to Cycle strategy</span> </div>
              </div>
              </a></li>

           <li style="cursor: pointer;">
<?php 
if(!empty($pair) && $pair->trade_status != 2)
{
?>
  <a href="" id="sell_popup" data-bs-toggle="modal" data-bs-target="#SellModal" data-bs-whatever="@fat">
  <div class="d-md-flex">
  <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico2.png" class="img-fluid me-2"></div>
  <div>
  <h6 class="color-2 mb-0">Sell</h6>
  <span class="color-1">Sell all currencies in hand </span> </div>
  </div>
  </a>
<?php
}
else
{
?>
  <a id="sellModels" data-bs-whatever="@fat">
  <div class="d-md-flex">
  <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico2.png" class="img-fluid me-2"></div>
  <div>
  <h6 class="color-2 mb-0">Sell</h6>
  <span class="color-1">Sell all currencies in hand </span> </div>
  </div>
  </a>
<?php
}
?>
</li>
<li style="cursor: pointer;"> 

<?php 
if(!empty($pair) &&  $pair->trade_status != 2)
{
?>
<a href="" id="buy_popup" data-bs-toggle="modal" data-bs-target="#BuyModal" data-bs-whatever="@fat">
<div class="d-md-flex">
<div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico3.png" class="img-fluid me-2"></div>
<div>
<h6 class="color-2 mb-0">Buy</h6>
<span class="color-1">When locked up,you can<br>
Take a one-click to cover <br>
the position
</span>
</div>
</div>
</a>
<?php
}
else
{
?>
<a id="buyModels" >
<div class="d-md-flex">
<div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico3.png" class="img-fluid me-2"></div>
<div>
<h6 class="color-2 mb-0">Buy</h6>
<span class="color-1">When locked up,you can<br>
Take a one-click to cover <br>
the position
</span>
</div>
</div>
</a>
<?php
}
?>

</li>
            <li style="cursor: pointer;"> <a id="Margin_Clk">
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico4.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0 smc"  id="mc" >Stop margin call</h6>
                </div>
              </div>
              </a></li>
            <li> <a href="" href="" data-bs-toggle="modal" data-bs-target="#staticBackdrop1" data-bs-whatever="@fat"  >
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico5.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0">Strategy mode</h6>
                </div>
              </div>
              </a></li>
        <li id="oneshot_limit_section" style="display: none;"> <a href="" href="" data-bs-toggle="modal" data-bs-target="#staticBackdrop2" data-bs-whatever="@fat"  >
              <div class="d-md-flex">
                <div><img src="<?php echo base_url();?>/styles/new_style/images/buysell-ico5.png" class="img-fluid me-2"></div>
                <div>
                  <h6 class="color-2 mb-0">Oneshot hit</h6>
                </div>
              </div>
              </a></li>
          </ul>
        </div>
        <?php if(!empty($manual_buy)) { ?>
          <div class="buysell-table bg-white inner-box mt-3">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <tr>

                  <td> Buy </td>
                  <td><a style="float: right;" href="javascript:void(0);" onclick="javascript:cancel(<?php echo $manual_buy->id;?>);" >Cancel an order</a></td>

                </tr>
           <!--      <tr>
                  <td> First preset start price </td>
                  <td> 0 </td>
                  <td></td>
                  <td></td>
                </tr> -->
                <tr>
                  <td> Trigger price </td>
                  <td> <?php echo "<=".$manual_buy->trigger_price;?></td>
                  <td> Amount of margin call </td>
                  <td> <?php echo $manual_buy->amount;?> </td>
                </tr>
                
              </tbody>
            </table>
          </div>
        </div>
      <?php } ?>
       <?php if(!empty($manual_sell)) { ?>
          <div class="buysell-table bg-white inner-box mt-3">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <tr>

                  <td> Sell</td>
                   <td><a style="float: right;" href="javascript:void(0);" onclick="javascript:cancel(<?php echo $manual_sell->id;?>);" >Cancel an order</a></td>
                </tr>
           <!--      <tr>
                  <td> First preset start price </td>
                  <td> 0 </td>
                  <td></td>
                  <td></td>
                </tr> -->
                <tr>
                  <td> Trigger price </td>
                  <td> <?php echo ">=".$manual_sell->trigger_price;?> </td>
                  <td> Amount of margin call </td>
                  <td> <?php echo $manual_sell->amount;?> </td>
                </tr>
                
              </tbody>
            </table>
          </div>
        </div>
      <?php } ?>
        <div class="buysell-table bg-white inner-box mt-3">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <tr>
                  <td> Transaction Overview </td>
                </tr>
           <!--      <tr>
                  <td> First preset start price </td>
                  <td> 0 </td>
                  <td></td>
                  <td></td>
                </tr> -->
                <tr>
                  <td> First order amount </td>
                  <td> <?php echo $trade_process->first_buy_amount ? $trade_process->first_buy_amount : 0;?> </td>
                  <td> Margin call limit </td>
                  <td> <?php echo $trade_process->margin_column_limit ? $trade_process->margin_column_limit : 0;?> </td>
                </tr>
                <tr>
                  <td> Take profit ratio </td>
                  <td> <?php echo $trade_process->whole_profit_ratio ? $trade_process->whole_profit_ratio."%" : "0%";?> </td>
                  <td> Take profit Callback </td>
                  <td> <?php echo $trade_process->whole_profit_callback ? $trade_process->whole_profit_callback."%" : "0%";?>  </td>
                </tr>
                <tr>
                  <td> Margin call drop </td>
            <td><?php echo $tradeupdate['margin_call_drops'] ? $tradeupdate['margin_call_drops']."%" : "0%";?>  </td>
                  <td> Sub Position Call back </td>
                  <td><?php echo $trade_process->sub_position_callback ? $trade_process->sub_position_callback."%" : "0%";?> </td>
                </tr>
            <tr>
                  <td> Call Margin Trigger Price </td>
            <td><span id="down_price"><?php echo $tradeupdate['down_price'] ? $tradeupdate['down_price'] : " ";?></span></td>
                  <td> Take Profit Trigger Price </td>
                  <td><span id="take_profit_trigger"><?php echo $tradeupdate['take_profit_trigger'] ? $tradeupdate['take_profit_trigger'] : " ";?></span></td>
                </tr>
                <tr>
                  <td> Status </td>
                  <td><span id="margin_status"><?php echo $trade_process->margin_call ? "Waiting For Trigger" : "Stop Margin Call";?></span></td>
                  <td> Buy In Call Back</td>
                  <td><?php echo $trade_process->buyin_callback ? $trade_process->buyin_callback."%" : "0 %";?></td>
                </tr>
               <!--  <tr>
                  <td> Margin trigger price </td>
                  <td> 2.075 </td>
                  <td> Take Profit Trigger Price </td>
                  <td> 2.075 </td>
                </tr>
                <tr>
                  <td> Margin call drop </td>
                  <td> 4.00% </td>
                  <td></td>
                  <td></td>
                </tr> -->
              </tbody>
            </table>
          </div>
        </div>
         </div>
         <div class="tab-pane fade" id="pills-sell" role="tabpanel" aria-labelledby="pills-sell-tab">
          <?php

          $trade_where = array(
              'uuserid' => $uusersid,
              'type' => '1',
              'status' => 0,
              'trade_process_id ' => $trade_process->id,
              'margin_call_drops >= ' => '5'
            );
          $buy_records = $this->db->table('api_trade_history')->where($trade_where)->orderBy('id','ASC')->get()->getResult();
          ?>
           <div class="buysell-table bg-white inner-box mt-4">
          <div class="table-responsive">
            <table class="table-striped">
              <tbody>
                <?php 
                   if($buy_records) { 
                     foreach ($buy_records as $key => $value) { ?>
                      <tr>
                        <td><?php echo $value->margin_call_drops." th call";?></td>
                      </tr>
                      <tr>
                        <td>Avg price</td>
                        <td><?php echo $value->live_price;?></td>
                        <td>Position quantity</td>
                        <td class="next_border"><?php echo $value->received_amount;?></td>
                        <td>Position Amount</td>
                        <td><?php echo $value->quantity;?></td>
                      </tr>
              

               <?php }  } else { ?>
                      <tr>
                        <td><?php echo "Subbin calls are not active";?></td>
                      </tr>
               <?php } ?>
              </tbody>
            </table>
          </div>
        </div>
         </div>
       </div>
    <?php } ?>
  </div>
    </div>
    <div class="modal fade" id="exampleModal5" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Order Details</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
       <div id="data_store"> </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

      <div class="row">
                <div class="col-lg-12">
                  <div class="inner-title pt-4 pb-4">
                    <h6 class="color-2">Trading Records</h6>
                  </div>
                  <div class="table-responsive  main-table mont">
                   <div class="trading-table">
                    <div class="table-responsive">
                      <table class="table-striped">
                        <thead>
                          <tr>
                            <th> Trading pair </th>
                            <th> Buy in/Sell </th>
                            <th> Time </th>
                            <th> Order Number </th>
                            <th> Type </th>
                            <th> Quantity </th>
                            <th> Average buyin price (USDT)</th>
                            <th> profit(USDT) </th>
                            <th> profit(%) </th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php
                         
                          $openorders = $api->orders($id);
                         
                          if($openorders) {
                            $i=0;
                           foreach (array_reverse($openorders)  as $row)
                           {

                              if ($row['orderId']) {
                                    $sell_records =  $this->db->table('api_trade_history')->where('order_id',$row['orderId'])->where('trade_process_id',$pair->id)->where('status',0)->where('type',1)->get()->getRow();
                                    if ($sell_records->subsell_status == '' || $sell_records->subsell_status == '0') {

                                        if($sell_records->description == "manual_buy"){
                                           $buy_sell_status = "Manual-Buy";
                                        }else if($sell_records->description == "manual_sell" ){
                                          $buy_sell_status = "Manual-Sell";
                                        }else{
                                        $buy_sell_status = $row['side'];
                                      }
                                        if($row['type'] == "TAKE_PROFIT_LIMIT" || $row['type'] == "STOP_LOSS_LIMIT")
                                        $avg_trans_price = $sell_records->avg_price;
                                        else
                                          $avg_trans_price = $sell_records->live_price;
                                    }else{
                                        $buy_sell_status = 'SUB-SELL';
                                        $avg_trans_price = $sell_records->live_price - $sell_records->avg_price;
                                    }
                                }
                            if($row['side'] == "BUY")
                              $class = "success";
                            else
                              $class = "fail";

                            if($row['type'] == "LIMIT")
                              $type = "Limit Price";
                            else
                              $type = "Market Price";
                            $i=0;
                            if($sell_records) {
                            ?>
                            <tr>
                              <td><img height="20" width="20" src="<?php echo base_url('styles/images/tradingpair_images/'.$row['symbol'].'.png');?>" ><?php echo " ".$row['symbol'];?></td>
                              <td><span class="<?php echo $class;?>"> <?php echo $buy_sell_status;?> </span></td>
                              <td><?php echo date('Y-m-d h:i:s',substr($row['updateTime'],0,-3));?></td>
                              <td><button type="button" class="btn btn-outline-success" onclick="orderModal(<?php echo $row['orderId'];?>);" data-toggle="modal" data-target="#exampleModal5" id="orderModal" style="padding: 10px 17px 7px 13px !important;"><span><?php echo $row['orderId'];?></span></button></td>
                              <td><?php echo $type;?></td>
                              <td><?php echo $row['origQty'];?></td>
                              <td><?php echo $avg_trans_price;?></td>
                              <td><?php if($row['side'] == 'SELL'){ echo $sell_records->avg_price; }else{ echo '---';} ?></td>
                              <td> <?php if($row['side'] == 'SELL'){ if($sell_records->subsell_status == '1'){ echo $sell_records->profit_percentage;}elseif($sell_records->subsell_status == '' || $sell_records->subsell_status == '0'){ echo $sell_records->profit_percentage; }else{ echo "---"; }}else{ echo "---";} ?> </td>
                            </tr>
                          <?php
                          $i++;
                           } }  }
                          ?>

                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
</section>

<script type="text/javascript">
  function orderModal(id){
    jQuery.ajax({
                    method: 'POST',
                    data: {'id':id,'uusersid':"<?php echo $uusersid;?>","pair":"<?php echo $id;?>"},
                    url: '<?php echo base_url("/orderDetails");?>',
                    success:function(resp) {
                      console.log(resp);
                         jQuery('#data_store').html(resp);
                         jQuery('#exampleModal5').modal('show');
                    }
                });
  }
</script>

<style type="text/css">
  #BuyModal h6
  {
    font-size: 14px;
  }
  #BuyModal .modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 95%;
    pointer-events: auto;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid rgba(0,0,0,.2);
    border-radius: .3rem;
    outline: 0;
    padding: 16px;
}

#SellModal h6
  {
    font-size: 14px;
  }
  #SellModal .modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 95%;
    pointer-events: auto;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid rgba(0,0,0,.2);
    border-radius: .3rem;
    outline: 0;
    padding: 16px;
}
</style>


<!-- BuyModal model pages  -->
<div class="modal fade"  id="BuyModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">BUY</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row">

<div class="col-lg-12">
  <input type="hidden" id="pair" value="<?php echo $id;?>">

<div class="row">
<div class="col-lg-6">
 <h6> Position amount </h6>
</div>
<div class="col-lg-6" >
 <span id="trade_position_amount1"><?php echo $tradeupdate['total_position_amount'] ? $tradeupdate['trade_position_amount'] : 0 ;?></span> USDT
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Average position price</h6>
</div>
<div class="col-lg-6">
  <span id="trade_avg_position1"><?php echo $tradeupdate['trade_avg_position'] ? $tradeupdate['trade_avg_position'] : 0 ;?></span> USDT
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6> Position quantity</h6>
</div>
<div class="col-lg-6">
  <span id="trade_position_quantity"><?php echo $tradeupdate['trade_position_quantity'] ? $tradeupdate['trade_position_quantity'] : 0 ;?></span>&nbsp;&nbsp;<?php echo substr($id, 0,-4);?>
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Current price</h6>
</div>
<div class="col-lg-6 all_list_price">
   <?php 
  if($output['price'])
   echo $output['price'];
   else
    echo '0.00';?>
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Rate of return</h6>
</div>
<div class="col-lg-6">
 <span id="trade_rate_percentage2"><?php echo $tradeupdate['trade_rate_percentage'] ? $tradeupdate['trade_rate_percentage'] : "0%" ;?></span>
</div>
</div>

<hr>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Estimated average position price</h6>
</div>
<div class="col-lg-6 all_list_price1">
 -
</div> 
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Estimated holding profit and loss</h6>
</div>
<div class="col-lg-6" id="trade_estimate_price2">
 -
</div>
</div>


<div class="col-lg-6">
<h6>Trigger Price</h6>
</div>

<div class="row mt-2">
<div class="col-lg-7">
<div class="input-group mb-4">
  <input type="text" class="form-control" id='limit_clk' placeholder="Enter Trigger's price" aria-label="Recipient's username" aria-describedby="basic-addon2">
  <div class="input-group-append">
    <button class="btn btn-primary" id="market_clk" type="button">Market Price</button>
  </div>
</div>
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Amount of margin call</h6>
</div>
</div>


<div class="row mt-2">
<div class="col-lg-6">
<div class="form-block mb-3 position-relative">
<input name="code1" class="form-control"   type="text" id="code1" required="" placeholder="Please Enter Purchase Amount" value="" />
</div>
</div>
</div>

</div>

</div>
</div>
<div class="modal-footer" style="padding: 0px;">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" id="buy" class="btn btn-primary">Buy</button>
</div>
</div>
</div>
</div>



<div class="modal fade" id="SellModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">SELL</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row">

<div class="col-lg-12">
  <input type="hidden" id="pair1" value="<?php echo $id;?>">

<div class="row">
<div class="col-lg-6">
 <h6> Position amount </h6>
</div>
<div class="col-lg-6">
  <span class="trade_position_amount"><?php echo $tradeupdate['trade_position_amount'] ? $tradeupdate['trade_position_amount'] : 0;?></span> USDT
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Average position price</h6>
</div>
<div class="col-lg-6">
  <span class="trade_avg_position"><?php echo $tradeupdate['trade_avg_position'] ? $tradeupdate['trade_avg_position'] : 0;?></span>USDT
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Position quantity</h6>
</div>
<div class="col-lg-6 ">
 <span class="trade_position_quantity"><?php echo $tradeupdate['trade_position_quantity'] ? $tradeupdate['trade_position_quantity'] : 0;?></span>&nbsp;&nbsp;<?php echo substr($id, 0,-4);?>
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Current price</h6>
</div>
<div class="col-lg-6 all_list_price">
 <?php 
  if($output['price'])
   echo $output['price'];
   else
    echo '0.00';?>
</div>
</div>

<!-- <div class="row mt-2">
<div class="col-lg-6">
<h6>Rate of return</h6>
</div>
<div class="col-lg-6">
<span id="trade_rate_percentage1">0%</span>
</div>
</div>
 -->

 <div class="row mt-2">
<div class="col-lg-6">
<h6>Position profit and loss</h6>
</div>
<div class="col-lg-6" id="trade_estimate_price">
 <?php echo $tradeupdate['trade_estimate_price'] ? $tradeupdate['trade_estimate_price'] : " 0%";?>
</div>
</div>


<hr>



<div class="row mt-2">
<div class="col-lg-6">
<h6>Estimated selling profit</h6>
</div>
<div class="col-lg-6 estimate_sell">
</div>
</div>




<div class="col-lg-6">
<h6>Trigger Price (Sell at market price after reaching the trigger price)</h6>
</div>


<div class="row mt-2">
<div class="col-lg-7">
<div class="input-group mb-4">
  <input type="text" class="form-control" id='limit_clk1' placeholder="Enter Trigger's Price" aria-label="Recipient's username" aria-describedby="basic-addon2">
  <div class="input-group-append">
    <button class="btn btn-primary" id="market_clk1" type="button">Market Price</button>
  </div>
</div>
</div>
</div>

<div class="row mt-2">
<div class="col-lg-6">
<h6>Clearance Quantity</h6>
</div>
</div>


<div class="row mt-2">
<div class="col-lg-6">
<div class="form-block mb-3 position-relative">
<input name="code1" class="form-control clearance"   type="text" id="clearance" required="" placeholder="Please Enter Clearance Quantity in  <?php echo substr($id,0,-4);?>" value="" />
</div>
</div>
</div>

<div class="row mt-2">
<div class="col-lg-9">
<button class="btn btn-danger" id="quarter" type="button">25%</button>
<button class="btn btn-danger" id="half" type="button">50%</button>
<button class="btn btn-danger" id="onebuythree" type="button">75%</button>
<button class="btn btn-danger" id="full" type="button">100%</button>
</div>
</div>
<br/>
<div class="row mt-2">
<div class="col-lg-6">
<h6>Remaining Position Amount</h6>
</div>
<div class="col-lg-6">
 <span id="remaining_amount"><?php echo $tradeupdate['trade_remain_amount'] ? $tradeupdate['trade_remain_amount'] : 0;?></span> USDT
</div>
<span id="err" style="color: red;"></span>
</div>

</div>

</div>
</div>
<div class="modal-footer" style="padding: 0px;">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" id="sell"  class="btn btn-primary">Sell</button>
</div>
</div>
</div>
</div>

<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" class="col-lg-12" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document" style="width:360px;height:200px;">
<div class="modal-content" style="border-radius:30px;padding: 5px;position: absolute;width: 130%; " >
<div class="modal-header"style="border-bottom: 0px;border-bottom: 1px solid #dee2e6 !important;">
<center><b><p class="modal-title" id="staticBackdropLabel" style="border-bottom: 0px;font-size:15px;line-height: 24px;">First Preset Start Price</p></b></center>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" style="border-bottom: 1px solid #dee2e6;font-size:15px;line-height: 24px;">
<span style="color:#dee2e6;font-size: 13px;"><input style="border-style: none;" type="text" name="first_preset_price" id="first_preset_price" placeholder="Please Enter First Presend Start Price USDT" value="<?php echo $qry->first_buy_amount;?>"></span><p style="font-size:14px;"><p>
</div>
<div class="modal-footer" >
  <table style="margin-bottom: -2px;">
    <tr>
      <button data-bs-dismiss="modal" class="btn btn-primary" style="border-right: 1px solid #dee2e6;text-align: center;">Cancel</button>
      <button style="text-align: center;" class="btn btn-secondary" name="sure_price" data-bs-dismiss="modal" id="sure_price">Sure</button>
    </tr>
  </table>
</div>
</div>
</div>
</div>  


<div class="modal fade" id="staticBackdrop2" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" class="col-lg-12" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document" style="width:360px;height:200px;">
<div class="modal-content" style="border-radius:30px;padding: 5px;position: absolute;width: 130%; " >
<div class="modal-header"style="border-bottom: 0px;border-bottom: 1px solid #dee2e6 !important;">
<center><b><p class="modal-title" id="staticBackdropLabel" style="border-bottom: 0px;font-size:15px;line-height: 24px;">Oneshot Hit Price</p></b></center>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" style="border-bottom: 1px solid #dee2e6;font-size:15px;line-height: 24px;">
<span style="color:#dee2e6;font-size: 13px;"><input style="border-style: none;" type="text" name="oneshot_limit" id="oneshot_limit" placeholder="Please Enter Oneshot Hit Price" value="<?php echo $qry->oneshot_limit;?>"></span><p style="font-size:14px;"><p>
</div>
<div class="modal-footer" >
  <table style="margin-bottom: -2px;">
    <tr>
      <button data-bs-dismiss="modal" class="btn btn-primary" style="border-right: 1px solid #dee2e6;text-align: center;">Cancel</button>
      <button style="text-align: center;" class="btn btn-secondary" name="sure_limit" data-bs-dismiss="modal" id="sure_limit">Sure</button>
    </tr>
  </table>
</div>
</div>
</div>
</div>  

<style type="text/css">
  
  #staticBackdrop1 .form-check-input[type=checkbox]
  {
    border-radius: 1.25em;
  }

</style>

<div class="modal fade" id="staticBackdrop1" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" style="display: none;" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content" style="border-radius:30px;padding: 11px;" >
<div class="modal-header" style="border-bottom: 0px;padding-top: 11px;margin-bottom:-15px;">
<p class="modal-title" id="staticBackdropLabel" style="padding-left:170px;"><b>Strategy mode</b></p>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<center>
<span class="span" style="border-bottom: 1px;">Please select a strategy mode</span>
</center>
<hr>
<div class="row col-lg-12 mt-3">
<div class="form-check form-check-right mb-3" style="font-size: 14px;">
<input type="radio" class="form-check-label" name="strategy_mode" id="strategy_mode" value="1" <?php if($user->strategy_mode==='1'){ echo 'checked="checked"'; } ?>> Whole warehouse mode<br><br>
<input type="radio" class="form-check-label" name="strategy_mode" id="strategy_mode" value="2" <?php if($user->strategy_mode==='2'){ echo 'checked="checked"'; } ?>> Sub-bin mode<br><br>
<input type="radio" class="form-check-label" name="strategy_mode" id="strategy_mode" value="3" <?php if($user->strategy_mode==='3'){ echo 'checked="checked"'; } ?>> Sub-bin mode-real-time settlement

</div>
</div>

</div>
<div class="modal-footer" style="padding: 0px;">
  <table style="margin-bottom: -2px;">
    <tr>
      <button data-bs-dismiss="modal" class="btn btn-primary" style="border-right: 1px solid #dee2e6;text-align: center;">Cancel</button>
      <button style="text-align: center;" class="btn btn-secondary"  data-bs-dismiss="modal" name="sure_mode" id="sure_mode">Sure</button>
    </tr>
  </table>
</div>
</div>
</div>
</div>  

<input type="hidden" value="<?php echo $user->strategy_type;?>" id="find_mode">
<input type="hidden" value="<?php echo $user->strategy_mode;?>" id="modes">





</body>

<?php
 echo view('user/footer1');
  // echo view('user/common_script');
?>  

<script src="<?php echo base_url();?>/styles/new_style/js/jquery-2.1.4.min.js"></script>
<script src="<?php echo base_url();?>/styles/new_style/js/bootstrap.min.js"></script>
<script src="<?php echo base_url();?>/styles/new_style/js/owl.carousel.min.js"></script>
<script src="<?php echo base_url();?>/styles/new_style/js/script.js"></script>
<script src="<?php echo base_url();?>/styles/new_style/js/wow.min.js"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
<script type="text/javascript" src="<?php echo base_url('/styles/js/datatables.min.js');?>"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
      $('.main-table table').dataTable({
          "language": { search: "" },
          "Info": false
    });
    });
</script>

<script type="text/javascript">
     $(document).ready(function() {

    var xhr2;
    var fn2 = function(){
    if(xhr2 && xhr2.readyState != 4){
    xhr2.abort();
    }
    xhr2 = $.ajax({
    type: 'post',
    url: "<?php echo base_url("cron_second");?>",
    success: function(data) {

    console.log(data);

    }
    });
    };
    // var interval = setInterval(fn2, 30000);


    var xhr3;
    var fn3 = function(){
    if(xhr3 && xhr3.readyState != 4){
    xhr3.abort();
    }
    xhr3 = $.ajax({
    type: 'post',
    url: "<?php echo base_url("cron_third");?>",
    success: function(data) {

    console.log(data);

    }
    });
    };
    // var interval = setInterval(fn3, 30000);



      $('#exampleModal1_clr').on('click', function() {
    var num = <?php echo $trade_process->margin_column_limit;?>;
    if(num == "")
      num = 7;

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time1");?>',
    data : {'number1':num,'pair':'<?php echo $output['symbol']?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#ex_demo1').html(msg);
    }
    }
    });

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time2");?>',
    data : {'number2':num,'pair':'<?php echo $output['symbol']?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#ex_demo2').html(msg);
    }
    }
    });

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time");?>',
    data : {'number':num,'pair':'<?php echo $output['symbol']?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#ex_demo').html(msg);
    }
    }
    });

});


$('#replenishment_time').keyup(function(){

var num = $('#replenishment_time').val();

if(num>=5)
{
              $.ajax({
              type: 'post',
              dataType:'html',
              url : '<?php echo base_url("/replenishment_time");?>',
              data : {'number':num,'pair':'<?php echo $output['symbol']?>'},
              headers: {'X-Requested-With': 'XMLHttpRequest'},
              success : function(msg)
              {
                if(msg)
                {
                $('#ex_demo').html(msg);
                }
              }
              });

               $('#subposition').css('display', 'block');

}
else
{
   $('#ex_demo').html("");
    $('#subposition').css('display', 'none');
}
});


$('#replenishment_time').keyup(function(){

var num = $('#replenishment_time').val();

if(num>0)
{
              $.ajax({
              type: 'post',
              dataType:'html',
              url : '<?php echo base_url("/replenishment_time1");?>',
              data : {'number1':num,'pair':'<?php echo $output['symbol']?>'},
              headers: {'X-Requested-With': 'XMLHttpRequest'},
              success : function(msg)
              {
                if(msg)
                {
                $('#ex_demo1').html(msg);
                }
              }
              });

}
});

$('#replenishment_time').keyup(function(){
var num = $('#replenishment_time').val();
if(num>0)
{
              $.ajax({
              type: 'post',
              dataType:'html',
              url : '<?php echo base_url("/replenishment_time2");?>',
              data : {'number2':num,'pair':'<?php echo $output['symbol']?>'},
              headers: {'X-Requested-With': 'XMLHttpRequest'},
              success : function(msg)
              {
                if(msg)
                {
                $('#ex_demo2').html(msg);
                }
              }
              });

}
});

    $('#submit_button').click(function(){
      var first_buy_amount =  $("[name=first_buy_amount]").val();
      var whole_profit_ratio =  $("[name=whole_profit_ratio]").val();
      var whole_profit_callback =  $("[name=whole_profit_callback]").val();
      var sub_position_callback = $("[name=sub_position_callback]").val();
      var limit = $("[name=replenishment_time]").val();
      var buyin_callback =  $("[name=buyin_callback]").val();
      var flag = 1;
      if(!(whole_profit_ratio > 0)){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Please enter a value greater than 1', 'danger');
          flag = 0;
      }
        if(limit >= 5){
        var j=0;
        var i;
           for(i=5; limit >= i; i++){
            var var_name = "rep_time"+j;
            if($("[name="+var_name+"]").val() < sub_position_callback && flag == 1){
            $.notify(' <i class="fas fa-exclamation-triangle"></i> Subbin Take profit ratio will be greater than subbin take profit callback', 'danger');
            flag = 0;
            }
            j++;
           }
        }


      if(whole_profit_ratio < whole_profit_callback && flag == 1){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Take profit ratio will be greater than take profit callback', 'danger');
          flag = 0;
        }
        if(!(buyin_callback >= 0) && flag == 1){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Please enter a positive value', 'danger');
          flag = 0;
        }
        if(!(first_buy_amount >= 11 && flag == 1)){
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Minimum first buy amount is 11 USDT', 'danger');
          flag = 0;
      }

     var empty = true;

      $('#exampleModal1 input[type="text"]').each(function() {
      if($(this).val() == ''){
      $flag = 0;
      empty = false;
      }
      });

      if(empty == false){
      $.notify(' <i class="fas fa-exclamation-triangle"></i> Some fields are empty', 'danger');
      }

        if(flag == 1 && empty == true){
          $('#exampleModal1').submit();
          $.notify('<i class="fas fa-check"></i>  Set Successfully', 'success');
        }
          
    });  

    $('#subposition').css('display', 'none');

        var num = $('#replenishment_time').val();

      if(num >= 5)
        {
          $('#subposition').css('display', 'block');
        }
        else
        {
          $('#subposition').css('display', 'none');
        }


 
    $('#sure_price').click(function(){
    var uusersid = $('#uusersid').val();
    var first_preset_drop = $('#first_preset_price').val();
    $.ajax({
    type: 'post',
    url : '<?php echo base_url("/dashboard/first_preset_drop");?>',
    data : {'first_preset_drop':first_preset_drop,'uusersid':uusersid,'pair':'<?php echo $output['symbol'];?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       window.location.reload();
    }
    }
    });
    });

   $('#sure_limit').click(function(){
    var uusersid = $('#uusersid').val();
    var oneshot_limit = $('#oneshot_limit').val();
    $.ajax({
    type: 'post',
    url : '<?php echo base_url("/dashboard/oneshot_limit");?>',
    data : {'oneshot_limit':oneshot_limit,'uusersid':uusersid,'pair':'<?php echo $output['symbol'];?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       window.location.reload();
    }
    }
    });
    });
    });
</script>

<script type="text/javascript">
$(document).ready(function() {
  var trade_update = async function(){

   var  live_price = $('.all_list_price').html();
    $.ajax({
      type: 'post',
      url : '<?php echo base_url('trade_update');?>',
      data : {pair:'<?php echo $id; ?>','uusersid': '<?php echo $this->session->get('uusersid');?>','live_price': live_price},
      success : function(msg) { 

        var myArray = JSON.parse(msg);

        var total_amount = myArray['trade_position_amount'];
        var trade_position_quantity = myArray['trade_position_quantity'];
        var avg_position =  myArray['trade_avg_position'];
        var calls =  myArray['trade_number_of_call'];
        var rate_percentage =  myArray['trade_rate_percentage'];
        var live_price =  myArray['live_price'];
        var status =  myArray['status'];
        var take_profit_trigger =  myArray['take_profit_trigger'];
        var down_price =  myArray['down_price'];
        var current_position_amount =  myArray['current_position_amount'];
        var trade_estimate_price =  myArray['trade_estimate_price'];
        trade_details(total_amount,avg_position,calls,rate_percentage,live_price,status,take_profit_trigger,down_price,current_position_amount,trade_estimate_price,trade_position_quantity); 
      }
    });
  };
  var interval = setInterval(trade_update, 6000); 


  function trade_details(total_amount,avg_position,calls,rate_percentage,live_price,status,take_profit_trigger,down_price,current_position_amount,trade_estimate_price,trade_position_quantity){
    $('#trade_position_amount').text(total_amount);
    $('#trade_position_amount1').text(total_amount);
    $('#trade_position_amount2').text(total_amount);
    $('.trade_position_amount').text(total_amount);
    $('#trade_avg_position').text(avg_position);
    $('#trade_avg_position1').text(avg_position);  
    $('.trade_avg_position').text(avg_position);
    $('#trade_number_of_call').text(calls);
    $('#trade_rate_percentage').text(rate_percentage);
    $('#trade_rate_percentage1').text(rate_percentage);
    $('#trade_rate_percentage2').text(rate_percentage);
    $('#take_profit_trigger').text(take_profit_trigger);
    $('#trade_estimate_price').text(trade_estimate_price);
    $('#trade_estimate_price1').text(trade_estimate_price);
    $('#trade_position_quantity').text(trade_position_quantity);
    $('.trade_position_quantity').text(trade_position_quantity);
    $('#down_price').text(down_price);
    $('.all_list_price').text(live_price);
    $('.current_position_amount').text(current_position_amount+" USDT");
    if(status == 1)
    $('#margin_status').text("Waiting For Trigger");
    else if(status == "")
    $('#margin_status').text(" ");
    else
    $('#margin_status').text("Stop Margin Call");
  }
});
</script>
<script src="<?php echo base_url()?>/styles/new_style/js/notify.js"></script>
<script type="text/javascript">
  
    $(document).ready(function(){

      if($('#Ostartegy').is(':hidden')){
        $('#oneshot_limit_section').css('display','inline-block');
      }

        $('#Cstartegy_Name').on('click',function(){
    
    var num="Cycle Strategy";
    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $output['symbol']?>";

    console.log(pairs);
    console.log(pair_id);

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/Cstartegy");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id,'url':'<?php echo $uri->getSegment(2); ?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       $.notify('<i class="fas fa-check"></i>  Set Successfully', 'success');
    }
    }
    });
  });

           function doalert(obj) {
        $('#Cstartegy').css('display','none');
        $('#Ostartegy').css('display','inline-block');
        $('#oneshot_limit_section').css('display','none');
        var a = $('#Ostartegy_Name').text();
        $('#crypto-strategy').html(a);
    }

     function Ooalert(obj) {
        $('#Cstartegy').css('display','inline-block');
        $('#Ostartegy').css('display','none');
        $('#oneshot_limit_section').css('display','inline-block');
        var b = $('#Cstartegy_Name').text();
        $('#crypto-strategy').html(b);
    }

  

      

      $('#sellModels').on('click',function(){         
          $.notify(' <i class="fas fa-exclamation-triangle"></i>  No position temporarily ', 'danger');
      });
      $('#buyModels').on('click',function(){         
          $.notify(' <i class="fas fa-exclamation-triangle"></i> Please start the strategy first', 'danger');
      });

    $('#start_button').on('click',function()
    {
       var avaialabe_fuel_fee     =  '<?php echo $buy_bal;?>';
       var fuel_fee               = '<?php echo $tradSet->min_fuel_fee;?>';
       var activate               = '<?php echo $activation; ?>';

       console.log('available fuel '+avaialabe_fuel_fee.replace(',',''));
       console.log('fuel fee '+fuel_fee);
 
      if(activate)
      {
   
     if(parseFloat(avaialabe_fuel_fee.replace(',',''))>parseFloat(fuel_fee))
     {

      if(<?php echo $bind_api;?>){

      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingprocess");?>',
         data:{'id':"<?php echo $id;?>",'uri':"<?php echo $uri->getSegment(2);?>",'pair':"<?php echo $output['symbol']?>" },
        success:function(msg)
        {
          alert(msg);
          console.log(msg);
         // window.location.reload();
        }
      })
    }else{
       $.notify(' <i class="fas fa-exclamation-triangle"></i>  Please bind your api to start the trade. ', 'danger');
    }
   
    }
   else
   {
    $.notify(' <i class="fas fa-exclamation-triangle"></i>  Please recharge fuel. ', 'danger');
   }
    }
     else
     {
        $.notify(' <i class="fas fa-exclamation-triangle"></i>  Please activate the robot first ', 'danger');
      }
    });
     

   var margin_call = '<?php echo $user->margin_call;?>';
     
   if(margin_call==1)
     {
          $('#mc').html("Stop margin call");
     }
     else
     {
        $('#mc').html("Initiate margin call");
     }

    var output_symbol = '<?php echo $output['symbol']?>';

    setInterval(function(){
    $.ajax({
    type:'post',
    method: 'POST',
    url: '<?php echo base_url("/autoLoadPrice");?>',
    dataType:"html",
    data:{
    'symbol':output_symbol,
    },
    success: function (data) {
    $('.all_list_price').html(data);
    }
    });

    }, 6000);



     var find_mode = $('#find_mode').val();
     var mode = $('#modes').val();
     if(mode==1)
     {
      mode =  "Whole warehouse mode";
     }
      if(mode==2)
     {
      mode =  "Sub-bin mode";
     }
      if(mode==3)
     {
      mode =  "Sub-bin mode-real-time settlement";
     }

     if(find_mode=="One-shot strategy")
     {
        $('#crypto-strategy').html("One-shot strategy");
        $('#crypto-strategy_mode').html(mode);
        $('#Cstartegy').css('display','none');
        $('#Ostartegy').css('display','inline-block');
        $('#oneshot_limit_section').css('display','none');
     }
     else
     {
        $('#crypto-strategy').html(find_mode);
        $('#crypto-strategy_mode').html(mode);
        $('#Cstartegy').css('display','inline-block');
        $('#Ostartegy').css('display','none');
        $('#oneshot_limit_section').css('display','inline-block');

     }
   

      $('.main-table table').dataTable({
          "language": { search: "" },
          "Info": false
    });
    });


</script>

<script type="text/javascript">

   $('#start_button_block').on('click',function(){  
       $.notify(' <i class="fas fa-exclamation-triangle"></i>  Please activate the robot first ', 'danger');
     });


    $('#Margin_Clk').on('click',function(){

     var pairs = "<?php echo $pair->trade_status;?>";

     if(pairs)
     {

      var mci = $('.smc').html();

     if(mci == "Stop margin call")
     {
         $('#mc').html("Initiate margin call");
         var value = 1;
     }
     if(mci != "Stop margin call")
     {
        $('#mc').html("Stop margin call");
        var value = 0;
     }


    var pairs  = "<?php echo $output['symbol']?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/call_margin");?>',
    data : {'margin_id':value,'pair':pairs,'url':'<?php echo $uri->getSegment(2); ?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       $.notify('<i class="fas fa-check"></i>  Set Successfully', 'success');
    }
    }
    });

     if(value != 1)
          $('#margin_status').text('Waiting For Trigger');
     else
          $('#margin_status').text("Stop Margin Call");  

  }
  else
  {
    $.notify('<i class="fas fa-times"></i> No position temporarily', 'danger');
  }
   
    });


    $('#Ostartegy').on('click',function(){
    
    var num="Ostartegy";
    
    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $output['symbol']?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/Ostartegy");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id,'url':'<?php echo $uri->getSegment(2); ?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
       $.notify('<i class="fas fa-check"></i>  Set Successfully', 'success');
    }
    }
    });
  });


    $('#logModal').on('click',function(){

    var num="Ostartegy";
    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $output['symbol']?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/logModal");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id,'url':'<?php echo $uri->getSegment(2); ?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#logModals').html(msg)
    }
    }
    });

    });


  

  $('#sure_mode').on('click',function(){
   
   var num = $('input[name="strategy_mode"]:checked').val();

    var pairs = "<?php echo $pair->trade_status;?>";
    var pair_id  = "<?php echo $output['symbol']?>";

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/Cstartegy_mode");?>',
    data : {'number2':num,'pair':pairs,'pair_id':pair_id,'url':'<?php echo $uri->getSegment(2); ?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
      $.notify('<i class="fas fa-check"></i>  Set Successfully', 'success');
       window.location.reload();
    }else{
      $.notify(' <i class="fas fa-exclamation-triangle"></i> &nbsp;&nbsp; Strictly restricted after 5th trade', 'danger');
    }
    }
    });
 
  });



    $('#buy').on('click',function()
    {
      if($('#limit_clk').is(':disabled'))
        var val= "";
      else
        var val = $('#limit_clk').val();
      var num=  $('#code1').val();
      var id=$('#pair').val();
      var uusersid=<?php echo $this->session->get('uusersid');?>;
      var trade_process_id = <?php echo $pair->id;?>;
      
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingbuy");?>',
         data:{'val':val, 'num':num, 'id':id ,'uusersid':uusersid,'trade_process_id':trade_process_id},
         

        success:function(msg)
        {
          // console.log(msg);
          if(msg == 'failure')
            $.notify(' <i class="fas fa-exclamation-triangle"></i> &nbsp;&nbsp; Buy process failed. Please try again... ', 'danger');
          else if(msg == 'fail')
            $.notify(' <i class="fas fa-exclamation-triangle"></i> &nbsp;&nbsp; Trigger buy order already exist... ', 'danger');
          else
           window.location.reload();
        },
        error: function (request, message, error) {
         let  err =  handleException(request, message, error);
            if(err)
              $.notify(' <i class="fas fa-exclamation-triangle"></i>&nbsp;&nbsp; Buy process failed. Please try again... ', 'danger');
        }
      })
    });


    <?php $uri = service('uri');?>

    $('#pause_button').on('click',function()
    {
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingprocess1");?>',
         data:{'id':"<?php echo $id;?>",'uri':"<?php echo $uri->getSegment(2);?>" },
        success:function(msg)
        {
           window.location.reload();
        }
      })
    });

  $('#stop_button').on('click',function()
    {
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingprocess2");?>',
         data:{'id':"<?php echo $id;?>",'uri':"<?php echo $uri->getSegment(2);?>",'pair':"<?php echo $pair->id;?>",'uusersid':"<?php echo $this->session->get('uusersid');?>" },
        success:function(msg)
        {
          console.log(msg);
           // window.location.reload();

        }
      })
    });

    function cancel(id)
    {
      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/cancel_order");?>',
         data:{'id':id},
        success:function(msg)
        {
          console.log(msg);
           window.location.reload();
        }
      })
    }

   



    $('#quarter').on('click',function()
    {
       $('.estimate_sell').html("");
      var price = <?php echo $tradeupdate['trade_remain_amount'] ?  $tradeupdate['trade_remain_amount'] : 0;?>;
      var quantity = <?php echo $tradeupdate['trade_position_quantity'] ?  $tradeupdate['trade_position_quantity'] : 0;?>;
      var quantity_quarter = +quantity * 25 / 100;
      var quarter = +price * 25 / 100;
      var remain = +price - +quarter;
      $('#clearance').val(quantity_quarter);
      $('#remaining_amount').html(remain);
      var profit_loss = $('#trade_estimate_price').html();
      var position_perc = profit_loss.substring(0, profit_loss.length - 1);
      var live_price = $('.all_list_price').html();
      var est_sell_pre = quantity_quarter * live_price;
             var estimate_sell1 =  +parseFloat(price) * +parseFloat(profit_loss) / 100;
      var estimate_sell = estimate_sell1 * 1/4;
       $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // var estimate_sell1 = +parseFloat(est_sell_pre) * +parseFloat(position_perc) / 100;
      // var estimate_sell = estimate_sell1 * 80/100;
      // if(position_perc > 0)
      //   $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // else
      //   $('.estimate_sell').html("-"+estimate_sell.toPrecision(5));
    });


    $('#half').on('click',function()
    {
       $('.estimate_sell').html("");
      var price =<?php echo $tradeupdate['trade_remain_amount'] ?  $tradeupdate['trade_remain_amount'] : 0;?>;
      var quantity = <?php echo $tradeupdate['trade_position_quantity'] ?  $tradeupdate['trade_position_quantity'] : 0;?>;
      var quantity_quarter = +quantity * 50 / 100;
      var quarter = +price * 50 / 100;
      var remain = price - quarter;
      $('#clearance').val(quantity_quarter);
      $('#remaining_amount').html(remain);
      var profit_loss = $('#trade_estimate_price').html();
      var position_perc = profit_loss.substring(0, profit_loss.length - 1);
      var live_price = $('.all_list_price').html();
       var estimate_sell1 =  +parseFloat(price) * +parseFloat(profit_loss) / 100;
      var estimate_sell = estimate_sell1 * 1/2;
       $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // var est_sell_pre = quantity_quarter * live_price;
      // var estimate_sell1 = +parseFloat(est_sell_pre) * +parseFloat(position_perc) / 100;
      // var estimate_sell = estimate_sell1 * 80/100;
      // if(position_perc > 0)
      //   $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // else
      //   $('.estimate_sell').html("-"+estimate_sell.toPrecision(5));
    });


    $('#onebuythree').on('click',function()
    {
       $('.estimate_sell').html("");
        var price = <?php echo $tradeupdate['trade_remain_amount'] ?  $tradeupdate['trade_remain_amount'] : 0;?>;
      var quantity = <?php echo $tradeupdate['trade_position_quantity'] ?  $tradeupdate['trade_position_quantity'] : 0;?>;
      var quantity_quarter = +quantity * 75 / 100;
      var quarter = +price * 75 / 100;
      var remain = price - quarter;
      $('#clearance').val(quantity_quarter);
      $('#remaining_amount').html(remain);
      var profit_loss = $('#trade_estimate_price').html();
      var position_perc = profit_loss.substring(0, profit_loss.length - 1);
      var live_price = $('.all_list_price').html();
      var est_sell_pre = quantity_quarter * live_price;
      var estimate_sell1 =  +parseFloat(price) * +parseFloat(profit_loss) / 100;
      var estimate_sell = estimate_sell1 * 3/4;
      $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // var estimate_sell1 = +parseFloat(est_sell_pre) * +parseFloat(position_perc) / 100;
      // var estimate_sell = estimate_sell1 * 80/100;
      // if(position_perc > 0)
      //   $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // else
      //   $('.estimate_sell').html("-"+estimate_sell.toPrecision(5));
    });


    $('#full').on('click',function()
    {
       $('.estimate_sell').html("");
      var price = <?php echo $tradeupdate['trade_remain_amount'] ?  $tradeupdate['trade_remain_amount'] : 0;?>;
      $('#clearance').val(<?php echo $tradeupdate['trade_position_quantity'] ?  $tradeupdate['trade_position_quantity'] : 0;?>);
      $('#remaining_amount').html(0);
      var profit_loss = $('#trade_estimate_price').html();
      var position_perc = profit_loss.substring(0, profit_loss.length - 1);
      var live_price = $('.all_list_price').html();
    var est_sell_pre = <?php echo $tradeupdate['trade_position_quantity'] ?  $tradeupdate['trade_position_quantity'] : 0;?> * live_price;
      var estimate_sell = +parseFloat(price) * +parseFloat(profit_loss) / 100;
      // var estimate_sell = estimate_sell1 * 80/100;
      // if(profit_loss > 0)
        $('.estimate_sell').html(estimate_sell.toPrecision(5));
      // else
      //   $('.estimate_sell').html("-"+estimate_sell.toPrecision(5));
    });

    $('#clearance').on('change',function(){
      var price =  $('#clearance').val();
      var id=$('#pair1').val();
      var old_price =  <?php echo $tradeupdate['trade_remain_amount'] ?  $tradeupdate['trade_remain_amount'] : 0;?>;
      var total_quantz =  <?php echo $tradeupdate['trade_position_quantity'] ?  $tradeupdate['trade_position_quantity'] : 0;?>;
      if(price <= total_quantz){
        $('#err').html();
        var live_price = $('.all_list_price').html();
        var total_price = live_price * price ;
        var msg = old_price - total_price;
        $('#remaining_amount').html(msg);
        var profit_loss = $('#trade_estimate_price').html();
        var position_perc = profit_loss.substring(0, profit_loss.length - 1);
        var live_price = $('.all_list_price').html();
        var est_sell_pre = price * live_price;
        var estimate_sell1 = +parseFloat(est_sell_pre) * +parseFloat(position_perc) / 100;
        var estimate_sell = estimate_sell1 * 80/100;
      if(position_perc > 0)
        $('.estimate_sell').html(estimate_sell.toPrecision(5));
      else
        $('.estimate_sell').html("-"+estimate_sell.toPrecision(5));
        
     
       }else{
       $('#err').html('Your Clearance Amount is not greater than available position quantity');        
       }
    });



 $('#sell').on('click',function()
    {
        if($('#limit_clk1').is(':disabled'))
        var val= "";
      else
        var val = $('#limit_clk1').val();
      var num=  $('#clearance').val();
      var id=$('#pair1').val();
      var uusersid=<?php echo $this->session->get('uusersid');?>;
      var trade_process_id = <?php echo $pair->id;?>;

      $.ajax({
        'method': 'POST',
        'url': '<?php echo base_url("/tradingsell");?>',
         data:{'val':val,'num':num,'id':id,'uusersid':uusersid,'trade_process_id':trade_process_id},
        
        success:function(msg)
        { 
          if(msg == 'failure')
            $.notify(' <i class="fas fa-exclamation-triangle"></i>&nbsp;&nbsp; Sell process failed. Please try again... ', 'danger');
          else if(msg == 'fail')
            $.notify(' <i class="fas fa-exclamation-triangle"></i>&nbsp;&nbsp; Trigger sell order already exist... ', 'danger');
          else
           window.location.reload();
        },
        error: function (request, message, error) {
         let  err =  handleException(request, message, error);
            if(err)
              $.notify(' <i class="fas fa-exclamation-triangle"></i>&nbsp;&nbsp; Sell process failed. Please try again... ', 'danger');
        }
      })
    });

function handleException(request, message, error) {
    var msg = "";
    msg += "Code: " + request.status + "\n";
    msg += "Text: " + request.statusText + "\n";
    if (request.responseJSON != null) {
        msg += "Message: " +
        request.responseJSON.Message + "\n";
    }
    return msg;
}





$('#buy_popup').on('click', function(){
    $('.all_list_price1').html($('#trade_avg_position1').html()+" USDT");
    $('#trade_estimate_price2').html($('#trade_rate_percentage2').html());
});


    $('#market_clk').on('click',function(){
    if($('#limit_clk').is(':disabled')){
    $("#limit_clk").attr('disabled', false);
    }
    else
    {
    $("#limit_clk").attr('disabled', true);
    }
    });

    $('#limit_clk').on('change',function(){
    if($('#code1').val() == "" || $('#code1').val() == 0){
      var avg_price = $('#trade_avg_position').html();
      var live_price = $('#limit_clk').val();
      var ror = 0.00;

    console.log("avg price " + avg_price);
    console.log("live price "+live_price);

    if(avg_price > live_price){
       ror1 = avg_price - live_price ;
       ror2 = ror1 / avg_price ;
       ror = ror2 * 100;
       ror = Number((ror).toFixed(2));
       ror = '-'+ror;
    }
    else if(avg_price < live_price) {
       ror1 = live_price - avg_price ;
       ror2 = ror1 / live_price ;
       ror = ror2 * 100;
       ror = Number((ror).toFixed(2));
        }
    $('.all_list_price1').html($('#trade_avg_position1').html()+" USDT");
    $('#trade_estimate_price2').html(ror+"%");
    }else{
      var prev_amount = $('#trade_position_amount').html();
    var prev_quantity = $('#trade_position_quantity').html();
    var amount = $('#code1').val();
    if($('#limit_clk').is(':disabled')){
    var live_price = $('.all_list_price').html();
    }else{
    if($('#limit_clk').val() == "" || $('#limit_clk').val() == 0)
    var live_price = $('.all_list_price').html();
    else
    var live_price = $('#limit_clk').val();
    }

    console.log("prev amount " +prev_amount);
    console.log("prev quantity " +prev_quantity);
    console.log("amount " +amount);
    console.log("live price " +live_price);

    var quantity = amount / live_price ;
    var total_usdt = +prev_amount + +amount;
    var total_quantity = +prev_quantity + +quantity;
    console.log("quantity "+quantity);
    console.log("total usdt "+total_usdt);
    console.log("total quantity "+total_quantity);
    var avg_price = total_usdt / total_quantity;
    avg_price = Number((avg_price).toFixed(5));
   
   
    var ror = 0.00;

    console.log("avg price " + avg_price);
    console.log("live price "+live_price);

    if(avg_price > live_price){
       ror1 = avg_price - live_price ;
       ror2 = ror1 / avg_price ;
       ror = ror2 * 100;
       ror = Number((ror).toFixed(2));
       ror = '-'+ror;
    }
    else if(avg_price < live_price) {
       ror1 = live_price - avg_price ;
       ror2 = ror1 / live_price ;
       ror = ror2 * 100;
       ror = Number((ror).toFixed(2));
        }

    console.log(ror);
    $('.all_list_price1').html(avg_price+" USDT");
    $('#trade_estimate_price2').html(ror+"%");

    }

    });

    $('#code1').on('change',function(){
    var prev_amount = $('#trade_position_amount').html();
    var prev_quantity = $('#trade_position_quantity').html();
    var amount = $('#code1').val();
    if($('#limit_clk').is(':disabled')){
    var live_price = $('.all_list_price').html();
    }else{
    if($('#limit_clk').val() == "" || $('#limit_clk').val() == 0)
    var live_price = $('.all_list_price').html();
    else
    var live_price = $('#limit_clk').val();
    }

    console.log("prev amount " +prev_amount);
    console.log("prev quantity " +prev_quantity);
    console.log("amount " +amount);
    console.log("live price " +live_price);

    var quantity = amount / live_price ;
    var total_usdt = +prev_amount + +amount;
    var total_quantity = +prev_quantity + +quantity;
    console.log("quantity "+quantity);
    console.log("total usdt "+total_usdt);
    console.log("total quantity "+total_quantity);
    var avg_price = total_usdt / total_quantity;
    avg_price = Number((avg_price).toFixed(5));
   
   
    var ror = 0.00;

    console.log("avg price " + avg_price);
    console.log("live price "+live_price);

    if(avg_price > live_price){
       ror1 = avg_price - live_price ;
       ror2 = ror1 / avg_price ;
       ror = ror2 * 100;
       ror = Number((ror).toFixed(2));
       ror = '-'+ror;
    }
    else if(avg_price < live_price) {
       ror1 = live_price - avg_price ;
       ror2 = ror1 / live_price ;
       ror = ror2 * 100;
       ror = Number((ror).toFixed(2));
    }

    console.log(ror);
    $('.all_list_price1').html(avg_price+" USDT");
    $('#trade_estimate_price2').html(ror+"%");

   
    });

    
    $('#market_clk1').on('click',function(){

    if($('#limit_clk1').is(':disabled')){

    $("#limit_clk1").attr('disabled', false);

    }
    else
    {
    $("#limit_clk1").attr('disabled', true);
    }

    });



$(document).ready(function(){
    var num = $('#replenishment_time').val();
    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time1");?>',
    data : {'number1':num,'pair':'<?php echo $output['symbol']?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#ex_demo1').html(msg);
    }
    }
    });

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time2");?>',
    data : {'number2':num,'pair':'<?php echo $output['symbol']?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#ex_demo2').html(msg);
    }
    }
    });

    $.ajax({
    type: 'post',
    dataType:'html',
    url : '<?php echo base_url("/replenishment_time");?>',
    data : {'number':num,'pair':'<?php echo $output['symbol']?>'},
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    success : function(msg)
    {
    if(msg)
    {
    $('#ex_demo').html(msg);
    }
    }
    });
});

          var xhr3;
    var fn3 = function(){
    if(xhr3 && xhr3.readyState != 4){
    xhr3.abort();
    }
    xhr3 = $.ajax({
    type: 'post',
    url: "<?php echo base_url("cron_third");?>",
    success: function(data) {
    console.log(data);
    }
    });
    };
    // var interval = setInterval(fn3, 10000);
      var xhr1;
    var fn1 = function(){
        if(xhr1 && xhr1.readyState != 4){
            xhr1.abort();
        }
        xhr1 = $.ajax({
            type: 'post',
            url: "<?php echo base_url("cron_first");?>",
            success: function(data) {

                console.log(data);
            }
        });
    };
    // var interval = setInterval(fn1, 10000);

    var xhr2;
    var fn2 = function(){
    if(xhr2 && xhr2.readyState != 4){
    xhr2.abort();
    }
    xhr2 = $.ajax({
    type: 'post',
    url: "<?php echo base_url("cron_second");?>",
    success: function(data) {

    console.log(data);

    }
    });
    };
    // var interval = setInterval(fn2, 10000);
    wow = new WOW(
      {
        animateClass: 'animated',
        offset:       100,
        callback:     function(box) {
          console.log("WOW: animating <" + box.tagName.toLowerCase() + ">")
        }
      }
    );
    wow.init();
    document.getElementById('moar').onclick = function() {
      var section = document.createElement('section');
      section.className = 'section--purple wow fadeInDown';
      this.parentNode.insertBefore(section, this);
    };
</script>
<!--<script type="text/javascript">
  let acted = function(){
  const ws = new WebSocket('wss://stream.binance.com:9443/ws/<?php echo $id;?>@miniTicker');
  console.log(ws);


  ws.onmessage = function (event) {
    var data = JSON.parse(event.data);
    console.log(data['c'])

    $('.all_list_price').html(data['c']);

    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> -->
</html>
