<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Forex</title>
<meta name="robots" content="noindex">
<meta name="googlebot" content="noindex">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

<script>
$(document).ready(function(){
	$("#setloss").click(function(){
		var loss=$("#proloss").val();
		var trd=$("#trade_id").val();
		if(loss==''){alert("Please enter value");return false;}
		$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>home/ajax_setloss',
			 data: {loss:loss,trd:trd},
			 success: function(res){
				// $("#switch").text(res);
				 alert(res);
				// console.log(res);
				 //$(".exit_trades").html(res);
			 }
		 });
	});
	$("#setlot").click(function(){
		var trd=$("#trade_id").val();
		var lotsize=$("#trd_lot").val();
		var buy_price=$("#buy_pricee").val();
		if(lotsize==''){alert("Please enter value");return false;}
		$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>home/ajax_setlot',
			 data: {trd:trd,lotsize:lotsize,buy_price:buy_price},
			 success: function(res){
				// $("#switch").text(res);
				 alert(res);
				 console.log(res);
				 //$(".exit_trades").html(res);
			 }
		 });
	});
	$("#exit_trade_now").submit(function(e){e.preventDefault();
		var formdata=$(this).serialize();
		$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>home/ajax_exit_trade2',
			 data: {formdata:formdata},
			 success: function(res){
				// $("#switch").text(res);
				 alert(res);
				 console.log(res);
				 //$(".exit_trades").html(res);
			 }
		 });
	});
	$("#switch").click(function(){
		//var st=$(this).
		$.ajax({
			 type: "POST",
			 url: '<?php echo base_url();?>home/ajax_switch_market',
			 data: {market:'switch'},
			 success: function(res){
				 $("#switch").text(res);
				 //console.log(res);z
				 //$(".exit_trades").html(res);
			 }
		 });
	});
	$(".trade_type").click(function(){
		$("#trade_type").val($(this).attr("id"));
	});
	$("#order_type").change(function(){
		if($(this).val()=='Pending'){
			$(".order_val").show();	
		}else{
			$(".order_val").hide();
		}
	});
	$("#exit_trades").click(function(){
		$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_exit_trades',
				 data: {trd:'exit'},
				 success: function(res){
					 //console.log(res);z
					 $(".exit_trades").html(res);
				 }
			 });
	});
	$("#pending_orders").click(function(){
		$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_pending_trades',
				 data: {trd:'pending'},
				 success: function(res){
					 //console.log(res);z
					 $(".pending_orders").html(res);
				 }
			 });
	});
	$(".lotchange").click(function(){
		var id=$(this).attr("id");
		var lot=parseFloat($("#lotsize").text());
			//if(lot || lot<=1){
			if(id=='plus' && lot<5){
				var newlot=lot*10;	
			}else if(lot>0.01){
				var newlot=lot/10;	
			}
			$("#lotsize").text(newlot);
			$("#lot").val(newlot);
	});
	setInterval(function(){ 
			//////////////////////////
			<?php $currs=$this->db->get_where("curr_pips",array("curr_status"=>"yes"))->result();
			$i=1;foreach($currs as $cur){
				$curname=strtoupper(str_replace("-","_",$cur->curr_code));?>
			var <?php echo $curname;?>_sell=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(2)").text(); 
			var <?php echo $curname;?>_buy=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(3)").text();
			var <?php echo $curname;?>_high=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(6)").text(); 
			var <?php echo $curname;?>_low=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(7)").text(); 
			var <?php echo $curname;?>_margin=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(8)").text();
			
			var <?php echo $curname;?>_sell_col=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(2)").css( "background-color" );
			var <?php echo $curname;?>_buy_col=$("#live-rates-4bccd9b2e8354173a4a7e026865a9709 tbody tr:nth-child(<?php echo $i;?>) td:nth-child(3)").css( "background-color" );
			
			
			<?php $i++;}?>

			var XAU_USD_sell=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(2)").text();
			var XAU_USD_buy=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(3)").text();
			var XAU_USD_high=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(6)").text(); 
			var XAU_USD_low=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(7)").text(); 
			var XAU_USD_margin=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(8)").text();			
			var XAU_USD_sell_col=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(2)").css( "background-color" );
			var XAU_USD_buy_col=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(1) td:nth-child(3)").css( "background-color" );

			var XAG_USD_sell=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(2)").text();
			var XAG_USD_buy=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(3)").text();
			var XAG_USD_high=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(6)").text(); 
			var XAG_USD_low=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(7)").text(); 
			var XAG_USD_margin=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(8)").text();			
			var XAG_USD_sell_col=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(2)").css( "background-color" );
			var XAG_USD_buy_col=$("#live-rates-734f3c22323647de8eafb051c58f68ef tbody tr:nth-child(2) td:nth-child(3)").css( "background-color" );

			var BTC_USD_sell=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(2)").text();
			var BTC_USD_buy=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(3)").text();
			var BTC_USD_high=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(6)").text(); 
			var BTC_USD_low=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(7)").text(); 
			var BTC_USD_margin=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(8)").text();			
			var BTC_USD_sell_col=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(2)").css( "background-color" );
			var BTC_USD_buy_col=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(1) td:nth-child(3)").css( "background-color" );

			var ETH_USD_sell=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(2)").text();
			var ETH_USD_buy=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(3)").text(); 
			var ETH_USD_high=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(6)").text(); 
			var ETH_USD_low=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(7)").text(); 
			var ETH_USD_margin=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(8)").text();			
			var ETH_USD_sell_col=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(2)").css( "background-color" );
			var ETH_USD_buy_col=$("#live-rates-176bad5d3a4c4acea6a009aa7995b73a tbody tr:nth-child(2) td:nth-child(3)").css( "background-color" );
			/////////////////
			
			var pair=$("#pairid").val();


			switch(pair){
				<?php $i=1;foreach($currs as $cur){
					$curname=strtoupper(str_replace("-","_",$cur->curr_code));?>
				case '<?php echo $curname;?>':
				$("#buy_val").text(<?php echo $curname;?>_buy);
				$("#sell_val").text(<?php echo $curname;?>_sell);
				$("#buy_price").val(<?php echo $curname;?>_buy);
				$("#sell_price").val(<?php echo $curname;?>_sell);
				$("#buy_color").val(<?php echo $curname;?>_buy_col);
				$("#sell_color").val(<?php echo $curname;?>_sell_col);
				$("#margin").val(<?php echo $curname;?>_margin);
				break;
				<?php $i++;}?>
			}
			var alldata=[<?php $i=1;foreach($currs as $cur){
				$curname=strtoupper(str_replace("-","_",$cur->curr_code));echo $curname;?>_sell+"|"+<?php echo $curname;?>_buy+'|<?php echo $curname;?>|'+<?php echo $curname;?>_buy_col+'|'+<?php echo $curname;?>_sell_col+'|'+<?php echo $curname;?>_margin+'|'+<?php echo $curname;?>_high+'|'+<?php echo $curname;?>_low,<?php }?>];//,AUD_USD_sell+"="+AUD_USD_buy+'=AUD_USD='+AUD_USD_buy_col+'='+AUD_USD_sell_col,USD_JPY_sell+"="+USD_JPY_buy+'=USD_JPY='+USD_JPY_buy_col+'='+USD_JPY_sell_col,GBP_USD_sell+"="+GBP_USD_buy+'=GBP_USD='+GBP_USD_buy_col+'='+GBP_USD_sell_col,USD_CHF_sell+"="+USD_CHF_buy+'=USD_CHF='+USD_CHF_buy_col+'='+USD_CHF_sell_col,USD_CAD_sell+"="+USD_CAD_buy+'=USD_CAD='+USD_CAD_buy_col+'='+USD_CAD_sell_col];
			//console.log(alldata);
			$.ajax({
				 type: "POST",
				 url: '<?php echo base_url();?>home/ajax_trade_calc',
				 data: {alldata:alldata},
				 success: function(res){
					 console.log(res);
					 $("#live_trades").html(res);
				 }
			 });
			 
	}, 2000); 
	});
