Browse Source

Updated coin mgt block exp pangea instantdex

release/v0.1
vineetbhargav86 9 years ago
parent
commit
cdb9280112
  1. 132
      iguana/app/coin_mgmt.js
  2. 67
      iguana/app/startup.js
  3. 97
      iguana/index.html
  4. 16
      iguana/js/api.js
  5. 135
      iguana/js/blockexplorer.js
  6. 385
      iguana/js/instantdex.js
  7. 120
      iguana/js/pangea.js
  8. 2
      iguana/js/sites.js

132
iguana/app/coin_mgmt.js

@ -30,13 +30,13 @@ coinManagement.CoinStatuses = [
coinManagement.Initialize = function () {
coinManagement.Coins = [
new coinManagement.Coin(6, 'USD', 'US Dollar', 1),
new coinManagement.Coin(2, 'EUR', 'EURO', 2),
new coinManagement.Coin(3, 'GBP', 'British Pound', 3),
new coinManagement.Coin(4, 'INR', 'Indian Rupee', 4),
new coinManagement.Coin(5, 'YEN', 'Japanese Yen', 3)
new coinManagement.Coin(1, 'BTC', 'Bitcoin', 1),
new coinManagement.Coin(2, 'BTCD', 'Bitcoin Dark', 1),
//new coinManagement.Coin(3, 'GBP', 'British Pound', 3),
//new coinManagement.Coin(4, 'INR', 'Indian Rupee', 4),
//new coinManagement.Coin(5, 'YEN', 'Japanese Yen', 3)
];
}
};
coinManagement.GetCoinIndex = function (id) {
@ -52,6 +52,20 @@ coinManagement.GetCoinIndex = function (id) {
}
};
coinManagement.GetCoinIndexBySymbol = function (id) {
if (coinManagement.Coins == null || coinManagement.Coins == undefined) {
return -1;
}
for (var index = 0; index < coinManagement.Coins.length; index++) {
if (coinManagement.Coins[index].Symbol == id) {
console.log('# coin symbol:' + id.toString() + 'is @' + index);
return index;
}
}
};
coinManagement.Post = function (coin) {
if (coin === null || coin === undefined) {
@ -228,15 +242,35 @@ var GetStatusNameHtml = function (id) {
};
var getActionButton = function (id) {
return '<button class="btn btn-raised btn-danger btn-xs coinMgmtActionButton" data-id=' + id + '>Delete</button>';
var getActionButton = function (objCoin) {
if(objCoin.StatusId===3){
return getStopActionButton(objCoin.Id);
}else if(objCoin.StatusId===2 || objCoin.StatusId===4){
return getStartActionButton(objCoin.Id);
}else if(objCoin.StatusId===1){
return getAddActionButton(objCoin.Id);
}
};
var getAddActionButton = function (id) {
return '<button class="btn btn-raised btn-success btn-xs coinMgmtAddActionButton" data-id=' + id + '>Add Coin</button>';
};
var getStopActionButton = function (id) {
// return '<button class="btn btn-raised btn-success btn-xs coinMgmtStartActionButton" data-id=' + id + '>Start Coin</button>';
return '<button class="btn btn-raised btn-danger btn-xs coinMgmtStopActionButton" data-id=' + id + '>Pause Coin</button>';
};
var getStartActionButton = function (id) {
// return '<button class="btn btn-raised btn-success btn-xs coinMgmtStartActionButton" data-id=' + id + '>Start Coin</button>';
return '<button class="btn btn-raised btn-success btn-xs coinMgmtStartActionButton" data-id=' + id + '>Start Coin</button>';
};
var objToHtml = function (objCoin) {
if (objCoin == null || objCoin == undefined) {
return '';
}
return '<tr><td>' + objCoin.Symbol + '</td><td>' + objCoin.Description + '</td><td>' + GetStatusNameHtml(objCoin.StatusId) + '</td><td>' + getActionButton(objCoin.Id) + '</td></tr>';
return '<tr><td>' + objCoin.Symbol + '</td><td>' + objCoin.Description + '</td><td>' + GetStatusNameHtml(objCoin.StatusId) + '</td><td>' + getActionButton(objCoin) + '</td></tr>';
};
var addCoin = function (e) {
@ -244,7 +278,7 @@ var addCoin = function (e) {
console.log('# add coin called');
e.target.removeAttribute('data-dismiss');
if (coinEditFormIsValid() == false) {
if (coinEditFormIsValid() === false) {
console.log('# add coin form is invalid');
return;
}
@ -283,11 +317,85 @@ var deleteCoin = function (id) {
renderGrid();
};
var pauseCoin = function (id) {
console.log('# coin pause called');
var index = coinManagement.GetCoinIndex(id);
var coin=coinManagement.Coins[index].Symbol;
console.log("clicked on coin "+coin);
var request="{\"agent\":\"iguana\",\"method\":\"pausecoin\",\"coin\":\""+coin+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result && response.result ==="coin paused"){
var indx=coinManagement.GetCoinIndexBySymbol(request.coin);
coinManagement.Coins[indx].StatusId=4;
console.log("coins status changed "+coinManagement.Coins[indx].StatusId);
renderGrid();
}
});
};
var startCoin = function (id) {
console.log('# coin start called');
//coinManagement.Delete(id);
var index = coinManagement.GetCoinIndex(id);
var coin=coinManagement.Coins[index].Symbol;
console.log("clicked on coin "+coin);
var request="{\"agent\":\"iguana\",\"method\":\"startcoin\",\"coin\":\""+coin+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result && response.result ==="coin started"){
var indx=coinManagement.GetCoinIndexBySymbol(request.coin);
coinManagement.Coins[indx].StatusId=3;
console.log("coins status changed "+coinManagement.Coins[indx].StatusId);
renderGrid();
}
});
};
var addExistingCoin = function (id) {
var isactive=0;
var maxpeers=16;
var services=128;
var index = coinManagement.GetCoinIndex(id);
console.log('# coin add called '+index);
var coin=coinManagement.Coins[index].Symbol;
console.log("clicked on coin "+coin);
var request="{\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\""+coin+"\",\"active\":"+isactive+",\"maxpeers\":"+maxpeers+",\"services\":"+services+"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result && (response.result ==="coin added" || response.result ==="coin already there")){
var indx=coinManagement.GetCoinIndexBySymbol(request.newcoin);
coinManagement.Coins[indx].StatusId=2;
console.log("coins status changed "+coinManagement.Coins[indx].StatusId);
renderGrid();
}
});
};
var initCoinsAdded=false;
var addInitCoins= function(){
if(!initCoinsAdded){
for (var index = 0; index < coinManagement.Coins.length; index++) {
addExistingCoin(coinManagement.Coins[index].Id);
}
initCoinsAdded=true;
}
};
var coinEditFormReset = function () {
document.getElementById('txtSymbol').value = '';
document.getElementById('txtDescription').value = '';
document.getElementById('ddStatus').value = 1;
}
};
// Event Handlers
var startCoinManagement = function () {
@ -302,4 +410,4 @@ var startCoinManagement = function () {
renderGrid();
populateCoinStatusDropDown();
}
};

