Anda di halaman 1dari 13

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.

org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>PoC vsc</title> <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> <script type="text/javascript" src="swfobject.js"></script> <script type="text/javascript" language="javascript" src="vsc.js "></script> <script type="text/javascript" language="javascript"> var vc = null; var currentStockDataFeed = null; var currentBookFeed = null; var ALL_FIELDS = ["idpapel","nome","lotePadrao","variacao_dia"," preco_maximo","preco_minimo","preco_abertura","preco_ultimo","preco_medio","qtde _ultimo","volume","qtde_negocios","qtde_papel_negociado","hora_ultimo","compra_v alor1","compra_valor2","compra_valor3","compra_valor4","compra_valor5","compra_q tde1","compra_qtde2","compra_qtde3","compra_qtde4","compra_qtde5","compra_oferta 1","compra_oferta2","compra_oferta3","compra_oferta4","compra_oferta5","venda_va lor1","venda_valor2","venda_valor3","venda_valor4","venda_valor5","venda_qtde1", "venda_qtde2","venda_qtde3","venda_qtde4","venda_qtde5","venda_oferta1","venda_o ferta2","venda_oferta3","venda_oferta4","venda_oferta5"]; var orderList = null; var accounts = null; function $ (id) { return window.document.getElementById(id); }; function carregarPapel_clickHandler () { var codigo = $('papel').value; if (currentStockDataFeed != null) vc.stopStockDataFeed(currentStockDataFeed); if (currentBookFeed != null) vc.stopBookFeed(currentBookFeed); currentStockDataFeed = vc.startStockDataFeed(codigo, ALL _FIELDS, startStockDataFeed_updateHandler); currentBookFeed = vc.startBookFeed(codigo, startBookFeed _updateHandler); vc.getDelayedMarketDataSnapshot([codigo], getDelayedMark etDataSnapshot_resultHandler); vc.getDelayedMarketDataTimeSeries([codigo], "today", get DelayedMarketDataTimeSeries_resultHandler); vc.getMarketDataTimeSeries([codigo], "today", getDelayed MarketDataTimeSeries_resultHandler); vc.getMarketCap(codigo, getMarketCap_resultHandler); }; function colocarOrdem_submitHandler () { var conta = accounts[$('contaOrdem').value]; var papel = $('papelOrdem').value;

var valor = $('valorOrdem').value; var side = null; if ($('side1').checked) side = "B"; else side = "S"; vc.putNewOrder({account:conta, code:papel, side:side, or derType:2, price:parseFloat(valor), orderQty:100, timeInForce:0}, putNewOrder_re sultHandler); function putNewOrder_resultHandler (result) { if (!result.success) alert(result.description); }; }; function startStockDataFeed_updateHandler (obj) { if (obj.success == false) { alert("Ocorreu um erro: " + obj.description); return; }; updateBook(obj.object); updatePropTable(obj.object); }; function startBookFeed_updateHandler (obj) { if (obj.success == false) { alert("Ocorreu um erro: " + obj.description); return; }; updateBookCompleto(obj.object.compra, $('bookCompleto_co mpra')); updateBookCompleto(obj.object.venda, $('bookCompleto_ven da')); }; function updatePropTable (obj) { for (var i in obj) $('value_' + i).innerHTML = obj[i]; }; function updateBookCompleto (list, target) { function createLine () { var tr = window.document.createElement('tr'); target.appendChild(tr); var td = window.document.createElement('td'); tr.appendChild(td); //td.innerHTML = "Corretora";

var td = window.document.createElement('td'); tr.appendChild(td); //td.innerHTML = "Preo"; var td = window.document.createElement('td'); tr.appendChild(td); //td.innerHTML = "Qtde"; var td = window.document.createElement('td'); tr.appendChild(td); td.innerHTML = target.children.length; }; function removeLine () { target.removeChild(target.children[target.childr en.length-1]); }; var fields = ["key", "id_corretora_valemobi", "mnemonic" , "nome_corretora", "command", "sentido", "qtde", "preco"]; var text = ""; if (target.getElementsByTagName('tr').length != list.len gth) { while (target.getElementsByTagName('tr').length > list.length) removeLine(target); while (target.getElementsByTagName('tr').length < list.length) createLine(target); }; var trs = target.getElementsByTagName('tr'); for (var k = 0; k < list.length; k++) { var tr = trs[k]; var tds = tr.getElementsByTagName('td'); tds[0].innerHTML = list[k].mnemonic; tds[1].innerHTML = list[k].preco; tds[2].innerHTML = list[k].qtde; }; }; function updateBook (obj) { for (var k = 1; k <= 5; k++) { $("venda_valor" + k.toString()).innerHTML = obj[ "venda_valor" + k.toString()]; $("venda_qtde" + k.toString()).innerHTML = obj[" venda_qtde" + k.toString()]; $("venda_oferta" + k.toString()).innerHTML = obj ["venda_oferta" + k.toString()]; $("compra_valor" + k.toString()).innerHTML = obj ["compra_valor" + k.toString()]; $("compra_qtde" + k.toString()).innerHTML = obj[ "compra_qtde" + k.toString()]; $("compra_oferta" + k.toString()).innerHTML = ob j["compra_oferta" + k.toString()]; }; };

function loadHandler () { vc = new ValemobiServiceClient("vsc.swf"); vc.onInitialize = function () { //vc.setAuthentication("4A7624F8E1B97CADF21B79AC BDDA1EE44A7624F90D71573EE7F4089DA04473AE4A7624FA9F23DD7EA28579CB945EF8EB4A7624FB AE7840B93EEFF7230160BFF0"); vc.setAuthentication("coinvalores", "coin2011"); vc.setUnsafeAccessToken("TOKENGERADO"); vc.startOrderFeed(orderFeed_updateHandler); vc.getAccounts(getAccount_resultHandler); carregarPapel_clickHandler(); }; }; function getAccount_resultHandler ($accounts) { var selectContas = $('contaOrdem'); accounts = $accounts; for (var k = 0; k < accounts.length; k++) { var op = window.document.createElement('option') ; op.value = k; op.label = accounts[k].mnbroker + " (" + account s[k].accountnumber + ") " + accounts[k].accounttype; op.innerHTML = accounts[k].mnbroker + " (" + acc ounts[k].accountnumber + ") " + accounts[k].accounttype; selectContas.appendChild(op); }; }; function updateOrderTable () { function createLine () { var tr = window.document.createElement('tr'); target.appendChild(tr); for (var k = 0; k < 7; k++) { var td = window.document.createElement(' td'); tr.appendChild(td); }; td.innerHTML = target.children.length; }; function removeLine () { target.removeChild(target.children[target.childr en.length-1]); }; function getBackgroundColor (code) { switch (code) { case 'REJE': return '#ff0000';

break; }; return '#ffffff'; }; var target = $('tbodyOrdens'); if (target.getElementsByTagName('tr').length != orderLis t.length) { while (target.getElementsByTagName('tr').length > orderList.length) removeLine(); while (target.getElementsByTagName('tr').length < orderList.length) createLine(); }; var trs = target.getElementsByTagName('tr'); for (var k = 0; k < orderList.length; k++) { var tr = trs[k]; var tds = tr.getElementsByTagName('td'); tds[0].innerHTML = '<a href="javascript:cancelar Ordem(' + orderList[k].nu_order + ');">Cancelar</a>'; tds[1].innerHTML = String(orderList[k].dh_creati on_time).replace(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/gi, "$3/$2/$1 $4: $5:$6"); tds[2].innerHTML = orderList[k].cd_stock; tds[3].innerHTML = orderList[k].side; tds[4].innerHTML = orderList[k].price; tds[5].innerHTML = orderList[k].ds_order_status; tds[5].style.backgroundColor = getBackgroundColo r(orderList[k].cd_order_status); }; }; function cancelarOrdem (id) { function handler (result) { if (!result.success) { alert(result.description); }; }; vc.cancelOrder(id, handler); }; function orderFeed_updateHandler (obj) { if (!obj.success) { alert(obj.description); return; }; if (obj.type == 'new') orderList = obj.object; updateOrderTable();

}; function getDelayedMarketDataSnapshot_resultHandler (result) { if (!result.success) { alert("getDelayedMarketDataSnapshot_resultHandle r: " + result.description); return; }; }; function getDelayedMarketDataTimeSeries_resultHandler (result) { if (!result.success) { alert("getDelayedMarketDataTimeSeries_resultHand ler: "+result.description); return; }; }; function getMarketCap_resultHandler (result) { if (!result.success) { alert("getMarketCap_resultHandler: "+result.desc ription); return; }; alert("mcap da empresa: " + result.marketcap); }; function carregarPapel_submitHandler () { carregarPapel_clickHandler(); }; var timeoutID = null; var papelAtual = "PETR4"; function keyUpHandler () { function timeoutHandler () { if (localPapel != papelAtual) return; vc.getStockByParms({code:[$('papel').value]}, ca llback); }; function callback (result) { if (!result.success) { alert("callback: " + result.description) ; return; };

if (localPapel != papelAtual) return; var selectPapel = $('selectPapel'); while (selectPapel.children.length > 0) selectPa pel.removeChild(selectPapel.children[0]); var r = result.object; for (var k = 0; k < r.length; k++) { var op = window.document.createElement(' option'); op.value = r[k].cdStock; op.label = r[k].cdStock; op.innerHTML = r[k].cdStock; selectPapel.appendChild(op); }; }; clearTimeout(timeoutID); if (trim(String($('papel').value).toUpperCase()) != trim (papelAtual.toUpperCase())) { var localPapel = papelAtual = $('papel').value; timeoutID = setTimeout(timeoutHandler, 100); }; }; function focusHandler () { $('selectPapel').style.display = null; }; function blurHandler () { $('selectPapel').style.display = 'none'; }; function trim (str) { return str.replace(/^\s+ \s+$/g,""); }; function getLog_clickHandler () { $('log').value = vc.getLog(); }; </script> </head> <body onload="javascript:loadHandler();"> <div> <form style="float:left;" onsubmit="carregarPapel_submitHandler( ); return false;"> <input style="width:100px;" type="text" id="papel" name= "papel" value="PETR4" onkeyup="javascript:keyUpHandler();" onfocus="javascript:f ocusHandler();" onblur="javascript:blurHandler();" /> <input type="submit" value="Recuperar dados" /> </form> <input type="button" style="float:right" value="get log" onclick ="javascript:getLog_clickHandler();" />

<form style="float:right;" onsubmit="colocarOrdem_submitHandler( ); return false;"> <select id="contaOrdem" name="contaOrdem"></select> <input type="text" id="papelOrdem" name="papelOrdem valu e="PETR4" /> <input type="text" id="valorOrdem" name="valorOrdem" val ue="27.80" /> <input type="radio" id="side1" name="side" value="B" che cked="true" /> Compra <input type="radio" id="side2" name="side" value="S" /> Venda <input type="submit" value="Colocar ordem" /> </form> </div> <div style="position:absolute; left:8px; top:30px;"> <select id="selectPapel" name="selectPapel" size="4" sty le="width:100px; display:none;"> <option>Teste1</option> <option>Teste2</option> <option>Teste3</option> <option>Teste4</option> <option>Teste5</option> <option>Teste6</option> <option>Teste7</option> </select> </div> <div style="float:left;"> <table> <tr> <td align="center" valign="top"> Book Simples<br /> <table> <tr> <td> <table b order="1"> <tr> <th colspan="3">Compra</th> </tr> <tr> <td id="compra_valor1" name="compra_valor1"></td> <td id="compra_qtde1" name="compra_qtde1"></td> <td id="compra_oferta1" name="compra_oferta1"></td> </tr> <tr> <td id="compra_valor2" name="compra_valor2"></td> <td id="compra_qtde2" name="compra_qtde2"></td> <td id="compra_oferta2" name="compra_oferta2"></td>

</tr> <tr> <td id="compra_valor3" name="compra_valor3"></td> <td id="compra_qtde3" name="compra_qtde3"></td> <td id="compra_oferta3" name="compra_oferta3"></td> </tr> <tr> <td id="compra_valor4" name="compra_valor4"></td> <td id="compra_qtde4" name="compra_qtde4"></td> <td id="compra_oferta4" name="compra_oferta4"></td> </tr> <tr> <td id="compra_valor5" name="compra_valor5"></td> <td id="compra_qtde5" name="compra_qtde5"></td> <td id="compra_oferta5" name="compra_oferta5"></td> </tr> </table> </td> <td valign="top" > <table b order="1"> <tr> <th colspan="3">Venda</th> </tr> <tr> <td id="venda_valor1" name="venda_valor1"></td> <td id="venda_qtde1" name="venda_qtde1"></td> <td id="venda_oferta1" name="venda_oferta1"></td> </tr> <tr> <td id="venda_valor2" name="venda_valor2"></td> <td id="venda_qtde2" name="venda_qtde2"></td>

<td id="venda_oferta2" name="venda_oferta2"></td> </tr> <tr> <td id="venda_valor3" name="venda_valor3"></td> <td id="venda_qtde3" name="venda_qtde3"></td> <td id="venda_oferta3" name="venda_oferta3"></td> </tr> <tr> <td id="venda_valor4" name="venda_valor4"></td> <td id="venda_qtde4" name="venda_qtde4"></td> <td id="venda_oferta4" name="venda_oferta4"></td> </tr> <tr> <td id="venda_valor5" name="venda_valor5"></td> <td id="venda_qtde5" name="venda_qtde5"></td> <td id="venda_oferta5" name="venda_oferta5"></td> </tr> </table> </td> </tr> </table> Detalhes<br/> <table border="1"> <tr> <th>Propriedade< /th> <th>Valor</th> </tr> <tr><td>idpapel</td><td id="value_idpapel" name="value_idpapel"></td></tr> <tr><td>nome</td><td id= "value_nome" name="value_nome"></td></tr> <tr><td>lotePadrao</td>< td id="value_lotePadrao" name="value_lotePadrao"></td></tr> <tr><td>variacao_dia</td ><td id="value_variacao_dia" name="value_variacao_dia"></td></tr> <tr><td>preco_maximo</td ><td id="value_preco_maximo" name="value_preco_maximo"></td></tr> <tr><td>preco_minimo</td ><td id="value_preco_minimo" name="value_preco_minimo"></td></tr> <tr><td>preco_abertura</ td><td id="value_preco_abertura" name="value_preco_abertura"></td></tr> <tr><td>preco_ultimo</td

><td id="value_preco_ultimo" name="value_preco_ultimo"></td></tr> <tr><td>preco_medio</td> <td id="value_preco_medio" name="value_preco_medio"></td></tr> <tr><td>qtde_ultimo</td> <td id="value_qtde_ultimo" name="value_qtde_ultimo"></td></tr> <tr><td>volume</td><td i d="value_volume" name="value_volume"></td></tr> <tr><td>qtde_negocios</t d><td id="value_qtde_negocios" name="value_qtde_negocios"></td></tr> <tr><td>qtde_papel_negoc iado</td><td id="value_qtde_papel_negociado" name="value_qtde_papel_negociado">< /td></tr> <tr><td>hora_ultimo</td> <td id="value_hora_ultimo" name="value_hora_ultimo"></td></tr> <tr><td>compra_valor1</t d><td id="value_compra_valor1" name="value_compra_valor1"></td>/tr> <tr><td>compra_valor2</t d><td id="value_compra_valor2" name="value_compra_valor2"></td></tr> <tr><td>compra_valor3</t d><td id="value_compra_valor3" name="value_compra_valor3"></td></tr> <tr><td>compra_valor4</t d><td id="value_compra_valor4" name="value_compra_valor4"></td></tr> <tr><td>compra_valor5</t d><td id="value_compra_valor5" name="value_compra_valor5"></td></tr> <tr><td>compra_qtde1</td ><td id="value_compra_qtde1" name="value_compra_qtde1"></td></tr> <tr><td>compra_qtde2</td ><td id="value_compra_qtde2" name="value_compra_qtde2"></td></tr> <tr><td>compra_qtde3</td ><td id="value_compra_qtde3" name="value_compra_qtde3"></td></tr> <tr><td>compra_qtde4</td ><td id="value_compra_qtde4" name="value_compra_qtde4"></td></tr> <tr><td>compra_qtde5</td ><td id="value_compra_qtde5" name="value_compra_qtde5"></td></tr> <tr><td>compra_oferta1</ td><td id="value_compra_oferta1" name="value_compra_oferta1"></td></tr> <tr><td>compra_oferta2</ td><td id="value_compra_oferta2" name="value_compra_oferta2"></td></tr> <tr><td>compra_oferta3</ td><td id="value_compra_oferta3" name="value_compra_oferta3"></td></tr> <tr><td>compra_oferta4</ td><td id="value_compra_oferta4" name="value_compra_oferta4"></td></tr> <tr><td>compra_oferta5</ td><td id="value_compra_oferta5" name="value_compra_oferta5"></td></tr> <tr><td>venda_valor1</td ><td id="value_venda_valor1" name="value_venda_valor1"></td></tr> <tr><td>venda_valor2</td ><td id="value_venda_valor2" name="value_venda_valor2"></td></tr> <tr><td>venda_valor3</td ><td id="value_venda_valor3" name="value_venda_valor3"></td></tr> <tr><td>venda_valor4</td ><td id="value_venda_valor4" name="value_venda_valor4"></td></tr> <tr><td>venda_valor5</td ><td id="value_venda_valor5" name="value_venda_valor5"></td></tr> <tr><td>venda_qtde1</td> <td id="value_venda_qtde1" name="value_venda_qtde1"></td></tr> <tr><td>venda_qtde2</td> <td id="value_venda_qtde2" name="value_venda_qtde2"></td></tr> <tr><td>venda_qtde3</td> <td id="value_venda_qtde3" name="value_venda_qtde3"></td></tr>

<tr><td>venda_qtde4</td> <td id="value_venda_qtde4" name="value_venda_qtde4"></td></tr> <tr><td>venda_qtde5</td> <td id="value_venda_qtde5" name="value_venda_qtde5"></td></tr> <tr><td>venda_oferta1</t d><td id="value_venda_oferta1" name="value_venda_oferta1"></td></tr> <tr><td>venda_oferta2</t d><td id="value_venda_oferta2" name="value_venda_oferta2"></td></tr> <tr><td>venda_oferta3</t d><td id="value_venda_oferta3" name="value_venda_oferta3"></td></tr> <tr><td>venda_oferta4</t d><td id="value_venda_oferta4" name="value_venda_oferta4"></td></tr> <tr><td>venda_oferta5</t d><td id="value_venda_oferta5" name="value_venda_oferta5"></td></tr> </table> </td> <td align="center" valign="top"> Book Completo<br /> <table> <tr> <td valign="top" align="center"> <table b order="1"> <thead> <tr> <th colspan="4">Compra</th> </tr> </thead> <tbody id="bookCompleto_compra" name="bookCompleto_compra"></tbody> </table> </td> <td valign="top" align="center"> <table b order="1"> <thead> <tr> <th colspan="4">Venda</th> </tr> </thead> <tbody id="bookCompleto_venda" name="bookCompleto_venda"></tbody> </table> </td> </tr> </table> </td> <td valign="top" align="center">

Ordens<br/> <table border="1"> <thead> <tr> <th></th > <th>Data </th> <th>Pape l</th> <th>C/V< /th> <th>Preo</ th> <th>Stat us</th> <th>#</t h> </tr> </thead> <tbody id="tbodyOrdens" name="tbodyOrdens"></tbody> </table> </td> </tr> </table> </div> <textarea id="log" name="log"></textarea> </body> </html>