Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data.result is not iterable #35

Open
gaia opened this issue Dec 27, 2017 · 2 comments
Open

data.result is not iterable #35

gaia opened this issue Dec 27, 2017 · 2 comments

Comments

@gaia
Copy link

gaia commented Dec 27, 2017

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
Copy link

@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
Copy link
Author

gaia commented Dec 29, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants