/* * 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","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(""+i+""+return_json_table(response[i])+""); continue; } $('#Instandex_output_table').append(""+i+""+response[i]+""); } }; function isJsonArray(what) { return Object.prototype.toString.call(what) === '[object Array]'; } var return_json_table=function(string){ var op=""; //op=op+""); op=op+"
"+i+"";//+response[i]+"
"; //for(var x in string){ for (var i in string[0]){ op=op+""; console.log("field name: "+i); } op=op+""; //} for(var x in string){ op=op+""; for (var i in string[x]){ op=op+""; } op=op+""; } op=op+"
"+i+"
"+string[x][i].toString()+"
"; 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(""+response.result[i][0]+""+response.result[i][1]+""); }} }); }; //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("Bid priceAsk price"); response=JSON.parse(response); for(var i=0;i"+response.bids[i]+""+response.asks[i]+""); } }); }; /* * 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=' Volume:Change percent: Base: Rel: Exchange: '; $('#Instandex_form_table').html(html); }; 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 if(method==="setuserid"){ set_setuserid_table(); } else if(method==="allpairs"){ set_allpair_table(); } else if(method==="tradeint"){ set_tradeint_table(); } else{ console.log("wrong method value"); } $('#Instandex_output_table').html(""); };