manu354 / cryptocurrency-arbitrage

A cryptocurrency arbitrage opportunity calculator. Over 800 currencies and 50 markets.
GNU General Public License v3.0
1.21k stars 337 forks source link

data.result is not iterable #35

Open gaia opened 6 years ago

gaia commented 6 years ago

I added a market

{ marketName: 'market', URL: 'https://market.net/api/ticker/adt_eth', toBTCURL: false, pairURL : '', last: function (data, coin_prices) { //Where to find the last price of coin in JSON data return new Promise(function (res, rej) { try { for (let obj of data.result) { if(obj["MarketName"].includes('BTC-')) { let coinName = obj["MarketName"].replace("BTC-", ''); if (!coin_prices[coinName]) coin_prices[coinName] = {}; coin_prices[coinName].market= obj.Last; } } res(coin_prices); } catch (err) { console.log(err); rej(err); }

        })
    },

},

Which returns for https://market.net/api/ticker/adt_eth

{"adt_eth":{"high":0.00022014,"low":0.00022014,"avg":0.00022014,"vol":0,"vol_cur":0,"last":0.00022014,"buy":0.00002016,"sell":0.00040400,"updated":1514361578},

but when i run the bot i get

TypeError: data.result is not iterable at /root/arb/settings.js:101:42 at new Promise () at Object.last (/root/arb/settings.js:99:20) at Request._callback (/root/arb/main.js:51:49) at Request.self.callback (/root/arb/node_modules/request/request.js:186:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request. (/root/arb/node_modules/request/request.js:1163:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at IncomingMessage. (/root/arb/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1056:12) at _combinedTickCallback (internal/process/next_tick.js:138:11)

the return result is valid JSON. how do i process the API call result to make it digestible?

ReyHaynes commented 6 years ago

@gaia

Your return result is an object when data.result is looking for an array. For this arbitrage system, you should point to the endpoint that supplies an array of data for all of the pairs, not just one single pair.

Also, once you get the right return type, you will need to modify the way the iteration is taking place in the for loop, since most likely, they will have their own property names.

gaia commented 6 years ago

i will build a custom parser and have the system call my parser instead of the API directly. thank you rey.