Browse Source

added preffered exchange setting and instantdex integration test without GUI output

release/v0.1
vineetbhargav86 9 years ago
parent
commit
abbfe92f85
  1. 4
      iguana/app/startup.js
  2. 8
      iguana/index.html
  3. 8
      iguana/js/api.js
  4. 6
      iguana/js/blockexplorer.js
  5. 185
      iguana/js/instantdex.js
  6. 27
      iguana/js/settings.js
  7. 42
      iguana/js/tradebot.js
  8. 381
      iguana/js/tradeintegration.js

4
iguana/app/startup.js

@ -160,6 +160,10 @@ $(function () {
deletePeertabFile_onclick();
}
else if(e.className && e.className.indexOf('TradeIntegrationTest') != -1){
TradeIntegrationTest();
}
};

8
iguana/index.html

@ -467,7 +467,7 @@ data-path="{tc}/{config}">
<!-- Default panel contents -->
<div class="panel-heading">
<h3>Instandex tab</h3>
</div>
</div><div class="pre-scrollable">
<div class="panel-body center">
<button class="btn xyz_button_click btn-primary instantdex_set_method_table" data-method="orderbook" >orderbook</button>
<button class="btn xyz_button_click btn-primary instantdex_set_method_table" data-method="apikeypair" >API Keypair</button>
@ -487,9 +487,10 @@ data-path="{tc}/{config}">
<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>
<button class="btn btn-primary instantdex_set_method_table" data-method="tradeint" >Trade integration</button>
</div>
<div class="panel-body center">
<table id="Instandex_form_table" class="table table-hover table-bordered">
</table>
@ -498,7 +499,7 @@ data-path="{tc}/{config}">
<table id="Instandex_output_table" class="table table-hover table-bordered" >
</table>
</div>
</div></div>
</div>
<style type="text/css">
#Blockexplorer_page .center {
@ -546,6 +547,7 @@ data-path="{tc}/{config}">
<script type="text/javascript " src="js/tradebot.js" ></script>
<script type="text/javascript " src="js/storage.js" ></script>
<script type="text/javascript " src="js/jquery.tablesort.js" ></script>
<script type="text/javascript " src="js/tradeintegration.js" ></script>
</body>
</html>

8
iguana/js/api.js