67
iguana/app/startup.js

@ -4,6 +4,7 @@ $(function () {
$(".select ").dropdown({ "autoinit ": ".select " });
startCoinManagement();
startBlockExplorer();
//startPeerManagement();
// Event Handlers
@ -11,8 +12,12 @@ $(function () {
// $('.coinMgmtActionButton').click equivelant w/o jQuery
document.body.onclick = function (e) {
e = window.event ? event.srcElement : e.target;
if (e.className && e.className.indexOf('coinMgmtActionButton') != -1) {
deleteCoin(e.getAttribute('data-id'));
if (e.className && e.className.indexOf('coinMgmtStartActionButton') != -1) {
startCoin(e.getAttribute('data-id'));
} else if (e.className && e.className.indexOf('coinMgmtAddActionButton') != -1) {
addExistingCoin(e.getAttribute('data-id'));
} else if (e.className && e.className.indexOf('coinMgmtStopActionButton') != -1) {
pauseCoin(e.getAttribute('data-id'));
}
else if (e.className && e.className.indexOf('addPeerToFav') != -1) {
addPeerToFav(e.getAttribute('data-id'),e.getAttribute('data-coin'));
@ -25,6 +30,64 @@ $(function () {
}else if(e.className && e.className.indexOf('connectPeer') != -1){
connectPeer(e.getAttribute('data-ip'),e.getAttribute('data-coin'));
}else if(e.className && e.className.indexOf('coinRPCactive') != -1){
callBlockEXPRPC(e.getAttribute('data-value'));
}else if(e.className && e.className.indexOf('getBlockHashActionButton') != -1){
getBlockhash(e.getAttribute('data-height'));
}else if(e.className && e.className.indexOf('getBlockActionButton') != -1){
getBlock(e.getAttribute('data-hash'));
}else if(e.className && e.className.indexOf('getTrancationActionButton') != -1){
getRawTransaction(e.getAttribute('data-hash'));
}
else if(e.className && e.className.indexOf('host_pangea_request') != -1){
hostPangea();
}
else if(e.className && e.className.indexOf('list_pangea_request') != -1){
lobbyPangea();
}
else if(e.className && e.className.indexOf('join_pangea_game') != -1){
joinPangea(e.getAttribute("data-tablehash"));
}
else if(e.className && e.className.indexOf('instantdex_set_keypair') != -1){
setUeseridandAPIkeyPair();
}
else if(e.className && e.className.indexOf('instantdex_orderbook') != -1){
orderbook();
}
else if(e.className && e.className.indexOf('instantdex_set_method_table') != -1){
instantdex_set_method_table(e.getAttribute("data-method"));
}
else if(e.className && e.className.indexOf('instantdex_sell') != -1){
InstantDEXSell();
}
else if(e.className && e.className.indexOf('instantdex_buy') != -1){
InstantDEXBuy();
}
else if(e.className && e.className.indexOf('instantdex_balance') != -1){
InstantDEX_balance();
}
else if(e.className && e.className.indexOf('instantdex_support') != -1){
InstantDEX_supports();
}
else if(e.className && e.className.indexOf('instantdex_withdraw') != -1){
InstantDEXWithdaw();
}
else if(e.className && e.className.indexOf('instantdex_order_status') != -1){
InstantDEX_orderstatus();
}
else if(e.className && e.className.indexOf('instantdex_open_orders') != -1){
InstantDEX_openorders();
}
else if(e.className && e.className.indexOf('instantdex_trade_history') != -1){
InstantDEX_tradehistory();
}
else if(e.className && e.className.indexOf('instantdex_order_cancel') != -1){
InstantDEX_cancelorder();
}
else if(e.className && e.className.indexOf('instantdex_pollgap') != -1){
InstantDEX_pollgap();
}
///instantdex_pollgap
};
});

97
iguana/index.html

@ -52,7 +52,7 @@ data-path="{tc}/{config}">
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse">
<ul class="nav navbar-nav">
<li id="welcome"><a href="#">Welcome <span class="sr-only">(current)</a></li>
<li id="welcome"> <!--<a href="#">Welcome <span class="sr-only">(current)</span></a>--></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">More <span class="caret"></span></a>
@ -75,9 +75,9 @@ data-path="{tc}/{config}">
<!-- /.container-fluid -->
</nav>
<div class="container">
<div id="welcome_page" class="page" style="text-align: center;">
<!--<div id="welcome_page" class="page" style="text-align: center;">
<div class="panel panel-default">
<!-- Default panel contents -->
<!-- Default panel contents
<div class="panel-heading">Welcome</div>
<div class="panel-body">
<h2>iguana</h2>
@ -92,9 +92,9 @@ data-path="{tc}/{config}">
</p>
</div>
</div>
</div>
</div>-->
<!-- eyedea page is for creating front-end markup -->
<div id="eyedea_page" class="page">
<div id="Pangea_page" class="page">
<div class="row" style="margin-bottom:15px;">
<div class="col-xs-4 col-sm-3 col-md-2">
<div class="api-navpills">
@ -116,7 +116,8 @@ data-path="{tc}/{config}">
<textarea name="json_to_submit" id="json_src" cols="30" rows="5" class="result form-control" placeholder='Paste json here'></textarea>
</div>
<div class="form-group">
<button class="btn btn-primary submit_api_request" id='submit_primary'>Submit</button>
<button class="btn btn-primary host_pangea_request" id='submit_primary'>Host game</button>
<button class="btn btn-primary list_pangea_request" id='list_pangea'>List games</button>
</div>
</div>
</div>
@ -131,12 +132,12 @@ data-path="{tc}/{config}">
</div>
<hr>
<h3>
<span>Submitted JSON history</span>
<button id="clearHistory" style='float: right' class='btn btn-default'>Clear history</button>
<span>List of games</span>
<!--<button id="clearHistory" style='float: right' class='btn btn-default'>Clear history</button>-->
</h3>
<div class="row">
<div class="col-md-12">
<table class="table" id='submit_history'>
<table class="table" id='game_list_table'>
<tbody>
</tbody>
@ -361,10 +362,31 @@ data-path="{tc}/{config}">
<h3>Block Explorer tab</h3>
</div>
<div class="panel-body center">
<h3>Block Explorer</h3>
<p>
Page dedicated to searching blockchain.
</p>
<h3>Set Active coin</h3>
<div id="BlockExpCoin">
</div>
<div id="Blockhashbutton">
</div>
<div id="Blockhashoutput">
</div>
<div id="Blockbutton">
</div>
<div id="Blockoutput">
</div>
<div id="transactionButton">
</div>
<div id="transactionoutput">
</div>
<p>
** Awaiting specific requirements **
</p>
@ -376,6 +398,52 @@ data-path="{tc}/{config}">
}
</style>
</div>
<div id="Instandex_page" class="page">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
<h3>Instandex tab</h3>
</div>
<div class="panel-body center">
<button class="btn btn-primary instantdex_set_method_table" data-method="orderbook" >orderbook</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="apikeypair" >API Keypair</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="balance" >Balance</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="support" >Support</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="sell" >Sell</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="buy" >Buy</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="withdraw" >Withdraw</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="order_status" >Order status </button>
<button class="btn btn-primary instantdex_set_method_table" data-method="order_open" >Open Orders</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="order_cancel" >Cancel Order</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="trade_history" >Trade History</button>
<button class="btn btn-primary instantdex_set_method_table" data-method="pollgap" >Pollgap</button>
</div>
<div class="panel-body center">
<table id="Instandex_form_table">
</table>
<table >
<tr>
<td id="Instandex_output_table">
</td>
</tr>
</table>
</div>
</div>
<style type="text/css">
#Blockexplorer_page .center {
text-align: center;
}
</style>
</div>
<div id="listener"></div>
@ -410,6 +478,9 @@ data-path="{tc}/{config}">
<script type="text/javascript " src="js/methods.js " charset="utf-8 "></script>
<script type="text/javascript " src="js/settings.js " charset="utf-8 "></script>
<script type="text/javascript " src="js/imgAPI.js " ></script>
<script type="text/javascript " src="js/pangea.js" ></script>
<script type="text/javascript " src="js/blockexplorer.js" ></script>
<script type="text/javascript " src="js/instantdex.js" ></script>
</body>
</html>

16
iguana/js/api.js

@ -11,9 +11,9 @@ function tagGen(len)
var SPNAPI = (function(SPNAPI, $, undefined) {
SPNAPI.methods = {};
SPNAPI.pages = ["Settings", "eyedea", "Peers","Debug", "Coins", "Blockexplorer"];
SPNAPI.pages = ["Settings","Instandex", "Pangea", "Peers","Debug", "Coins", "Blockexplorer"];
SPNAPI.pageContent = {};
SPNAPI.page = "welcome";
SPNAPI.page = "Blockexplorer";
/*
* added variables for flexibility
*/
@ -39,11 +39,15 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
}else if(page==="Debug"){
filesystem_save();
}else if(page==="Coins"){
addInitCoins();
}else if(page==="Instandex"){
ListAllExchanges();
}
});
$(".page").hide();
$("#welcome_page").show();
$("#Blockexplorer_page").show();
$(".submit_api_request").on("click", function () {
SPNAPI.submitRequest();
});
@ -136,6 +140,12 @@ $.ajax({
if(i==="agent" ||i==="method"){
continue;
}
if(request[i] instanceof Array ){
for(var x in request[i]){
url=url+i+"/"+request[i][x]+"/";
}
continue;
}
url=url+i+"/"+request[i]+"/";
}
console.log("Url generated from request:"+url);

135
iguana/js/blockexplorer.js

@ -0,0 +1,135 @@
/*
*
* Variables to store values:
*
*/
var BlockHash="";
var Block="";
var checkExternalBlock=0;
/*
*
* @returns {undefined}
* the function sets output to show radio buttons
* And then select between coins to start RPC calls
*
*/
var setCoinRadio=function(){
var html="";
for (var index = 0; index < coinManagement.Coins.length; index++) {
var coin=coinManagement.Coins[index].Symbol;
html=html+'<label class="radio-inline"><input class="coinRPCactive" type="radio" name="blockEXPcoin" data-value="'+coin+'">'+coin+'</label>';
}
document.getElementById('BlockExpCoin').innerHTML = html;
};
/*
*
* @param {type} coin
* @returns {undefined}
* called when user click on one of radio buttons
* to start RPC for particular coin
*/
var callBlockEXPRPC=function(coin){
var request="{\"agent\":\"SuperNET\",\"method\":\"bitcoinrpc\",\"setcoin\":\""+coin+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result && response.result==='set bitcoin RPC coin'){
document.getElementById('Blockhashbutton').innerHTML='<button class="btn btn-raised btn-success btn-xs getBlockHashActionButton" data-height="0">Get blockhash</button>';
}
});
};
/*
*
* @param {type} height
* @returns {undefined}
* Function gets the blockhash when called and is stored in global variable
* (initially height is set to zero)
*
*/
var getBlockhash= function(height){
var request="{\"agent\":\"ramchain\",\"method\":\"getblockhash\",\"height\":\""+height+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result){
BlockHash=response.result;
//Blockhashoutput
document.getElementById('Blockhashoutput').innerHTML='Blockhash is: '+BlockHash;
document.getElementById('Blockbutton').innerHTML='<button class="btn btn-raised btn-success btn-xs getBlockActionButton" data-hash="'+BlockHash+'">Get block</button>';
}
});
};
/*
*
* @param {type} hash
* @returns {undefined}
* Function gets Block for a paritculat blockhash
* and store inside global varianle
*
*/
var getBlock= function(hash){
var request="{\"agent\":\"ramchain\",\"method\":\"getblock\",\"blockhash\":\""+hash+"\",\"remoteonly\":\""+checkExternalBlock+"\"}";
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result){
document.getElementById('Blockoutput').innerHTML=response.result;
Block=response.result;
document.getElementById('transactionButton').innerHTML='<button class="btn btn-raised btn-success btn-xs getTrancationActionButton" data-hash="'+Block+'">Get transaction</button>';
}
});
};
/*
*
* @param {type} Hash
* @returns {undefined}
* Function implements getrawtransaction API call to get raw transaction
*
*/
// Example Txids used
//0b9cf7e23c07dc02e31392548e743605df8f90acacfd749ae6aaa0457d62d08a
//081ed782fdcf940de229e89336247e1bcce3599613af26d9c47a8eb18d6a3bb7
//e7386986f14c994d6c70e8eb60753ea1fe2dc2a58567e6269dc6b04ef5310693
//5f7edfb417855f80b7c12e1a9c040f8b496db23c82c90e4de905b8cff8139f03
var getRawTransaction=function(Hash){
var request="{\"agent\":\"ramchain\",\"method\":\"getrawtransaction\",\"txid\":\"5f7edfb417855f80b7c12e1a9c040f8b496db23c82c90e4de905b8cff8139f03\",\"verbose\":1}";
SPNAPI.makeRequest(request, function(request,response){
/*response=JSON.parse(response);
if(response.result){
document.getElementById('Blockoutput').innerHTML=response.result;
//document.getElementById('Blockbutton').innerHTML='<button class="btn btn-raised btn-success btn-xs getBlockActionButton" data-hash="'+BlockHash+'">Get block</button>';
}*/
});
};
/*
*
* called initially
*
*/
var startBlockExplorer=function(){
setCoinRadio();
};

385
iguana/js/instantdex.js

@ -0,0 +1,385 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var exchanges="";
var saved_exchanges=false;
var setUeseridandAPIkeyPair=function(){
InstantDEX_setuserid();
};
var setAPIkeyPair=function(){
var exchange=$('#Instandex_exchange').val();
var apikey=$('#Instandex_apikey').val();
var passphrase=$('#Instandex_apipassphrase').val();
var request='{"agent":"InstantDEX","method":"apikeypair","exchange":"'+exchange+'","apikey":"'+apikey+'","apisecret":"'+passphrase+'"}';
SPNAPI.makeRequest(request, function(request,response){
//response=JSON.parse(response);
$('#Instandex_output_table').append(response);
}
);
};
/*
*
THREE_STRINGS(InstantDEX,setuserid,exchange,userid,tradepassword);
*/
var InstantDEX_setuserid=function(){
var exchange=$('#Instandex_exchange').val();
var userid=$('#Instandex_userid').val();
var tradepassword=$('#Instandex_tradepassword').val();
var request='{"agent":"InstantDEX","method":"setuserid","exchange":"'+exchange+'","userid":"'+userid+'","tradepassword":"'+tradepassword+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
setAPIkeyPair();
});
};
var ListAllExchanges=function(){
if(!saved_exchanges){
var request='{"agent":"InstantDEX","method":"allexchanges"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.result && response.result instanceof Array ){
for(var i in response.result){
$('#Instandex_exchange').append('<option value="'+response.result[i]+'">'+response.result[i]+'</option>');
exchanges=exchanges+'<option value="'+response.result[i]+'">'+response.result[i]+'</option>';
}
saved_exchanges=true;
}
}
);}
};
//THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfields,invert);
var orderbook=function(){
var exchange=$('#Instandex_exchange').val();
var base=$('#Instandex_base').val();
var rel=$('#Instandex_rel').val();
var depth=$('#Instandex_orderbook_depth').val();
var request='{"agent":"InstantDEX","method":"orderbook","exchange":"'+exchange+'","base":"'+base+'","rel":"'+rel+'","depth":'+depth+',"allfields":0,"invert":0}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html("");
/*
*
* {"exchange":"btce","inverted":0,"base":"LTC","rel":"BTC","bids":[0.00814000, 0.00813000, 0.00812000, 0.00811000, 0.00810000, 0.00809000, 0.00808000, 0.00807000, 0.00806000, 0.00805000, 0.00804000, 0.00803000, 0.00802000, 0.00801000, 0.00800000, 0.00799000, 0.00798000, 0.00797000, 0.00796000, 0.00795000],"asks":[0.00816000, 0.00817000, 0.00818000, 0.00819000, 0.00820000, 0.00821000, 0.00822000, 0.00823000, 0.00824000, 0.00825000, 0.00826000, 0.00827000, 0.00828000, 0.00829000, 0.00830000, 0.00831000, 0.00832000, 0.00833000, 0.00834000, 0.00835000],"numbids":20,"numasks":20,"highbid":0.00814000,"lowask":0.00816000,"timestamp":1454329614,"time":"2016-02-01T12:26:54Z","maxdepth":20,"tag":"374388797247258721"}
*/
$('#Instandex_output_table').append("<tr class='row history-row'><th width='100px'>Bid price</th><th width='100px'>Ask price</th></tr>");
response=JSON.parse(response);
for(var i=0;i<response.numbids;i++){
$('#Instandex_output_table').append("<tr class='row history-row'><td>"+response.bids[i]+"</td><td>"+response.asks[i]+"</td></tr>");
}
});
};
/*
*
THREE_STRINGS_AND_THREE_DOUBLES(InstantDEX,buy,exchange,base,rel,price,volume,dotrade);
THREE_STRINGS_AND_THREE_DOUBLES(InstantDEX,sell,exchange,base,rel,price,volume,dotrade);
THREE_STRINGS_AND_DOUBLE(InstantDEX,withdraw,exchange,base,destaddr,amount);
*/
var InstantDEXBuy=function(){
var exchange=$('#Instandex_exchange').val();
var base=$('#Instandex_base').val();
var rel=$('#Instandex_rel').val();
var price=$('#Instandex_price').val();
var request='{"agent":"InstantDEX","method":"buy","exchange":"'+exchange+'","base":"'+base+'","rel":"'+rel+'","price":'+price+',"volume":0,"dotrade":0}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
var InstantDEXSell=function(){
var exchange=$('#Instandex_exchange').val();
var base=$('#Instandex_base').val();
var rel=$('#Instandex_rel').val();
var price=$('#Instandex_price').val();
var request='{"agent":"InstantDEX","method":"sell","exchange":"'+exchange+'","base":"'+base+'","rel":"'+rel+'","price":'+price+',"volume":0,"dotrade":0}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
var InstantDEXWithdaw=function(){
var exchange=$('#Instandex_exchange').val();
var base=$('#Instandex_base').val();
var destinationaddr=$('#Instandex_destaddr').val();
var amount=$('#Instandex_amount').val();
var request='{"agent":"InstantDEX","method":"withdraw","exchange":"'+exchange+'","base":"'+base+'","destaddr":"'+destinationaddr+'","amount":'+amount+'}';
console.log(request);
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
/*
*
THREE_STRINGS(InstantDEX,supports,exchange,base,rel);
*/
var InstantDEX_supports=function(){
var exchange=$('#Instandex_exchange').val();
var base=$('#Instandex_base').val();
var rel=$('#Instandex_rel').val();
var request='{"agent":"InstantDEX","method":"supports","exchange":"'+exchange+'","userid":"'+base+'","rel":"'+rel+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
/*
*
*
* TWO_STRINGS(InstantDEX,balance,exchange,base); */
var InstantDEX_balance=function(){
var exchange=$('#Instandex_exchange').val();
var base=$('#Instandex_base').val();
var request='{"agent":"InstantDEX","method":"balance","exchange":"'+exchange+'","base":"'+base+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html("");
response=JSON.parse(response);
for(var i in response){
if(i==='tag') continue;
$('#Instandex_output_table').append("<tr><th width='100px'>"+i+"</th><td width='200px'>"+response[i]+"</td></tr>");
}
});
};
/*
*
* TWO_STRINGS(InstantDEX,orderstatus,exchange,orderid);
*/
var InstantDEX_orderstatus=function(){
var exchange=$('#Instandex_exchange').val();
var orderid=$('#Instandex_orderid').val();
var request='{"agent":"InstantDEX","method":"orderstatus","exchange":"'+exchange+'","orderid":"'+orderid+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
/*
*
TWO_STRINGS(InstantDEX,cancelorder,exchange,orderid);
* */
var InstantDEX_cancelorder=function(){
var exchange=$('#Instandex_exchange').val();
var orderid=$('#Instandex_orderid').val();
var request='{"agent":"InstantDEX","method":"cancelorder","exchange":"'+exchange+'","orderid":"'+orderid+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
/*
* STRING_ARG(InstantDEX,openorders,exchange);
*/
var InstantDEX_openorders=function(){
var exchange=$('#Instandex_exchange').val();
var request='{"agent":"InstantDEX","method":"openorders","exchange":"'+exchange+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
/*
*
STRING_ARG(InstantDEX,tradehistory,exchange);
* */
var InstantDEX_tradehistory=function(){
var exchange=$('#Instandex_exchange').val();
var request='{"agent":"InstantDEX","method":"tradehistory","exchange":"'+exchange+'"}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
/*
* STRING_AND_INT(InstantDEX,pollgap,exchange,pollgap);
*/
var InstantDEX_pollgap=function(){
var exchange=$('#Instandex_exchange').val();
var pollgap=$('#Instandex_pollgap').val();
var request='{"agent":"InstantDEX","method":"pollgap","exchange":"'+exchange+'","pollgap":'+pollgap+'}';
SPNAPI.makeRequest(request, function(request,response){
$('#Instandex_output_table').html(response);
});
};
var set_apikeypass_table=function (){
var html='<tr><td> UserID:</td><td><input type="text" id="Instandex_userid"/></td></tr><tr><td> Password:</td><td><input type="text" id="Instandex_tradepassword"/></td></tr><tr><td> Apikey:</td><td><input type="text" id="Instandex_apikey"/></td></tr><tr><td> Passphrase:</td><td><input type="text" id="Instandex_apipassphrase"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_set_keypair" >Set keypair</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_orderbook_table=function (){
var html='<tr><td> Base:</td><td><input type="text" id="Instandex_base"/></td></tr><tr><td>Rel:</td><td><input type="text" id="Instandex_rel"/></td></tr><tr><td>Depth:</td><td><input type="text" id="Instandex_orderbook_depth"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_orderbook" >orderbook</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_sell_table=function (){
var html='<tr><td> Base:</td><td><input type="text" id="Instandex_base"/></td></tr><tr><td>Rel:</td><td><input type="text" id="Instandex_rel"/></td></tr><tr><td>Price:</td><td><input type="text" id="Instandex_price"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_sell" >Sell</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_buy_table=function (){
var html='<tr><td> Base:</td><td><input type="text" id="Instandex_base"/></td></tr><tr><td>Rel:</td><td><input type="text" id="Instandex_rel"/></td></tr><tr><td>Price:</td><td><input type="text" id="Instandex_price"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_buy" >Buy</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_balance_table=function (){
var html='<tr><td> Base:</td><td><input type="text" id="Instandex_base"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_balance" >Check balance</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_support_table=function (){
var html='<tr><td> Base:</td><td><input type="text" id="Instandex_base"/></td></tr><tr><td>Rel:</td><td><input type="text" id="Instandex_rel"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_support" >Check Support</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_withdraw_table=function (){
var html='<tr><td> Base:</td><td><input type="text" id="Instandex_base"/></td></tr><tr><td>Destination address:</td><td><input type="text" id="Instandex_destaddr"/></td></tr><tr><td>Amount:</td><td><input type="text" id="Instandex_amount"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_withdraw" >Withdraw</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_order_status_table=function (){
var html='<tr><td> Order ID:</td><td><input type="text" id="Instandex_orderid"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_order_status" >Check order status</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_open_order_table=function (){
var html='<tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_open_orders" >Open orders</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_trade_history_table=function (){
var html='<tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_trade_history" >See Trade History</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_order_cancel_table=function (){
var html='<tr><td> Order ID:</td><td><input type="text" id="Instandex_orderid"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_order_cancel" >Cancel order</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var set_pollgap_table=function (){
var html='<tr><td> Pollgap:</td><td><input type="text" id="Instandex_pollgap"/></td></tr><tr><td> Exchange:</td><td><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td> <button class="btn btn-primary instantdex_pollgap" >Pollgap</button></td><td></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
};
var instantdex_set_method_table=function (method){
if(method==="apikeypair"){
set_apikeypass_table();
}else if(method==="orderbook"){
set_orderbook_table();
}else if(method==="sell"){
set_sell_table();
}else if(method==="buy"){
set_buy_table();
}else if(method==="balance"){
set_balance_table();
}
else if(method==="support"){
set_support_table();
}
else if(method==="withdraw"){
set_withdraw_table();
}
else if(method==="order_status"){
set_order_status_table();
}
else if(method==="order_open"){
set_open_order_table();
}
else if(method==="order_cancel"){
set_order_cancel_table();
}
else if(method==="trade_history"){
set_trade_history_table();
}
else if(method==="pollgap"){
set_pollgap_table();
}
else{
console.log("wrong method value");
}
$('#Instandex_output_table').html("");
};

120
iguana/js/pangea.js

@ -0,0 +1,120 @@
/*
* Implement basic commands
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"pangea\",\"method\":\"host\",\"minplayers\":2,\"params\":[]}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"pangea\",\"method\":\"lobby\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"pangea\",\"method\":\"join\",\"tablehash\":\"18e9e7448a68a4d46bfde55be0e667c4f4ba015e2c183fbc7cbc0c26996f7656\",\"handle\":\"mini\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"pangea\",\"method\":\"start\",\"tablehash\":\"18e9e7448a68a4d46bfde55be0e667c4f4ba015e2c183fbc7cbc0c26996f7656\"}"
*
*/
/*
* Saves data in format
* {"tablehash":"9542c00ef64a73814e5694011703a69608c528c077b55cf7669d77432b7bb32b","host":"0.0.0.0","minbuyin":0,"maxbuyin":0,"minplayers":2,"maxplayers":2,"M":0,"N":2,"numcards":52,"rake":0,"maxrake":0,"hostrake":0,"pangearake":0,"bigblind":0,"ante":0,"opentime":"2016-01-30T11:30:22Z","numactive":0}
*/
var Tables=[];
/*
* JS function to check if String is JSON
* If yes it returns the JSON object as output
*
*/
function IsJsonString(str) {
var json;
try {
json=JSON.parse(str);
} catch (e) {
return false;
}
return json;
}
/*
* Funcion called when User clicks on
* "Host Game" Button
* Takes JSON strings as Request
* Implements API call to host a game
*
*/
var hostPangea=function(){
var text = $('textarea#json_src').val();
var request=IsJsonString(text);
if(request!==false){
if(!request.agent){
request.agent="pangea";
}
if(!request.method){
request.method="host";
}
if(!request.minplayers){
request.minplayers=2;
console.log("Minimum playes is set to 2");
}
request=JSON.stringify(request);
//var request='{"agent":"pangea","method":"host","minplayers":2,"params":["127.0.0.1"]}';
SPNAPI.makeRequest(request, function(request,response){
}
);
}else{
console.log("Not a valid JSON");
}
};
/*
* Sets the HTML for returned list of games
* And show in GUI
*/
var showGameList=function(){
//console.log($('#game_list_table tbody').html());
$('#game_list_table tbody').html("");
var newTab;
newTab = "<tr class='row history-row'><td >Host</td><td >MinBuyin</td><td >MaxBuyin</td><td >Min player</td><td >Max player</td><td>Join</td></tr>";
$('#game_list_table tbody').append(newTab);
for(var j=0; j<Tables.length;j++){
newTab = "<tr class='row history-row'><td >"+Tables[j].host+"</td><td >"+Tables[j].minbuyin+"</td><td >"+Tables[j].maxbuyin+"</td><td >"+Tables[j].minplayers+"</td><td >"+Tables[j].maxplayers+"</td><td >"+'<button class="btn btn-primary join_pangea_game" data-tablehash="'+Tables[j].tablehash+'">Join</button>'+"</td></tr>";
$('#game_list_table tbody').append(newTab);
}
};
/*
* API call to Get list of games
*/
var lobbyPangea= function(){
var request='{"agent":"pangea","method":"lobby"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.tables){
Tables=response.tables;
showGameList();
}
}
);
};
/*
* API call to Join a game
* Called when user clicks on "Join" button in Pangea tab
*/
var joinPangea= function(hash){
var request='{"agent":"pangea","method":"join","tablehash":"'+hash+'","handle":"mini"}';
SPNAPI.makeRequest(request, function(request,response){
}
);
};
var startGamePangea= function(){
var request='{"agent":"pangea","method":"start","tablehash":"18e9e7448a68a4d46bfde55be0e667c4f4ba015e2c183fbc7cbc0c26996f7656"}';
SPNAPI.makeRequest(request, function(request,response){
});
};

2
iguana/js/sites.js

@ -62,7 +62,7 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
$(this).parent().addClass('active');
var method_obj = SPNAPI.methods[agent].reduce(function (obj, methods) {
if (methods.method == method) {
if (methods.method === method) {
return obj.concat(methods);
} else {
return obj;

Loading…
Cancel
Save