</script>
</head>

<body>

<div class="container-fluid">
		<h3>Forex Trading</h3>
	<div class="row">
    	<div class="col-md-12">
        <form class="form-inline" action="" method="post" id="change_form">
          <div class="form-group">
            <select class="form-control" id="pairidd" name="pairr" required>
                <option value="">Pair</option>
                <?php $i=1;foreach($currs as $cur){$curname=strtoupper(str_replace("-","_",$cur->curr_code));?>
                <option value="<?php echo $curname;?>"><?php echo strtoupper($cur->curr_code);?></option>
                <?php }?>
            </select>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Buy Value" name="buy_val">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Sell Value" name="buy_val">
          </div>
          <button type="submit" class="btn btn-warning">UPDATE</button>
          <?php $admin=$this->db->get("admin")->row();?>
          <button type="button" id="switch" class="btn btn-info pull-right"><?php echo $admin->live_market;?></button>
        </form>
        <div id="live-rates-4bccd9b2e8354173a4a7e026865a9709" class="live-rates__table"><h3 class="text-danger">Loding Forex...</h3></div>
        <div id="live-rates-734f3c22323647de8eafb051c58f68ef" class="live-rates__table"><h3 class="text-danger">Loding Metals...</h3></div>
        <div id="live-rates-176bad5d3a4c4acea6a009aa7995b73a" class="live-rates__table"><h3 class="text-danger">Loding Crypto...</h3></div>
        </div>
    	<div class="col-md-12">
        <script src="https://prodstorage.azureedge.net/Scripts/jquery.signalR-2.4.0.min.js" defer></script>
		<script src="https://dashboard.acuitytrading.com/Widgets/lib/@1.0.0/widget-core-oanda.js" defer></script>
        <ul class="nav nav-tabs">
          <li class="active"><a data-toggle="tab" href="#menu1">MARKET ORDERS</a></li>
          <li><a data-toggle="tab" href="#menu3" id="pending_orders">PENDING ORDERS</a></li>
          <li><a data-toggle="tab" href="#menu2" id="exit_trades">CLOSED TRADES</a></li>
          <li><a data-toggle="tab" href="#menu4">NEW TRADE</a></li>
        </ul>
        
        <div class="tab-content">
          <div id="menu1" class="tab-pane fade in active" style="padding:5px;">
            <table class="table table-bordered table-striped" id="live_trades">
            	
            </table>
          </div>
          <div id="menu3" class="tab-pane fade" style="padding:5px;">
            <table class="table table-bordered table-striped pending_orders">
            	
            </table>
          </div>
          <div id="menu2" class="tab-pane fade" style="padding:5px;">
            <table class="table table-bordered table-striped exit_trades">
            	
            </table>
          </div>
          <div id="menu4" class="tab-pane fade" style="padding:5px;">
            <form action="<?php echo base_url().'home/trade_submit';?>" method="post">
            	<input type="hidden" name="buy_price" id="buy_price"/>
            	<input type="hidden" name="sell_price" id="sell_price"/>
            	<input type="hidden" name="buy_color" id="buy_color"/>
            	<input type="hidden" name="sell_color" id="sell_color"/>
            	<input type="hidden" name="margin" id="margin"/>
            	
                <div class="row">
                	<div class="form-group col-md-5">
                        <select class="form-control" id="pairid" name="pair" required>
                            <option value="">Select Pair</option>
                            <?php $i=1;foreach($currs as $cur){$curname=strtoupper(str_replace("-","_",$cur->curr_code));?>
                            <option value="<?php echo $curname;?>"><?php echo strtoupper($cur->curr_code);?></option>
                            <?php }?>
                        </select>
                    </div>
                    <div class="form-group col-md-7">
                        <select class="form-control" name="user" required>
                            <option value="">Select User</option>
                            <?php //$this->db->order_by("id","desc");
								  $users=$this->db->get("users")->result();
								  foreach($users as $user){echo "<option value='".$user->id."'>".$user->email."</option>";}?>
                        </select>
                    </div>
                	<div class="col-md-4 text-center">
                    	<h2 class="text-danger" id="buy_val">0</h2>
                    	<button class="btn btn-danger btn-block" type="button">BUY</button>
                    </div>
                    <div class="text-center col-md-4">
                    	<h2 class="text-default">LOT</h2>
                        <select class="form-control" name="lotsize" required>
                        	<option value="0.01">0.01</option>
                        	<option value="0.1">0.1</option>
                        	<option value="1">1</option>
                        	<option value="2">2</option>
                        	<option value="3">3</option>
                        	<option value="4">4</option>
                        	<option value="5">5</option>
                        </select>
                        <!--<div class="btn-group">
                          <button type="button" class="btn btn-primary lotchange" id="minus">-</button>
                          <button type="button" class="btn btn-default" id="lotsize">0.01</button>
                          <input type="hidden" name="lotsize" id="lot" value="0.01"/>
                          <button type="button" class="btn btn-primary lotchange" id="plus">+</button>
                        </div> -->
                    </div>
                    <div class="form-group col-md-4 text-center">
                    	<h2 class="text-success" id="sell_val">0</h2>
                    	<button class="btn btn-success btn-block" type="button">SELL</button>
                    </div>
                    <div class="form-group col-md-4">
                    	<label>Trade Type</label>
                        <select class="form-control" name="trade_type" required>
                            <option value="BUY">BUY</option>
                            <option value="SELL">SELL</option>
                        </select>
                    </div>
                    <div class="form-group col-md-4">
                    	<label>Target</label>
                        <input type="text" class="form-control" name="target">
                    </div>
                    <div class="form-group col-md-4">
                    	<label>Stop Loss</label>
                        <input type="text" class="form-control" name="stoploss">
                    </div>
                    <div class="form-group col-md-4">
                    	<label>Order Type</label>
                        <select class="form-control" name="order_type" id="order_type" required>
                            <option value="Market">Market</option>
                            <option value="Pending">Pending</option>
                        </select>
                    </div>
                    <div class="form-group col-md-4 order_val" style="display:none;">
                    	<label>At Price</label>
                        <input type="text" class="form-control" name="pending_val">
                    </div>
                </div> 
                <button type="submit" class="btn btn-warning">Start Trade</button>
            </form>
          </div>
        </div>
        
        <div id="myModal" class="modal fade" role="dialog">
          <div class="modal-dialog modal-sm">
        
            <!-- Modal content-->
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Edit Trade</h4>
              </div>
              <div class="modal-body trade_data">
                <p>Loading Data...</p>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
            </div>
        
          </div>
        </div>
        <div id="myModal1" class="modal fade" role="dialog">
          <div class="modal-dialog modal-sm">
        
            <!-- Modal content-->
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Exit Trade</h4>
              </div>
              <div class="modal-body trade_data">
                <form action="" method="post" id="exit_trade_now">
                	<!--<div class="form-group">
                    	<label>Select Profit/Loss</label>
                        <select class="form-control" name="proloss" required>
                        	<option value="Credit">Profit</option>
                        	<option value="Debit">Loss</option>
                        </select>
                    </div>-->
                    <div class="form-group">
                    	<label>Profit/Loss</label>
                        <input type="text" class="form-control" name="proloss" id="proloss"/>
                        <input type="hidden" id="trade_id" class="form-control" name="id"/>
                    </div> 
                     
                    <button type="button" id="setloss" class="btn btn-warning">SET LOSS</button>
                    <button type="submit" class="btn btn-danger pull-right">EXIT TRADE</button>
                    <hr/>
                    <div class="form-group">
                    	<label>Qty</label>
                        <input type="text" class="form-control" id="trd_lot" name="lotsize"/>
                    </div>
                    <div class="form-group">
                    	<label>Buy Price</label>
                        <input type="text" class="form-control" id="buy_pricee" name="buy_price"/>
                    </div>
                    <button type="button" id="setlot" class="btn btn-warning">SET LOT</button>
                </form>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              </div>
            </div>
        
          </div>
        </div>

        <script>
				window.addEventListener('load', function(){
					AcuityWidgets.globals({
						apikey: '4b12e6bb-7ecd-49f7-9bbc-2e03644ce41f',
						locale: 'en-GB'
					});
					<?php //if(date("D")!='Sat' && date("D")!="Sun"){?>
					AcuityWidgets.CreateWidget(
						'OandaLiveRates',
						document.getElementById('live-rates-4bccd9b2e8354173a4a7e026865a9709'),
						{
							instruments: [<?php $i=1;foreach($currs as $cur){$curname=strtoupper(str_replace("-","_",$cur->curr_code));?>"<?php echo $curname;?>",<?php }?>]
						}
						
					).mount();

					AcuityWidgets.CreateWidget(
						'OandaLiveRates',
						document.getElementById('live-rates-734f3c22323647de8eafb051c58f68ef'),
						{
							 instrumentType: "metal",
                
                
                    instruments: ["XAU_USD", "XPD_USD", "XPT_USD", "XAG_USD", "XAU_XAG"],
                
                region: "OGM",
                urlTemplate: "/bvi-en/cfds/instruments/{instrument}/",
                instrumentsWithLink: ["XAU_USD", "XPD_USD", "XPT_USD", "XAG_USD", "XAU_XAG"]
						}
						
					).mount();
					
					<?php //}else{?>

					AcuityWidgets.CreateWidget(
            'OandaLiveRates',
            document.getElementById('live-rates-176bad5d3a4c4acea6a009aa7995b73a'),
            {
                
                
                    instruments: ["BTC_USD",  "ETH_USD"],
                
                region: "OGM",
                urlTemplate: "/bvi-en/cfds/instruments/{instrument}/",
                instrumentsWithLink: ["BTC_USD",  "ETH_USD"]
            }
        ).mount();
		<?php //}?>
				});
		</script>
        </div>
        
    </div>
</div>
</body>
</html>