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

Stop inflecting API method parameters on each call #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions betfair/betfair.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def list_event_types(self, filter=None, locale=None):
return self.make_api_request(
'Sports',
'listEventTypes',
utils.get_kwargs(locals()),
{'filter': filter, 'locale': locale},
model=models.EventTypeResult,
)

Expand All @@ -161,7 +161,7 @@ def list_competitions(self, filter=None, locale=None):
return self.make_api_request(
'Sports',
'listCompetitions',
utils.get_kwargs(locals()),
{'filter': filter, 'locale': locale},
model=models.CompetitionResult,
)

Expand All @@ -176,7 +176,7 @@ def list_time_ranges(self, granularity, filter=None):
return self.make_api_request(
'Sports',
'listTimeRanges',
utils.get_kwargs(locals()),
{'granularity': granularity, 'filter': filter},
model=models.TimeRangeResult,
)

Expand All @@ -191,7 +191,7 @@ def list_events(self, filter=None, locale=None):
return self.make_api_request(
'Sports',
'listEvents',
utils.get_kwargs(locals()),
{'filter': filter, 'locale': locale},
model=models.EventResult,
)

Expand All @@ -206,7 +206,7 @@ def list_market_types(self, filter=None, locale=None):
return self.make_api_request(
'Sports',
'listMarketTypes',
utils.get_kwargs(locals()),
{'filter': filter, 'locale': locale},
model=models.MarketTypeResult,
)

Expand All @@ -221,7 +221,7 @@ def list_countries(self, filter=None, locale=None):
return self.make_api_request(
'Sports',
'listCountries',
utils.get_kwargs(locals()),
{'filter': filter, 'locale': locale},
model=models.CountryCodeResult,
)

Expand All @@ -236,7 +236,7 @@ def list_venues(self, filter=None, locale=None):
return self.make_api_request(
'Sports',
'listCountries',
utils.get_kwargs(locals()),
{'filter': filter, 'locale': locale},
model=models.VenueResult,
)

Expand All @@ -256,7 +256,8 @@ def list_market_catalogue(
return self.make_api_request(
'Sports',
'listMarketCatalogue',
utils.get_kwargs(locals()),
{'filter': filter, 'maxResults': max_results,
'marketProjection': market_projection, 'locale': locale},
model=models.MarketCatalogue,
)

Expand All @@ -276,7 +277,9 @@ def list_market_book(
return self.make_api_request(
'Sports',
'listMarketBook',
utils.get_kwargs(locals()),
{'marketIds': market_ids, 'priceProjection': price_projection,
'orderProjection': order_projection, 'matchProjection': match_projection,
'currencyCode': currency_code, 'locale': locale},
model=models.MarketBook,
)

Expand All @@ -296,7 +299,8 @@ def list_market_profit_and_loss(
return self.make_api_request(
'Sports',
'listMarketProfitAndLoss',
utils.get_kwargs(locals()),
{'marketIds': market_ids, 'includeSettledBets': include_settled_bets,
'includeBspBets': include_bsp_bets, 'netOfCommission': net_of_commission},
model=models.MarketProfitAndLoss,
)

Expand Down Expand Up @@ -348,7 +352,9 @@ def list_current_orders(
return self.make_api_request(
'Sports',
'listCurrentOrders',
utils.get_kwargs(locals()),
{'betIds': bet_ids, 'marketIds': market_ids, 'orderProjection': order_projection,
'dateRage': date_range, 'orderBy': order_by, 'sortDir': sort_dir,
'fromRecord': from_record, 'recordCount': record_count},
model=models.CurrentOrderSummaryReport,
)

Expand Down Expand Up @@ -376,7 +382,11 @@ def list_cleared_orders(
return self.make_api_request(
'Sports',
'listClearedOrders',
utils.get_kwargs(locals()),
{'betStatus': bet_status, 'eventTypeIds': event_type_ids, 'eventIds': event_ids,
'marketIds': market_ids, 'runnerIds': runner_ids, 'betIds': bet_ids,
'side': side, 'settledDateRange': settled_date_range, 'groupBy': group_by,
'includeItemDescription': include_item_description, 'locale': locale,
'fromRecord': from_record, 'recordCount': record_count},
model=models.ClearedOrderSummaryReport,
)

Expand All @@ -392,7 +402,7 @@ def place_orders(self, market_id, instructions, customer_ref=None):
return self.make_api_request(
'Sports',
'placeOrders',
utils.get_kwargs(locals()),
{'marketId': market_id, 'instructions': instructions, 'customerRef': customer_ref},
model=models.PlaceExecutionReport,
)

Expand All @@ -408,7 +418,7 @@ def cancel_orders(self, market_id, instructions, customer_ref=None):
return self.make_api_request(
'Sports',
'cancelOrders',
utils.get_kwargs(locals()),
{'marketId': market_id, 'instructions': instructions, 'customerRef': customer_ref},
model=models.CancelInstructionReport,
)

Expand All @@ -424,7 +434,7 @@ def replace_orders(self, market_id, instructions, customer_ref=None):
return self.make_api_request(
'Sports',
'replaceOrders',
utils.get_kwargs(locals()),
{'marketId': market_id, 'instructions': instructions, 'customerRef': customer_ref},
model=models.ReplaceExecutionReport,
)

Expand All @@ -439,7 +449,7 @@ def update_orders(self, market_id, instructions, customer_ref=None):
return self.make_api_request(
'Sports',
'updateOrders',
utils.get_kwargs(locals()),
{'marketId': market_id, 'instructions': instructions, 'customerRef': customer_ref},
model=models.UpdateExecutionReport,
)

Expand All @@ -452,7 +462,7 @@ def get_account_funds(self, wallet=None):
result = self.make_api_request(
'Account',
'getAccountFunds',
utils.get_kwargs(locals()),
{'wallet': wallet},
model=models.AccountFundsResponse,
)

Expand All @@ -472,7 +482,8 @@ def get_account_statement(
result = self.make_api_request(
'Account',
'getAccountStatement',
utils.get_kwargs(locals()),
{'locale': locale, 'fromRecord': from_record, 'recordCount': record_count,
'itemDateRange': item_date_range, 'includeItem': include_item, 'wallet': wallet},
model=models.AccountStatementReport,
)

Expand All @@ -484,7 +495,7 @@ def get_account_details(self):
result = self.make_api_request(
'Account',
'getAccountDetails',
utils.get_kwargs(locals()),
{},
model=models.AccountDetailsResponse,
)

Expand All @@ -497,7 +508,7 @@ def list_currency_rates(self, from_currency=None):
result = self.make_api_request(
'Account',
'listCurrencyRates',
utils.get_kwargs(locals()),
{'fromCurrency': from_currency},
model=models.CurrencyRate,
)

Expand All @@ -512,6 +523,6 @@ def transfer_funds(self, from_, to, amount):
result = self.make_api_request(
'Account',
'transferFunds',
utils.get_kwargs(locals()),
{'from': from_, 'to': to, 'amount': amount},
model=models.TransferResponse,
)
21 changes: 0 additions & 21 deletions betfair/meta/utils.py

This file was deleted.

15 changes: 1 addition & 14 deletions betfair/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import absolute_import

import six
import json
import datetime
import collections
Expand All @@ -12,7 +11,6 @@
from six.moves import http_client as httplib

from betfair import exceptions
from betfair.meta import utils
from betfair.meta.models import BetfairModel


Expand All @@ -28,17 +26,6 @@ def get_chunks(sequence, chunk_size):
]


def get_kwargs(kwargs):
"""Get all keys and values from dictionary where key is not `self`.

:param dict kwargs: Input parameters
"""
return {
key: value for key, value in six.iteritems(kwargs)
if key != 'self'
}


def check_status_code(response, codes=None):
"""Check HTTP status code and raise exception if incorrect.

Expand Down Expand Up @@ -107,7 +94,7 @@ def make_payload(base, method, params):
payload = {
'jsonrpc': '2.0',
'method': '{base}APING/v1.0/{method}'.format(**locals()),
'params': utils.serialize_dict(params),
'params': params,
'id': 1,
}
return payload
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_encode_model_invalid():


def test_make_payload():
result = make_payload('Sports', 'listMarketBook', {'some_param': 123})
result = make_payload('Sports', 'listMarketBook', {'someParam': 123})
assert result == {
'jsonrpc': '2.0',
'method': 'SportsAPING/v1.0/listMarketBook',
Expand Down