Forum Moderators: open
<html>
<head>
<script type="text/javascript" src="../jQuery/jquery.js"></script>
<script type="text/javascript" src="../ajax.js"></script>
<style>
span.realTime{
width:100px;
height:15px;
border:0px solid black;
font-family:arial;
font-size:10px;
text-align:center;
color: black;
}
table.tickerContain{
font-family:arial;
font-size:11px;
text-align:center;
}
table.inputAPI{
font-family:arial;
font-size:10px;
}
textarea.input{
font-family:arial;
font-size:10px;
width:100px;
height:15px;
}
</style>
</head>
<body onLoad="initialize()">
<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="db"; // Database name
$tbl_name="tbl"; // Table name
$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="select * from ".$tbl_name." order by DateIn desc;";
$result = mysql_query($sql) or die(mysql_error());
echo '<table class="tickerContain">';
echo '<tr>';
echo '<td>';
echo 'ID';
echo '</td>';
echo '<td>';
echo 'TICKER';
echo '</td>';
echo '<td>';
echo 'SHARES';
echo '</td>';
echo '<td>';
echo 'PRICE';
echo '</td>';
echo '<td>';
echo 'CommIn';
echo '</td>';
echo '<td>';
echo 'CommOut';
echo '</td>';
echo '<td>';
echo 'DateIn';
echo '</td>';
echo '<td>';
echo 'LPrice';
echo '</td>';
echo '<td>';
echo '%CHG';
echo '</td>';
echo '<td>';
echo 'PNL';
echo '</td>';
echo '</tr>';
$tblOut='';
while ($row = mysql_fetch_array($result))
{
$tick='';
$tick=$row["ticker"];
$tblOut.= '<tr>';
$tblOut.= '<td id="'.$tick.'id">';
$tblOut.= $row["id"];
$tblOut.= '</td>';
$tblOut.= '<td id="'.$tick.'ticker">';
$tblOut.= $tick;
$tblOut.= '</td>';
$tblOut.= '<td id="'.$tick.'shares">';
$tblOut.= $row["shares"];
$tblOut.= '</td>';
$tblOut.= '<td id="'.$tick.'price">';
$tblOut.= $row["price"];
$tblOut.= '</td>';
$tblOut.= '<td id="'.$tick.'commissionIn">';
$tblOut.= $row["commissionIn"];
$tblOut.= '</td>';
$tblOut.= '<td id="'.$tick.'commissionOut">';
$tblOut.= $row["commissionOut"];
$tblOut.= '</td>';
$tblOut.= '<td id="'.$tick.'dateIn">';
$tblOut.= $row["dateIn"];
$tblOut.= '</td>';
$tblOut.= '<td>';
$tblOut.= '<span class="realTime" id="'.$tick.'LPrice">--</span>';
$tblOut.= '</td>';
$tblOut.= '<td>';
$tblOut.= '<span class="realTime" id="'.$tick.'pctChange">--</span>';
$tblOut.= '</td>';
$tblOut.= '<td>';
$tblOut.= '<span class="realTime" id="'.$tick.'pnl">--</span>';
$tblOut.= '</td>';
$tblOut.= '</tr>';
}
echo $tblOut;
echo '</table>';
mysql_close($conn);
echo '<table class="inputAPI">';
echo '<tr>';
echo '<td class="inputHead">';
echo 'Id';
echo '</td>';
echo '<td class="inputHead">';
echo 'Ticker';
echo '</td>';
echo '<td class="inputHead">';
echo 'Price';
echo '</td>';
echo '<td class="inputHead">';
echo 'Shares';
echo '</td>';
echo '<td class="inputHead">';
echo 'Commission In';
echo '</td>';
echo '<td class="inputHead">';
echo 'Commission Out';
echo '</td>';
echo '<td class="inputHead">';
echo 'Date In';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="ID"></textarea>';
echo '</td>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="ticker"></textarea>';
echo '</td>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="price"></textarea>';
echo '</td>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="shares"></textarea>';
echo '</td>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="commissionIn"></textarea>';
echo '</td>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="commissionOut"></textarea>';
echo '</td>';
echo '<td>';
echo '<textarea class="input" onFocus="this.select();" id="dateIn"></textarea>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<button onClick="portTool()">Complete</button>';
echo '<button onClick="updater()">Update</button>';
?>
</body>
</html>
<script>
function portTool(){
var ticker=escape(encodeURIComponent(document.getElementById("ticker").value));
var price=escape(encodeURIComponent(document.getElementById("price").value));
var shares=escape(encodeURIComponent(document.getElementById("shares").value));
var commissionIn=escape(encodeURIComponent(document.getElementById("commissionIn").value));
var commissionOut=escape(encodeURIComponent(document.getElementById("commissionOut").value));
var dateIn=escape(encodeURIComponent(document.getElementById("dateIn").value));
window.location="modifyListener.php?ticker="+ticker+"&price="+price+"&shares="+shares+"&commissionIn="+commissionIn+"&commissionOut="+commissionOut+"&dateIn="+dateIn;
}
function updater(){
$('table.tickerContain').css("background-color","yellow");
$a=$('table.tickerContain').children().length;
var myObj=new Array();
$ticker='';
for($i=0;$i<$a;$i++){
for($j=1;$j<$('table.tickerContain').children().eq($i).children().length;$j++){
if($ticker==''){
$ticker=$('table.tickerContain').children().eq($i).children().eq($j).children().eq(1).html();
}else{
$ticker=$ticker+"~"+$('table.tickerContain').children().eq($i).children().eq($j).children().eq(1).html();
}
}
}
$ticker2=escape(encodeURIComponent($ticker));
$.ajax({
url: 'batsListener.php?ticker='+$ticker2,
success: function(data) {
var dataSplit=data.split("@");
for(var k=0;k<dataSplit.length-1;k++){
var dataSplit2=dataSplit[k].split(",");
var lastPrice=(parseFloat(document.getElementById((dataSplit2[0]+"LPrice")).innerHTML));
//document.getElementById((dataSplit2[0]+"LPrice")).innerHTML=dataSplit2[6];
var newPrice=parseFloat(dataSplit2[6]);
if(lastPrice>newPrice){
document.getElementById((dataSplit2[0]+"LPrice")).innerHTML="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+dataSplit2[6]+"</span>";
}else if (lastPrice<newPrice){
document.getElementById((dataSplit2[0]+"LPrice")).innerHTML="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+dataSplit2[6]+"</span>";
}else{
document.getElementById((dataSplit2[0]+"LPrice")).innerHTML="<span style='color:black;'>"+dataSplit2[6]+"</span>"
}
var c=((dataSplit2[6]-(document.getElementById(dataSplit2[0]+"price").innerHTML))/((document.getElementById(dataSplit2[0]+"price").innerHTML)))*100;
var d=c+'';
d=d.substr(0,7);
if(c<0){
c="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+d+"</span>";
}else{
c="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+d+"</span>";
}
document.getElementById((dataSplit2[0]+"pctChange")).innerHTML=c;
var P=((dataSplit2[6]-document.getElementById(dataSplit2[0]+"price").innerHTML)*document.getElementById(dataSplit2[0]+"shares").innerHTML)-(document.getElementById(dataSplit2[0]+"commissionIn").innerHTML+parseFloat(document.getElementById(dataSplit2[0]+"commissionOut").innerHTML));
var Q=P+'';
Q=Q.substr(0,7);
if(P<0){
P="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+Q+"</span>";
}else{
P="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+Q+"</span>";
}
document.getElementById((dataSplit2[0]+"pnl")).innerHTML=P;
$('table.tickerContain').css("background-color","white");
}
}
});
}
function initialize(){
setInterval( "updater()", 5000 );
}
</script>
<html>
<head>
<style type="text/css">
span.realTime {
width:100px;
height:15px;
border:0px solid black;
font-family:arial;
font-size:10px;
text-align:center;
color: black;
}
table.tickerContain {
font-family:arial;
font-size:11px;
text-align:center;
}
table.inputAPI {
font-family:arial;
font-size:10px;
}
textarea.input {
font-family:arial;
font-size:10px;
width:100px;
height:15px;
}
</style>
<title></title>
</head>
<body onLoad="initialize()">
<table class="tickerContain">
<thead>
<tr>
<th>ID</th>
<th>TICKER</th>
<th>SHARES</th>
<th>PRICE</th>
<th>CommIn</th>
<th>CommOut</th>
<th>DateIn</th>
<th>LPrice</th>
<th>%CHG</th>
<th>PNL</th>
</tr>
</thead>
<tbody>
<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="db"; // Database name
$tbl_name="tbl"; // Table name
$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="select * from ".$tbl_name." order by DateIn desc;";
$result = mysql_query($sql) or die(mysql_error());
$tblOut='';
while ($row = mysql_fetch_array($result)) {
$tick=$row["ticker"];
?>
<tr>
<!-- Note, if tick begins with a number, this is invalid -->
<td id="<?php echo $tick;?>id"><?php echo $row["id"];?></td>
<td id="<?php echo $tick;?>ticker"><?php echo $tick;?></td>
<td id="<?php echo $tick;?>shares"><?php echo $row["shares"];?></td>
<td id="<?php echo $tick;?>price"><?php echo $row["price"];?></td>
<td id="<?php echo $tick;?>commissionIn"><?php echo $row["commissionIn"];?></td>
<td id="<?php echo $tick;?>commissionOut"><?php echo $row["commissionOut"];?></td>
<td id="<?php echo $tick;?>dateIn"><?php echo $row["dateIn"];?></td>
<td><span class="realTime" id="<?php echo $tick;?>LPrice">--</span></td>
<td><span class="realTime" id="<?php echo $tick;?>pctChange">--</span></td>
<td><span class="realTime" id="<?php echo $tick;?>pnl">--</span></td>
</tr>
<?php
}
mysql_close($conn);
?>
</tbody>
</table>
<form action="modifyListener.php" method="GET">
<div>
<table class="inputAPI">
<thead>
<tr>
<td class="inputHead">Id</td>
<td class="inputHead">Ticker</td>
<td class="inputHead">Price</td>
<td class="inputHead">Shares</td>
<td class="inputHead">Commission In</td>
<td class="inputHead">Commission Out</td>
<td class="inputHead">Date In</td>
</tr>
</thead>
<tbody>
<tr>
<td><textarea class="input" onfocus="this.select();" id="ID"></textarea></td>
<td><textarea class="input" onfocus="this.select();" id="ticker"></textarea></td>
<td><textarea class="input" onfocus="this.select();" id="price"></textarea></td>
<td><textarea class="input" onfocus="this.select();" id="shares"></textarea></td>
<td><textarea class="input" onfocus="this.select();" id="commissionIn"></textarea></td>
<td><textarea class="input" onfocus="this.select();" id="commissionOut"></textarea></td>
<td><textarea class="input" onfocus="this.select();" id="dateIn"></textarea></td>
</tr>
</tbody>
</table>
<input type="submit" value="Complete">
<button onclick="updater()">Update</button>
</div>
</form>
<script type="text/javascript" src="../jQuery/jquery.js"></script>
<script type="text/javascript" src="../ajax.js"></script>
<script>
function updater(){
var i,
j,
cols,
rows = $('table.tickerContain tbody').children(),
n = rows.length,
ticker = '';
$('table.tickerContain').css("background-color", "yellow");
for (i = 0; i < n; i++) {
for (j = 1, cols = rows.eq(i).children(); j < cols.length; j++) {
if (ticker == '') {
ticker = cols.eq(j).children().eq(1).html();
} else {
ticker += "~" + cols.eq(j).children().eq(1).html();
}
}
}
// escaping AND encoding?
ticker = escape(encodeURIComponent(ticker));
$.ajax({
url: 'batsListener.php?ticker=' + ticker,
success: function(data) {
var dataSplit = data.split("@"),
dataSplit2,
k,
lastPrice,
lastPriceEl,
newPrice,
n,
priceEl,
pctChangeEl,
sharesEl;
for(k = 0, n = dataSplit.length - 1; k < n; k++) {
dataSplit2 = dataSplit[k].split(",");
commInEl = document.getElementById(dataSplit2[0] + "commissionIn");
commOutEl = document.getElementById(dataSplit2[0] + "commissionOut");
lastPriceEl = document.getElementById(dataSplit2[0] + "LPrice");
pnlEl = document.getElementById(dataSplit2[0] + "pnl");
priceEl = document.getElementById(dataSplit2[0] + "price");
pctChangeEl = document.getElementById(dataSplit2[0] + "pctChange");
sharesEl = document.getElementById(dataSplit2[0] + "shares");
lastPrice = (parseFloat(lastPriceEl.innerHTML));
//document.getElementById((dataSplit2[0]+"LPrice")).innerHTML=dataSplit2[6];
newPrice = parseFloat(dataSplit2[6]);
if (lastPrice > newPrice) {
lastPriceEl.innerHTML = "<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>" + dataSplit2[6] + "</span>";
} else if (lastPrice < newPrice) {
lastPriceEl.innerHTML = "<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>" + dataSplit2[6] + "</span>";
} else {
lastPriceEl.innerHTML = "<span style='color:black;'>" + dataSplit2[6] + "</span>"
}
var c = ((dataSplit2[6] - (priceEl.innerHTML)) / (priceEl.innerHTML)) * 100;
var d = c + '';
d = d.substr(0,7);
if (c < 0) {
c = "<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>" + d + "</span>";
} else {
c = "<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>" + d + "</span>";
}
pctChangeEl.innerHTML = c;
var P = ((dataSplit2[6] - priceEl.innerHTML) * sharesEl.innerHTML) - (commInEl.innerHTML + parseFloat(commOutEl.innerHTML));
var Q = P + '';
Q = Q.substr(0,7);
if (P < 0) {
P = "<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>" + Q + "</span>";
} else {
P = "<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>" + Q + "</span>";
}
pnlEl.innerHTML = P;
$('table.tickerContain').css("background-color","white");
}
}
});
}
function initialize() {
setInterval( updater, 5000);
}
</script>
</body>
</html>
function portTool(){
var ticker=escape(encodeURIComponent(document.getElementById("ticker").value));
var price=escape(encodeURIComponent(document.getElementById("price").value));
var shares=escape(encodeURIComponent(document.getElementById("shares").value));
var commissionIn=escape(encodeURIComponent(document.getElementById("commissionIn").value));
var commissionOut=escape(encodeURIComponent(document.getElementById("commissionOut").value));
var dateIn=escape(encodeURIComponent(document.getElementById("dateIn").value));
window.location="modifyListener.php?ticker="+ticker+"&price="+price+"&shares="+shares+"&commissionIn="+commissionIn+"&commissionOut="+commissionOut+"&dateIn="+dateIn;
}
function updater(){
$('table.tickerContain').css("background-color","yellow");
$a=$('table.tickerContain').children().length;
var myObj=new Array();
$ticker='';
for($i=0;$i<$a;$i++){
for($j=1;$j<$('table.tickerContain').children().eq($i).children().length;$j++){
if($ticker==''){
$ticker=$('table.tickerContain').children().eq($i).children().eq($j).children().eq(1).html();
}else{
$ticker=$ticker+"~"+$('table.tickerContain').children().eq($i).children().eq($j).children().eq(1).html();
}
}
}
$ticker2=escape(encodeURIComponent($ticker));
getCustomerInfo($ticker2);
}
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request)
alert("Error initializing XMLHttpRequest!");
function getCustomerInfo(tickers) {
var url = "batsListener.php?ticker="+tickers;
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
$('table.tickerContain').css("background-color","white");
//var response = request.responseText;
updateValues(request.responseText);
}
}
}
function updateValues(response){
var dataSplit=response.split("@");
for(var k=0;k<dataSplit.length-1;k++){
var dataSplit2=dataSplit[k].split(",");
var lastPrice=(document.getElementById(dataSplit2[0]+"LPrice").innerHTML);
lastPriceSplit=lastPrice.split(">");
lastPrice=lastPriceSplit[1];
lastPrice=lastPrice+'';
lastPriceSplit=lastPrice.split("</");
lastPrice=parseFloat(lastPriceSplit[0]);
var newPrice=parseFloat(dataSplit2[6]);
if(lastPrice>newPrice){
document.getElementById((dataSplit2[0]+"LPrice")).innerHTML="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+dataSplit2[6]+"</span>";
}else if (lastPrice<newPrice){
document.getElementById((dataSplit2[0]+"LPrice")).innerHTML="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+dataSplit2[6]+"</span>";
}else{
document.getElementById((dataSplit2[0]+"LPrice")).innerHTML="<span style='background-color:lightgray;color:black;padding-left:2px;padding-right:2px;'>"+dataSplit2[6]+"</span>"
}
var c=((dataSplit2[6]-(document.getElementById(dataSplit2[0]+"price").innerHTML))/((document.getElementById(dataSplit2[0]+"price").innerHTML)))*100;
var d=c+'';
d=d.substr(0,7);
if(c<0){
c="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+d+"</span>";
}else{
c="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+d+"</span>";
}
document.getElementById((dataSplit2[0]+"pctChange")).innerHTML=c;
var P=((dataSplit2[6]-document.getElementById(dataSplit2[0]+"price").innerHTML)*document.getElementById(dataSplit2[0]+"shares").innerHTML)-(document.getElementById(dataSplit2[0]+"commissionIn").innerHTML+parseFloat(document.getElementById(dataSplit2[0]+"commissionOut").innerHTML));
if(k==0){
var bulkPCTo=parseFloat(document.getElementById(dataSplit2[0]+"price").innerHTML)*parseFloat(document.getElementById(dataSplit2[0]+"shares").innerHTML)+(parseFloat(document.getElementById(dataSplit2[0]+"commissionIn").innerHTML)+parseFloat(document.getElementById(dataSplit2[0]+"commissionOut").innerHTML));
var bulkPCTn=parseFloat(document.getElementById(dataSplit2[0]+"shares").innerHTML)*dataSplit2[6];
var bulkPNL=P;
}else{
bulkPCTo+=parseFloat(document.getElementById(dataSplit2[0]+"price").innerHTML)*parseFloat(document.getElementById(dataSplit2[0]+"shares").innerHTML)+(parseFloat(document.getElementById(dataSplit2[0]+"commissionIn").innerHTML)+parseFloat(document.getElementById(dataSplit2[0]+"commissionOut").innerHTML));
bulkPCTn+=parseFloat(document.getElementById(dataSplit2[0]+"shares").innerHTML)*dataSplit2[6];
bulkPNL+=P;
}
var Q=P+'';
Q=Q.substr(0,7);
if(P<0){
P="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+Q+"</span>";
}else{
P="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+Q+"</span>";
}
document.getElementById((dataSplit2[0]+"pnl")).innerHTML=P;
$('table.tickerContain').css("background-color","white");
}
var bulkPCT=100*((bulkPCTn-bulkPCTo)/bulkPCTo);
bulkPCT=bulkPCT+'';
if(bulkPNL<0){
bulkPNL=bulkPNL+'';
bulkPNL=bulkPNL.substr(0,7);
bulkPCT=bulkPCT.substr(0,7);
bulkPNL="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+bulkPNL+"</span>";
bulkPCT="<span style='background-color:red;color:white;padding-left:2px;padding-right:2px;'>"+bulkPCT+"</span>";
}else{
bulkPNL=bulkPNL+'';
bulkPNL=bulkPNL.substr(0,7);
bulkPCT=bulkPCT.substr(0,7);
bulkPNL="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+bulkPNL+"</span>";
bulkPCT="<span style='background-color:green;color:white;padding-left:2px;padding-right:2px;'>"+bulkPCT+"</span>";
}
document.getElementById("consolidatedPNL").innerHTML=bulkPNL;
document.getElementById("consolidatedPCT").innerHTML=bulkPCT;
}
function initialize(){
setInterval( "updater()", 2000 );
}