Skip to content

Commit

Permalink
v3.03.1 (Bug Fix)
Browse files Browse the repository at this point in the history
-Bug fix for kucoin markets support

-Full LoopRing markets support
  • Loading branch information
taoteh1221 committed May 30, 2021
1 parent 6b96eeb commit ac524b9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 29 deletions.
3 changes: 0 additions & 3 deletions DOCUMENTATION-ETC/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ API INTEGRATION SECTION
///////////////////////////////////////////////////////


https://docs3.loopring.io/en/websocket/ticker.html


https://www.bitmex.com/app/wsAPI


Expand Down
4 changes: 3 additions & 1 deletion DOCUMENTATION-ETC/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ v3.03.0
---------------------------------------------------------
v3.03.1

-Bug fix for kucoin support
-Bug fix for kucoin markets support

-Full LoopRing markets support

---------------------------------------------------------

Expand Down
2 changes: 0 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Discord: https://discord.gg/WZVK2nm

Telegram: https://t.me/joinchat/Oo2XZRS2HsOXSMGejgSO0A

Keybase: https://keybase.io/team/dragonfrugaltech

Twitter: https://twitter.com/taoteh1221

Private Contact: https://dragonfrugal.com/contact
Expand Down
12 changes: 7 additions & 5 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var exchange_markets = []; // LEAVE ALONE, AND DON'T DELETE (REQUIRED!)
// Binance formatting example: 'btcusdt|ethusdt|ethbtc|mkrusdt'
// Kucoin formatting example: 'MANA-BTC|ENJ-BTC|SXP-USDT'
// Hitbtc formatting example (MULTIPLE TICKERS NOT SUPPORTED): 'MYSTBTC'
// Okex formatting example: 'ENJ-USDT|ENJ-BTC|XCH-USDT'
// Loopring formatting example: 'LRC-USDT|LRC-ETH'
////
////
// Bitstamp markets (set to '' to disable)
Expand All @@ -34,7 +36,11 @@ exchange_markets['coinbase'] = 'BTC-USD|ETH-USD|ETH-BTC|UNI-USD|UNI-BTC';
////
////
// Binance markets (set to '' to disable)
exchange_markets['binance'] = 'mkrusdt|mkrbtc|lrcusdt|lrcbtc';
exchange_markets['binance'] = 'mkrusdt|mkrbtc|lrcbtc';
////
////
// Loopring markets (set to '' to disable)
exchange_markets['loopring'] = 'LRC-USDT|LRC-ETH';
////
////
// Kraken markets (set to '' to disable)
Expand All @@ -51,10 +57,6 @@ exchange_markets['okex'] = 'ENJ-USDT|ENJ-BTC|XCH-USDT|XCH-BTC';
////
// HitBTC markets (set to '' to disable)
exchange_markets['hitbtc'] = 'MYSTBTC'; // !!HITBTC WEBSOCKET API ONLY SUPPORTS ONE ASSET!!
////
////
// Loopring markets (set to '' to disable)
//exchange_markets['loopring'] = 'LRC-ETH'; // NOT FULLY SUPPORTED YET!!


// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down
103 changes: 87 additions & 16 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ return input[0].toUpperCase() + input.slice(1);
/////////////////////////////////////////////////////////////////////////////////////////////////////


