I recently started to work with Betfair's API-NG using Javascript and I am stuck at what is probably a real beginner issue. I am using Algotrader's library, which is great, and I am able to do most of the things that are of my interest. However, I am having trouble with handling the responses of multidimensional objects. I have the following code:
The response I get is:
I am now interested in getting the details of the Objects in "runners". I can do this by running the response through a for - in loop with a changed var invocation:
The response is:
So this brings me to the next dimension of objects that I am interested in. Ultimately I would like to obtain the properties "size" and "price" which are two levels down of the object, which is the property of "ex:".
I tried to just loop through level by level, but the code got very ugly (and probably not very efficient) and I wondered whether there isn't an easier way to obtain a response which shows me every property of every object, no matter on which dimension that object is.
It would be really great, if somebody could point me in the right direction. I spent all afternoon trying to google for a solution without success and I am quite desperate now.
Thank you very much
B.
Code:
function listMarketBook(callback){
console.log("Get MarketBook response");
var filter = {"marketIds":["1.116312560"],"priceProjection":{"priceData":["EX_BEST_OFFERS"]},"marketProjection": "RUNNER_DESCRIPTION"}
var invocation = session.listMarketBook(filter, function(err,res) {
if(err) {
console.log('Getting MarketBook response failed');
console.log(err);
console.log(invocation);
} else {
console.log(invocation.request);
console.log(invocation.response.result);
}
})
};
Code:
MarketBook response
{ jsonrpc: '2.0',
id: 1,
method: 'SportsAPING/v1.0/listMarketBook',
params:
{ marketIds: [ '1.116312560' ],
priceProjection: { priceData: [Object] },
marketProjection: 'RUNNER_DESCRIPTION' } }
[ { marketId: '1.116312560',
isMarketDataDelayed: false,
status: 'OPEN',
betDelay: 0,
bspReconciled: false,
complete: true,
inplay: false,
numberOfWinners: 1,
numberOfRunners: 3,
numberOfActiveRunners: 3,
lastMatchTime: '2014-11-18T18:18:54.772Z',
totalMatched: 160215.6,
totalAvailable: 762737.37,
crossMatching: true,
runnersVoidable: false,
version: 862639130,
[B][COLOR="Red"]runners: [ [Object], [Object], [Object] ][/COLOR][/B] } ]
Code:
var invocation = session.listMarketBook(filter, function(err,res) {
if(err) {
console.log('Getting MarketBook response failed');
console.log(err);
console.log(invocation);
} else {
console.log(invocation.request);
for(var index in invocation.response.result) {
var item = invocation.response.result[index];
console.log(item);
}
}
})
Code:
{ jsonrpc: '2.0',
id: 1,
method: 'SportsAPING/v1.0/listMarketBook',
params:
{ marketIds: [ '1.116312560' ],
priceProjection: { priceData: [Object] },
marketProjection: 'RUNNER_DESCRIPTION' } }
{ marketId: '1.116312560',
isMarketDataDelayed: false,
status: 'OPEN',
betDelay: 0,
bspReconciled: false,
complete: true,
inplay: false,
numberOfWinners: 1,
numberOfRunners: 3,
numberOfActiveRunners: 3,
lastMatchTime: '2014-11-18T18:25:04.229Z',
totalMatched: 160220.54,
totalAvailable: 762734.93,
crossMatching: true,
runnersVoidable: false,
version: 862639130,
runners:
[ { selectionId: 55190,
handicap: 0,
status: 'ACTIVE',
lastPriceTraded: 1.23,
totalMatched: 158317.68,
ex: [B][COLOR="Red"][Object][/COLOR][/B] },
{ selectionId: 1703,
handicap: 0,
status: 'ACTIVE',
lastPriceTraded: 18,
totalMatched: 509.47,
ex: [COLOR="red"][B][Object][/B][/COLOR] },
{ selectionId: 58805,
handicap: 0,
status: 'ACTIVE',
lastPriceTraded: 7.4,
totalMatched: 1393.38,
ex: [COLOR="red"][Object][/COLOR] } ] }
I tried to just loop through level by level, but the code got very ugly (and probably not very efficient) and I wondered whether there isn't an easier way to obtain a response which shows me every property of every object, no matter on which dimension that object is.
It would be really great, if somebody could point me in the right direction. I spent all afternoon trying to google for a solution without success and I am quite desperate now.
Thank you very much
B.


Comment