/*
* 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 exchange_array=[];
var returnExchangeOptions=function(){
var output="";
console.log("Exchange Options changed");
for(var i in exchange_array){
output=output+'';
}
//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","account":"0","type":"bid","base":"BTCD","rel":"BTCD","timestamp":1454949273,"price":0.00250000,"volume":11,"nonce":2684223522,"pendingvolume":0,"expiresin":3496})
$('#Instandex_output_table').append("
");
}
};
function isJsonArray(what) {
return Object.prototype.toString.call(what) === '[object Array]';
}
var return_json_table=function(string){
var op="";
//op=op+"
"+i+"
";//+response[i]+"
");
op=op+"
";
//for(var x in string){
for (var i in string[0]){
op=op+"
"+i+"
";
console.log("field name: "+i);
}
op=op+"
";
//}
for(var x in string){
op=op+"
";
for (var i in string[x]){
op=op+"
"+string[x][i].toString()+"
";
}
op=op+"
";
}
op=op+"
";
return op;
};
var setUeseridandAPIkeyPair=function(){
setAPIkeyPair();
};
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){
show_resposnse(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){
show_resposnse(response);
});
};
var ListAllExchanges=function(){
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 ){
exchange_array=response.result;
returnExchangeOptions();
}
}
);}
};
var InstantDEX_allpairs=function(){
var exchange=$('#Instandex_exchange').val();
var request='{"agent":"InstantDEX","method":"allpairs","exchange":"'+exchange+'"}';
SPNAPI.makeRequest(request, function(request,response){
response=JSON.parse(response);
//show_resposnse(response);
if(response.result){
for(var i in response.result){
$('#Instandex_output_table').append("
");
}
});
};
/*
*
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 volume=$('#Instandex_volume').val();
var request='{"agent":"InstantDEX","method":"buy","exchange":"'+exchange+'","base":"'+base+'","rel":"'+rel+'","price":'+price+',"volume":'+volume+',"dotrade":1}';
SPNAPI.makeRequest(request, function(request,response){
show_resposnse(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 volume=$('#Instandex_volume').val();
var request='{"agent":"InstantDEX","method":"sell","exchange":"'+exchange+'","base":"'+base+'","rel":"'+rel+'","price":'+price+',"volume":'+volume+',"dotrade":1}';
SPNAPI.makeRequest(request, function(request,response){
show_resposnse(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){
show_resposnse(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){
show_resposnse(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){
show_resposnse(response);
});
};
/*
*
* 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){
show_resposnse(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){
show_resposnse(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){
show_resposnse(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){
show_resposnse(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){
show_resposnse(response);
});
};
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='
UserID:
Password:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_apikeypass_table=function (){
var html='
Apikey:
Passphrase:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_orderbook_table=function (){
var html='
Base:
Rel:
Depth:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_sell_table=function (){
var html='
Base:
Rel:
Price:
Volume:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_buy_table=function (){
var html='
Base:
Rel:
Price:
Volume:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_balance_table=function (){
var html='
Base:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_support_table=function (){
var html='
Base:
Rel:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_withdraw_table=function (){
var html='
Base:
Destination address:
Amount:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_order_status_table=function (){
var html='
Order ID:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_open_order_table=function (){
var html='
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_trade_history_table=function (){
var html='
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_order_cancel_table=function (){
var html='
Order ID:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_pollgap_table=function (){
var html='
Pollgap:
Exchange:
';
$('#Instandex_form_table').html(html);
if(exchanges!==""){
$('#Instandex_exchange').html(exchanges);
if(SPNAPI.settings.prefferedExchange!==""){
changePrefferedEx("Instandex_exchange");}
}
};
var set_allpair_table=function (){
var html='
Exchange:
';
$('#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='