function is_json(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////


function load_js(file) {

script= document.createElement('script');
Expand Down Expand Up @@ -160,10 +173,17 @@ render = render.replace(/stamp/gi, "Stamp");
render = render.replace(/flyer/gi, "Flyer");
render = render.replace(/panda/gi, "Panda");
render = render.replace(/pay/gi, "Pay");
render = render.replace(/swap/gi, "Swap");
render = render.replace(/iearn/gi, "iEarn");
render = render.replace(/pulse/gi, "Pulse");
render = render.replace(/defi/gi, "DeFi");
render = render.replace(/ring/gi, "Ring");
render = render.replace(/amm/gi, "AMM");
render = render.replace(/ico/gi, "ICO");
render = render.replace(/erc20/gi, "ERC-20");
render = render.replace(/okex/gi, "OKex");

return render;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -197,19 +217,26 @@ return results;


function kucoin_config() {

if ( window.kucoin_alert == 1 ) {
return;
}
else {
window.kucoin_alert = 1;
}

// If kucoin auth data is cached, allow kucoin configs
if ( typeof kucoin_endpoint !== 'undefined' && typeof kucoin_token !== 'undefined' ) {
api['kucoin'] = kucoin_endpoint + '?token=' + kucoin_token;
console.log('Kucoin support enabled (valid installation detected).');
console.log('Kucoin support enabled (VALID installation detected).');
return true;
}
// Remove kucoin market configs if no cache data is present, to avoid script errors,
// and alert (to console ONLY) that app was improperly installed
else {
delete exchange_markets['kucoin'];
console_alert();
console.log('Kucoin support disabled (invalid installation detected).');
console.log('Kucoin support disabled (INVALID installation detected).');
return false;
}

Expand All @@ -221,6 +248,13 @@ function kucoin_config() {

function loopring_config() {

if ( window.loopring_alert == 1 ) {
return;
}
else {
window.loopring_alert = 1;
}

if ( typeof api['loopring'] == 'undefined' ) {

api['loopring'] = 'wait';
Expand All @@ -235,7 +269,7 @@ function loopring_config() {
// If loopring auth data is cached, allow loopring configs
if ( typeof loopring_token !== 'undefined' ) {
api['loopring'] = 'wss://ws.api3.loopring.io/v3/ws' + '?wsApiKey=' + loopring_token;
console.log('Loopring support enabled (valid installation detected).');
console.log('Loopring support enabled (VALID installation detected).');
return true;
}
// Remove loopring market configs if no cache data is present, to avoid script errors,
Expand All @@ -246,7 +280,7 @@ function loopring_config() {
api['loopring'] = ' ';
delete exchange_markets['loopring'];
console_alert();
console.log('Loopring support disabled (invalid installation detected).');
console.log('Loopring support disabled (INVALID installation detected).');
return false;
}

Expand Down Expand Up @@ -910,17 +944,22 @@ api['okex'] = 'wss://ws.okex.com:8443/ws/v5/public';
// Loopring
else if ( exchange == 'loopring' ) {

// API call config
// API call config
// ('unsubscribeAll' cancels any previous subscriptions)
subscribe_msg[exchange] = {
"topic": "ticker",
"market": "LRC-ETH"
};
"op": "sub",
"unsubscribeAll": true,
"topics": []
};


// Add markets to API call
var loop = 0;
markets[exchange].forEach(element => {
//subscribe_msg[exchange].params['symbol'] = element;
subscribe_msg[exchange].topics[loop] = {
"topic": "ticker",
"market": element
};
loop = loop + 1;
});

Expand Down Expand Up @@ -965,9 +1004,27 @@ function api_connect(exchange) {
// Socket response ///////////////////////////////////////////////////
sockets[exchange].onmessage = function(e) {

msg = JSON.parse(e.data);
//console.log(msg);

// Check if response is JSON, or just a regular string
if ( is_json(e.data) == true ) {
msg = JSON.parse(e.data);
}
else {
msg = e.data;
}


//console.log(e.data); // DEBUGGING
//console.log(msg); // DEBUGGING


// Loopring requires a response of 'pong', when message is 'ping'
if ( exchange == 'loopring' && msg == 'ping' ) {
sockets[exchange].send('pong');
//console.log('pong'); // DEBUGGING
}


// Parse exchange data

// Coinbase
Expand Down Expand Up @@ -1064,7 +1121,7 @@ function api_connect(exchange) {

price_raw = msg["data"]["price"];

// RE-SET volume_raw / base_volume AS UNDEFINED, as bitstamp provides no volume data
// RE-SET volume_raw / base_volume AS UNDEFINED, as bitstamp provides no 24hr volume data

var volume_raw;

Expand All @@ -1090,7 +1147,21 @@ function api_connect(exchange) {

price_raw = msg['data'][0]['idxPx'];

// RE-SET volume_raw / base_volume AS UNDEFINED, as okex provides no volume data
// RE-SET volume_raw / base_volume AS UNDEFINED, as okex provides no 24hr volume data

var volume_raw;

var base_volume;

}
// Loopring
else if ( exchange == 'loopring' && msg['data'] ) {

market_id = msg['data'][0];

price_raw = msg['data'][7];

// RE-SET volume_raw / base_volume AS UNDEFINED, as loopring provides no 24hr volume data

var volume_raw;

Expand All @@ -1103,7 +1174,7 @@ function api_connect(exchange) {
if (
exchange == 'bitfinex' && msg[1] == 'hb' // Bitfinex
) {
var market_id;
var market_id; // Set as UNDEFINED
}


Expand Down Expand Up @@ -1210,7 +1281,7 @@ function api_connect(exchange) {

if ( exchange == 'loopring' ) {

api[exchange] = void 0;
api[exchange] = void 0; // RE-SET API PARAMS AS UNDEFINED

loopring_config(); // GET A NEW TEMP KEY FROM LOOPRING'S REST API

Expand Down
8 changes: 6 additions & 2 deletions js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var app_version = '3.03.1'; // 2021/MAY/15TH



// Var inits
// BLANK var inits
var api = [];
var sockets = [];
var markets = [];
Expand All @@ -17,7 +17,11 @@ var subscribe_msg = [];
var trade_side_price = [];
var trade_side_arrow = [];
var markets_length = 0;
var api_alert; // MUST at least be set as 'undefined' here
// BELOW MUST at least be set as 'undefined' here
var api_alert;
var kucoin_alert;
var loopring_alert;
// END BLANK var inits

// Save what time the app started running (works fine with refresh)
var runtime_start = new Date().getTime();
Expand Down

0 comments on commit ac524b9

Please sign in to comment.