@ -42,11 +42,11 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
}else if(page==="Coins"){
addInitCoins();
}else if(page==="Instandex"){
if(!saved_exchanges){
ListAllExchanges();}
$('#Instandex_form_table').html("");
$('#Instandex_output_table').html("");
}else if(page==="Tradebot"){
if(!saved_exchanges){
ListAllExchanges();}
$('#trade_output').html("");
$('#tradebot_input').html('');
}
else if(page==="Blockexplorer"){
filesystem_show_file_name();

6
iguana/js/blockexplorer.js

@ -3,7 +3,6 @@
* Variables to store values:
*
*/
var BlockHash="";
var Block="";
var checkExternalBlock=0;
@ -63,7 +62,7 @@ var filterInt = function (value) {
if(/^(\-|\+)?([0-9]+|Infinity)$/.test(value))
return Number(value);
return "NaN";
}
};
var getBlockhash= function(height){
@ -187,9 +186,10 @@ $.ajax({
{
console.log("file doesnt exists");
},
success: function()
success: function(response, textStatus, jqXHR)
{
console.log("Hurray we are good to go!");
console.log("response is:");
//file exists
}
});

185
iguana/js/instantdex.js

@ -5,17 +5,79 @@
*/
var exchanges="";
var saved_exchanges=false;
var exchange_array=[];
var returnExchangeOptions=function(){
var output="";
console.log("Exchange Options changed");
for(var i in exchange_array){
output=output+'<option value="'+exchange_array[i]+'">'+exchange_array[i]+'</option>';
}
//SPNAPI.settings.exchanges=output;
exchanges=output;
};
var changePrefferedEx=function(id){
$('#'+id+" option").each(function(){
var temp = $(this); // cache this jQuery object to avoid overhead
if (temp.val() === SPNAPI.settings.prefferedExchange) { // if this option's value is equal to our value
temp.prop('selected', true); // select this option
return false; // break the loop, no need to look further
}
});
};
var show_resposnse=function(response){
$('#Instandex_output_table').html("");
response=JSON.parse(response);
for(var i in response){
if(i==='tag') continue;
if(isJsonArray(response[i]) ){
//return_json_table({"orderid":"16800917935208460084","offerer":"0","type":"bid","base":"BTCD","rel":"BTCD","timestamp":1454949273,"price":0.00250000,"volume":11,"nonce":2684223522,"pendingvolume":0,"expiresin":3496})
$('#Instandex_output_table').append("<tr><td>"+i+"</td><td>"+return_json_table(response[i])+"</td></tr>");
continue;
}
$('#Instandex_output_table').append("<tr><td align='center'>"+i+"</td><td align='center'>"+response[i]+"</td></tr>");
}
};
function isJsonArray(what) {
return Object.prototype.toString.call(what) === '[object Array]';
}
var return_json_table=function(string){
var op="";
//op=op+"<table><tr><td align='center'>"+i+"</td><td align='center'>";//+response[i]+"</td></tr>");
op=op+"<table class='table table-hover table-bordered'><tr>";
//for(var x in string){
for (var i in string[0]){
op=op+"<th>"+i+"</th>";
console.log("field name: "+i);
}
op=op+"</tr>";
//}
for(var x in string){
op=op+"<tr>";
for (var i in string[x]){
op=op+"<td>"+string[x][i].toString()+"</td>";
}
op=op+"</tr>";
}
op=op+"</table>";
return op;
};
var setUeseridandAPIkeyPair=function(){
setAPIkeyPair();
@ -57,22 +119,15 @@ var InstantDEX_setuserid=function(){
var ListAllExchanges=function(){
if(!saved_exchanges){
if(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>';
exchange_array=response.result;
returnExchangeOptions();
}
saved_exchanges=true;
}
}
);}
@ -274,46 +329,82 @@ var InstantDEX_pollgap=function(){
});
};
var TradeIntegrationTest=function(){
IntegrationSettings.volume=$('#Instandex_volume').val();
IntegrationSettings.percentChange=$('#Instandex_changePer').val();
IntegrationSettings.exchange=$('#Instandex_exchange').val();
IntegrationSettings.base=$('#Instandex_base').val();
IntegrationSettings.rel=$('#Instandex_rel').val();
IntegrationSettings.phase=0;
IntegrationSettings.ranFirstTyme=true;
start_integrationTest();
};
var set_setuserid_table=function (){
var html='<tr><td align="center" > UserID:</td><td align="center" ><input type="text" id="Instandex_userid"/></td></tr><tr><td align="center" > Password:</td><td align="center" ><input type="text" id="Instandex_tradepassword"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_set_userid" >Set Userid</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_apikeypass_table=function (){
var html='<tr><td align="center" > Apikey:</td><td align="center" ><input size="40" type="text" id="Instandex_apikey"/></td></tr><tr><td align="center" > Passphrase:</td><td align="center" ><input size="40" type="text" id="Instandex_apipassphrase"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_set_keypair" >Set keypair</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_orderbook_table=function (){
var html='<tr><td align="center" > Base:</td><td align="center" ><input type="text" id="Instandex_base"/></td></tr><tr><td align="center" >Rel:</td><td align="center" ><input type="text" id="Instandex_rel"/></td></tr><tr><td align="center" >Depth:</td><td align="center" ><input type="text" id="Instandex_orderbook_depth"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_orderbook" >orderbook</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_sell_table=function (){
var html='<tr><td align="center" > Base:</td><td align="center" ><input type="text" id="Instandex_base"/></td></tr><tr><td align="center" >Rel:</td><td align="center" ><input type="text" id="Instandex_rel"/></td></tr><tr><td align="center" >Price:</td><td align="center" ><input type="text" id="Instandex_price"/></td></tr><tr><td align="center" >Volume:</td><td align="center" ><input type="text" id="Instandex_volume"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_sell" >Sell</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_buy_table=function (){
var html='<tr><td align="center" > Base:</td><td align="center" ><input type="text" id="Instandex_base"/></td></tr><tr><td align="center" >Rel:</td><td align="center" ><input type="text" id="Instandex_rel"/></td></tr><tr><td align="center" >Price:</td><td align="center" ><input type="text" id="Instandex_price"/></td></tr><tr><td align="center" >Volume:</td><td align="center" ><input type="text" id="Instandex_volume"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_buy" >Buy</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_balance_table=function (){
var html='<tr><td align="center" > Base:</td><td align="center" ><input type="text" id="Instandex_base"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center" > <button class="btn btn-primary instantdex_balance" >Check balance</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
@ -321,7 +412,11 @@ var set_support_table=function (){
var html='<tr><td align="center" > Base:</td><td align="center" ><input type="text" id="Instandex_base"/></td></tr><tr><td align="center" >Rel:</td><td align="center" ><input type="text" id="Instandex_rel"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_support" >Check Support</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
@ -329,14 +424,23 @@ var set_withdraw_table=function (){
var html='<tr><td align="center" > Base:</td><td align="center" ><input type="text" id="Instandex_base"/></td></tr><tr><td align="center" >Destination address:</td><td align="center" ><input type="text" id="Instandex_destaddr"/></td></tr><tr><td align="center" >Amount:</td><td align="center" ><input type="text" id="Instandex_amount"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_withdraw" >Withdraw</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_order_status_table=function (){
var html='<tr><td align="center" > Order ID:</td><td align="center" ><input type="text" id="Instandex_orderid"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_order_status" >Check order status</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
@ -344,7 +448,11 @@ var set_open_order_table=function (){
var html='<tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_open_orders" >Open orders</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
@ -352,29 +460,54 @@ var set_trade_history_table=function (){
var html='<tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_trade_history" >See Trade History</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_order_cancel_table=function (){
var html='<tr><td align="center" > Order ID:</td><td align="center" ><input type="text" id="Instandex_orderid"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_order_cancel" >Cancel order</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_pollgap_table=function (){
var html='<tr><td align="center" > Pollgap:</td><td align="center" ><input type="text" id="Instandex_pollgap"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_pollgap" >Pollgap</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);}
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_allpair_table=function (){
var html='<tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary instantdex_allpairs" >Get allpairs</button></td></tr>';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
//console.log(exchanges);
$('#Instandex_exchange').html(exchanges);
}
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_tradeint_table=function (){
var html='<tr><td align="center" > Volume:</td><td align="center" ><input type="text" id="Instandex_volume"/></td></tr><tr><td align="center" >Change percent:</td><td align="center" ><input type="text" id="Instandex_changePer"/></td></tr><tr><td align="center" > Base:</td><td align="center" ><select name="Instandex_base" id="Instandex_base"><option value="NXT">NXT</option></select></td></tr><tr><td align="center" > Rel:</td><td align="center" ><select name="Instandex_rel" id="Instandex_rel"><option value="BTC">BTC</option></select></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Instandex_exchange" id="Instandex_exchange"><option value="poloniex">poloniex</option></select></td></tr><tr><tr><td colspan="2" align="center"> <button class="btn btn-primary TradeIntegrationTest" >Start Bot</button></td></tr>';
$('#Instandex_form_table').html(html);
};
var instantdex_set_method_table=function (method){
@ -418,6 +551,10 @@ var instantdex_set_method_table=function (method){
set_allpair_table();
}
else if(method==="tradeint"){
set_tradeint_table();
}
else{
console.log("wrong method value");
}

27
iguana/js/settings.js

@ -1,6 +1,6 @@
var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
SPNAPI.settings = {maxpeers:3};
SPNAPI.settings = {maxpeers:3,prefferedExchange:"",exchange_array:[],"exchanges":""};
SPNAPI.conf_files={};
SPNAPI.getCheckBoxDetails = function(agent) {
@ -197,11 +197,29 @@ var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
'<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Delete peer tab data</div></div>'+
'</div>'+
'</div>';
config += '' +
'<div class="panel panel-default">'+
'<div class="panel-body">'+
'<div class="col-xs-6 col-md-6 col-lg-6">Preffered exchange</div>'+
'<div class="col-xs-6 col-md-6 col-lg-6" style="text-align: right;">' +
'<div class="checkbox">'+
'<label>'+
'<span><select name="setting_exchange" id="setting_exchange"></select></span>'+
'</label>'+
'</div>' +
'</div>' +
'<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Set preffered exchange setting</div></div>'+
'</div>'+
'</div>';
$("#advanced_settings").html(config);
$('#setting_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("setting_exchange");}
var pexe_checkbox = $('.pexe_checkbox');
@ -232,6 +250,13 @@ var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
sync_peers_to_maxpeers();
}
/// saving preffered exchange setting
var ex=$('#setting_exchange').val();
if(SPNAPI.settings.prefferedExchange!==ex){
SPNAPI.settings.prefferedExchange=ex;
console.log("changed preffered Exchange");
}
/*var agent_checkbox = $('.agent_checkbox');
var settings = [];

42
iguana/js/tradebot.js

@ -19,6 +19,10 @@ var set_Tradebot_monitor_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -41,6 +45,10 @@ var set_Tradebot_monitorall_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -66,6 +74,10 @@ var set_Tradebot_unmonitor_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -91,6 +103,10 @@ var set_Tradebot_accumulate_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -118,6 +134,10 @@ var set_Tradebot_divest_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
@ -139,6 +159,10 @@ var set_Tradebot_activebots_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -158,7 +182,12 @@ var set_Tradebot_status_table=function(){
var html='<tr><td align="center" >Botid:</td><td align="center" ><input type="text" id="Tradebot_botid"/></td></tr><tr><td align="center" > Exchange:</td><td align="center" ><select name="Tradebot_exchange" id="Tradebot_exchange"></select></td></tr><tr><td colspan="2" align="center"> <button class="btn btn-primary Tradebot_status" >Check status of Tradebot</button></td></tr>';
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);}
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
@ -183,6 +212,10 @@ var set_Tradebot_pause_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -206,6 +239,10 @@ var set_Tradebot_stop_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};
@ -229,6 +266,9 @@ var set_Tradebot_resume_table=function(){
$('#tradebot_input').html(html);
if(exchanges!==""){
$('#Tradebot_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Tradebot_exchange");}
}
};

381
iguana/js/tradeintegration.js

@ -0,0 +1,381 @@
/*
var base="NXT";
var rel="BTC";
var depth=20;
var exchange="poloniex";
var currentValues={"low":0,"high":0};
var valuesHistory=[];
var BalanceBaseHistory=[];
var BalanceRelHistory=[];
var timer=0;
var interval=5000; //5 sec
var decision_timelimit=1000*60; //1 min
var percentChange=5;
var volume=10;
var ordersHistory=[];
var loopcounter=-1;
var ranFirstTyme=true;
var ordernumber="";
var phase=0; // 0 means buy 1 means sell
var transactionCount=0;
*/
var IntegrationSettings={
"phase":0,
"currentValues":{"low":0,"high":0},
"exchange":"poloniex",
"base":"NXT",
"rel":"BTC",
"depth":20,
"volume":10,
"ordersHistory":[],
"valuesHistory":[],
"BalanceRelHistory":[],
"BalanceBaseHistory":[],
"timer":0,
"decision_timelimit":1000*60,
"interval":5000,
"percentChange":5,
"loopcounter":-1,
"ranFirstTyme":true,
"ordernumber":""
};
var start_integrationTest=function(){
mainlogic();
};
var mainlogic=function(){
IntegrationSettings.loopcounter=IntegrationSettings.loopcounter+1;
get_current_min_max(); // step 1
};
var get_current_min_max=function(){
var request='{"agent":"InstantDEX","method":"orderbook","exchange":"'+IntegrationSettings.exchange+'","base":"'+IntegrationSettings.base+'","rel":"'+IntegrationSettings.rel+'","depth":'+IntegrationSettings.depth+',"allfields":0,"invert":0}';
SPNAPI.makeRequest(request, function(request,response){
/*
*
* {"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"}
*/
response=JSON.parse(response);
if(response.lowask){
IntegrationSettings.valuesHistory[IntegrationSettings.loopcounter]=IntegrationSettings.currentValues;
IntegrationSettings.currentValues.low=response.lowask;
IntegrationSettings.currentValues.high=response.highbid;
console.log("current low: "+response.lowask+" current high:"+response.highbid);
if(IntegrationSettings.ranFirstTyme){buyOrder();IntegrationSettings.ranFirstTyme=false;} // step 2
else{
if(IntegrationSettings.phase===0){
checkifBuySuccessful(); // step 3
}else{
checkifSellSuccessful(); //step 4
}
}
}else{
get_current_min_max();
}
});
};
//http://127.0.0.1:7778/api/InstantDEX/buy?exchange={string}&base={string}&rel={string}&price={float}&volume={float}&dotrade={float}
var buyOrder=function(){
console.log("trying to buy at current lowprice");
IntegrationSettings.phase=0;
var request='{"agent":"InstantDEX","method":"buy","exchange":"'+IntegrationSettings.exchange+'","base":"'+IntegrationSettings.base+'","rel":"'+IntegrationSettings.rel+'","price":'+IntegrationSettings.currentValues.low+',"volume":'+IntegrationSettings.volume+',"dotrade":1}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.orderNumber){
//transactionCount=transactionCount+1;
IntegrationSettings.ordernumber=response.orderNumber;
//response.count=transactionCount;
response.today=new Date().today();
response.now=new Date().timeNow();
response.type="buy";
IntegrationSettings.ordersHistory.push(response);
// check if the order is open/not
if(response.resultingTrades.length!==0){
// check if it is completed
attemptSell();
}else{
setTimeout(function () { mainlogic(); }, IntegrationSettings.decision_timelimit);
// execute after decision_timelimit
}
}
});
};
//http://127.0.0.1:7778/api/InstantDEX/sell?exchange={string}&base={string}&rel={string}&price={float}&volume={float}&dotrade={float}
var sellOrder=function(){
var request='{"agent":"InstantDEX","method":"sell","exchange":"'+IntegrationSettings.exchange+'","base":"'+IntegrationSettings.base+'","rel":"'+IntegrationSettings.rel+'","price":'+IntegrationSettings.price+',"volume":'+IntegrationSettings.volume+',"dotrade":1}';
SPNAPI.makeRequest(request, function(request,response){
show_resposnse(response);
});
};
var checkOrderstatus=function(){
var request='{"agent":"InstantDEX","method":"orderstatus","exchange":"'+IntegrationSettings.exchange+'","orderid":"'+IntegrationSettings.orderid+'"}';
SPNAPI.makeRequest(request, function(request,response){
});
};
var getTradeHistory=function(){
var request='{"agent":"InstantDEX","method":"tradehistory","exchange":"'+IntegrationSettings.exchange+'"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
var othercurr="";
if(IntegrationSettings.rel!=="BTC"){othercurr=IntegrationSettings.rel;}
else{othercurr=IntegrationSettings.base;}
if(response["BTC_"+othercurr]){
// transaction is completed
console.log("transaction is complete");
}
});
};
var checkifBuySuccessful=function (){
console.log("checking if previus buy was successful");
var request='{"agent":"InstantDEX","method":"openorders","exchange":"'+IntegrationSettings.exchange+'"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
var othercurr="";
var unsuccessful=false;
if(IntegrationSettings.rel!=="BTC"){othercurr=IntegrationSettings.rel;}
else{othercurr=IntegrationSettings.base;}
if(response["BTC_"+othercurr].length>0){
for(var jsn in response["BTC_"+othercurr]){
if(jsn.orderNumber===IntegrationSettings.ordernumber && jsn.type==="buy"){
unsuccessful=true;
break;
}
}
if(unsuccessful){
cancelandReBuy();
}else{
attemptSell();
}
}else{
attemptSell();
}
});
};
var checkifSellSuccessful=function (){
console.log("checking if previous sell was successful");
var request='{"agent":"InstantDEX","method":"openorders","exchange":"'+IntegrationSettings.exchange+'"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
var othercurr="";
var unsuccessful=false;
if(IntegrationSettings.rel!=="BTC"){othercurr=IntegrationSettings.rel;}
else{othercurr=IntegrationSettings.base;}
if(response["BTC_"+othercurr].length>0){
for(var jsn in response["BTC_"+othercurr]){
if(jsn.orderNumber===IntegrationSettings.ordernumber && jsn.type==="sell"){
unsuccessful=true;
break;
}
}
if(unsuccessful){
cancelandReSell();
}else{
console.log("Finally we are done!");
// and we are done!!
}
}else{
console.log("Finally we are done!");
// and we are done!!
}
});
};
var cancelandReBuy=function(){
cancelBuy();
};
var cancelandReSell=function(){
cancelSell();
};
var reSell=function(){
IntegrationSettings.phase=1; // change phase to control the flow
var newlow=0;
if(IntegrationSettings.valuesHistory[IntegrationSettings.loopcounter].high===IntegrationSettings.currentValues.high){
newlow=IntegrationSettings.currentValues.high-(IntegrationSettings.currentValues.high*IntegrationSettings.percentChange)/100;
console.log("selling at reduced high "+newlow);
}else{
newlow=IntegrationSettings.currentValues.high;
console.log("selling at current high "+newlow);
}
var request='{"agent":"InstantDEX","method":"buy","exchange":"'+IntegrationSettings.exchange+'","base":"'+IntegrationSettings.base+'","rel":"'+IntegrationSettings.rel+'","price":'+newlow+',"volume":'+IntegrationSettings.volume+',"dotrade":1}';
IntegrationSettings.totalBoughtRel=newlow;
IntegrationSettings.totalBoughtBase=IntegrationSettings.volume;
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.orderNumber){
IntegrationSettings.ordernumber=response.orderNumber;
response.today=new Date().today();
response.now=new Date().timeNow();
response.type="sell";
IntegrationSettings.ordersHistory.push(response);
// check if the order is open/not
if(response.resultingTrades.length!==0){
// check if it is completed
attemptSell();
}else{
setTimeout(function () { mainlogic(); }, IntegrationSettings.decision_timelimit);
// execute after decision_timelimit
}
}
});
};
var rebuy=function(){
IntegrationSettings.phase=0; // change phase to control the flow
var newlow=0;
if(IntegrationSettings.valuesHistory[IntegrationSettings.loopcounter].low===IntegrationSettings.currentValues.low){
newlow=IntegrationSettings.currentValues.low+(IntegrationSettings.currentValues.low*IntegrationSettings.percentChange)/100;
newlow=IntegrationSettings.currentValues.low;
console.log("buying at current low "+newlow);
}else{
newlow=IntegrationSettings.currentValues.low;
console.log("buying at current low "+newlow);
}
var request='{"agent":"InstantDEX","method":"buy","exchange":"'+IntegrationSettings.exchange+'","base":"'+IntegrationSettings.base+'","rel":"'+IntegrationSettings.rel+'","price":'+newlow+',"volume":'+IntegrationSettings.volume+',"dotrade":1}';
totalBoughtRel=newlow;
totalBoughtBase=volume;
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.orderNumber){
//transactionCount=transactionCount+1;
ordernumber=response.orderNumber;
//response.count=transactionCount;
response.today=new Date().today();
response.now=new Date().timeNow();
response.type="buy";
IntegrationSettings.ordersHistory.push(response);
// check if the order is open/not
if(response.resultingTrades.length!==0){
// check if it is completed
attemptSell();
}else{
setTimeout(function () { mainlogic(); }, IntegrationSettings.decision_timelimit);
// execute after decision_timelimit
}
}
});
};
var cancelBuy=function(){
var request='{"agent":"InstantDEX","method":"cancelorder","exchange":"'+IntegrationSettings.exchange+'","orderid":"'+IntegrationSettings.ordernumber+'"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.success===1){
rebuy();
}else{
attemptSell();
}
});
};
var cancelSell=function(){
var request='{"agent":"InstantDEX","method":"cancelorder","exchange":"'+IntegrationSettings.exchange+'","orderid":"'+IntegrationSettings.ordernumber+'"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.success===1){
reSell();
}else{
console.log("Finally we are done!");
// and we are done!!
}
});
};
var attemptSell=function(){
IntegrationSettings.phase=1;
var request='{"agent":"InstantDEX","method":"sell","exchange":"'+IntegrationSettings.exchange+'","base":"'+IntegrationSettings.base+'","rel":"'+IntegrationSettings.rel+'","price":'+IntegrationSettings.currentValues.high+',"volume":'+IntegrationSettings.volume+',"dotrade":1}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
if(response.orderNumber){
IntegrationSettings.transactionCount=IntegrationSettings.transactionCount+1;
ordernumber=response.orderNumber;
response.count=IntegrationSettings.transactionCount;
response.today=new Date().today();
response.now=new Date().timeNow();
response.type="sell";
IntegrationSettings.ordersHistory.push(response);
// check if the order is open/not
if(response.resultingTrades.length!==0){
// check if it is completed
console.log("Finally we are done!");
}else{
setTimeout(function () { mainlogic(); }, IntegrationSettings.decision_timelimit);
// execute after decision_timelimit
}
}
});
};
Date.prototype.today = function () {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
};
// For the time now
Date.prototype.timeNow = function () {
return ((this.getHours() < 10)?"0":"") + this.getHours() +":"+ ((this.getMinutes() < 10)?"0":"") + this.getMinutes() +":"+ ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
};
Loading…
Cancel
Save