jmcarp / betfair.py

A Python wrapper for the Betfair API
MIT License
103 stars 76 forks source link

Prices and http headers changes #23

Closed petedmarsh closed 9 years ago

petedmarsh commented 9 years ago

I just saw that you merged a couple of my open PRs, thanks! I have done some further work which I hadn't yet raised a PR for, here it is!

Changes:

  1. Add some headers to API HTTP requests (recommended in API documentation
  2. Add some utility methods for working with prices (nearest_price, ticks_difference and price_ticks_away

The individual commit message themselves have more detailed information in. One thing I should add: the nearest_price method is based on an implementation from: https://github.com/AlgoTrader/betfair-sports-api/blob/master/lib/betfair_price.js that code is under the MIT license, and so a copyright notice might need to be added ("The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software." - I'm not sure if this counts as a copy or "substantial portion").

jmcarp commented 9 years ago

This looks good, but I proposed a few additional changes in https://github.com/petedmarsh/betfair.py/pull/1. Feedback welcome. Thanks for your help!

petedmarsh commented 9 years ago

I've amended the commits to remove the HTTP header stuff and include the whitespace/spelling changes from https://github.com/petedmarsh/betfair.py/pull/1. To be honest I don't think it's worth having code that generates the prices: they don't changefamouslastwords and they'll just be computed over and over every time someone loads the module for the first time, so I've left those changes out :)

petedmarsh commented 9 years ago

I forgot to add - I'm in two minds as to whether the prices should be Decimals, on the one hand the accuracy is desirable but if they're used here they should really be used everywhere, i.e. the models should convert numbers from API response to Decimal, otherwise you can get type errors, e.g.:

Decimal('100') + 0.1
>>> TypeError: unsupported operand type(s) for +: 'Decimal' and 'float'
jmcarp commented 9 years ago

I went ahead and merged my revisions to the price module. I'm more concerned about code reuse and developer efficiency than the cycles we might save by not computing prices on import. Plus, it takes about 100 μs to build PRICES, and it's cached on import, so I'm not worried about performance :racehorse:.

Thanks again for the feature!