AlgoTrader / betfair-sports-api

Library is discontinued
MIT License
55 stars 15 forks source link

Invocation object is not actually exported in index.js #6

Closed alexice closed 11 years ago

alexice commented 11 years ago

there should be something like

exports.newInvocation = betfairInvocation.invocation;

because './lib/betfair_invocation' exports only invocation name, not newInvocation

And actually it would be better to include customizable invocation constructor into session object, so someone (me for example -) could call not implemented in betfair-sports-api.js calls but implemented in bf API itself (like getAccountStatement for example)

AlgoTrader commented 11 years ago

Invocation object is not exported deliberately. One should never create BetfairInvocation object directly, creating BetfairInvocation objects is highly not-recommended. BetfairInvocation relies on session object to appropriately prepare the request (including session key stuff) and check input parameters.

It never takes more than 20 minutes to implement a call, so you may add anything you want and send pull request. Alternatively, I can implement any request you need in days.

If you still want have access to BetfairInvocation, you may write

var invocation = require('./node_modules/betfair-sports-api/lib/betfair_invocation.js');

I have another idea. I can add something like session.customInvocation(api, name, request, cb) so you can write something like this:

var inv = session.customInvocation('global', 'getSomethingUnsupported', { marketId:'123'}, myCallback);

session will add appropriate header with proper sessionKey

alexice commented 11 years ago

Yes, this last idea is perfect -- sessioned invocation, that's what could be very handy for those who can make parameter check for API functions. Actually, I think that login/logout, session handling, price ladder and customInvocation - are only necessary for thous who are familiar with Betfair API.

And about invocation export I just mentioned that 19th line in index.js: exports.newInvocation = betfairInvocation.newInvocation; exports undefined

AlgoTrader commented 11 years ago

The session.someCall is far above the syntax sugar. It handles params check, it handles sessionKey. It handles "decompression" of stuff like getAllMarkets. I certainly prefer

var inv = session.getMarketProfitAndLoss(market.marketId, false);
inv.execute(...);

than

var inv = session.customInvocation('exchange', 'getMarketProfitAndLoss', {maket: market.marketId, includeBspBets: true});
inv.execute(...);

Anyway, BF prepares a new JSON API and it will be perfect for JavaScript/Node.js. No language likes Json like JavaScript

AlgoTrader commented 11 years ago

No time todo it, anyone to implement and send pull?