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

Update betfair.py #76

Open
wants to merge 6 commits 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
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ language: python
sudo: false

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "pypy"
- "3.8"

install:
- travis_retry python setup.py install
Expand Down
20 changes: 9 additions & 11 deletions betfair/betfair.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import os
import json
import itertools
import collections
import itertools
import json
import os

import requests
from six.moves import http_client as httplib
from six.moves import urllib_parse as urllib

from betfair import utils
from betfair import models
from betfair import exceptions

from betfair import models
from betfair import utils

IDENTITY_URLS = collections.defaultdict(
lambda: 'https://identitysso.betfair.com/api/',
italy='https://identitysso.betfair.it/api/',
lambda: 'https://identitysso-cert.betfair.com/api/',
italy='https://identitysso-cert.betfair.it/api/',
)

API_URLS = collections.defaultdict(
Expand All @@ -38,6 +35,7 @@ class Betfair(object):
:param Session session: Optional Requests session
:param int timeout: Optional timeout duration (seconds)
"""

def __init__(self, app_key, cert_file, content_type='application/json', locale=None,
session=None, timeout=None):
self.app_key = app_key
Expand Down Expand Up @@ -467,7 +465,7 @@ def get_account_statement(
:param int record_count: Specifies the maximum number of records to be returned
:param TimeRange item_date_range: Return items with an itemDate within this date range
:param IncludeItem include_item: Which items to include
:param Wallet wallte: Which wallet to return statementItems for
:param Wallet wallet: Which wallet to return statementItems for
"""
return self.make_api_request(
'Account',
Expand Down
1 change: 0 additions & 1 deletion betfair/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from enum import Enum


MarketProjection = Enum(
'MarketProjection', [
'COMPETITION',
Expand Down
1 change: 1 addition & 0 deletions betfair/meta/datatype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-


class DataType(object):

def __init__(self, type, preprocessor=None):
Expand Down
14 changes: 9 additions & 5 deletions betfair/meta/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-

import six
import inflection
from schematics import types
import six
from schematics import models
from schematics import types


class BetfairModelMeta(models.ModelMeta):
"""Set default `serialized_name` and `deserialize_from` of Schematics types
to camel-cased attribute names.
"""

def __new__(meta, name, bases, attrs):
for name, attr in six.iteritems(attrs):
if isinstance(attr, types.BaseType):
Expand All @@ -19,11 +20,14 @@ def __new__(meta, name, bases, attrs):
return super(BetfairModelMeta, meta).__new__(meta, name, bases, attrs)


class BetfairModel(six.with_metaclass(BetfairModelMeta, models.Model)):
class BetfairModel(models.Model, metaclass=BetfairModelMeta):

def __init__(self, **data):
def __init__(self, *args, **data):
super(BetfairModel, self).__init__()
self.import_data(data)
if args:
self.import_data(args[0])
else:
self.import_data(data)

def import_data(self, data, **kwargs):
kwargs['strict'] = False
Expand Down
2 changes: 0 additions & 2 deletions betfair/meta/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class DateTimeType(types.DateTimeType):

DEFAULT_FORMATS = (
'%Y-%m-%dT%H:%M:%S.%f',
'%Y-%m-%dT%H:%M:%S.%fZ',
Expand All @@ -15,7 +14,6 @@ class DateTimeType(types.DateTimeType):


class EnumType(types.BaseType):

MESSAGES = {'choices': u'Value must belong to enum {0}.'}

def __init__(self, enum, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion betfair/meta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import functools

import six
import inflection
import six


def convert_value(value, converter=None):
Expand Down
17 changes: 5 additions & 12 deletions betfair/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import

from schematics.types import BooleanType
from schematics.types import FloatType
from schematics.types import IntType
from schematics.types import LongType
from schematics.types import FloatType
from schematics.types import StringType
from schematics.types import BooleanType
from schematics.types.compound import DictType
from schematics.types.compound import ListType
from schematics.types.compound import ModelType

from betfair.meta.types import EnumType
from betfair.meta.types import DateTimeType
from betfair.meta.models import BetfairModel

from betfair import constants
from betfair.meta.models import BetfairModel
from betfair.meta.types import DateTimeType
from betfair.meta.types import EnumType


class Event(BetfairModel):
Expand Down Expand Up @@ -224,7 +221,6 @@ class MarketOnCloseOrder(BetfairModel):
# Results

class CompetitionResult(BetfairModel):

competition = ModelType(Competition)
market_count = IntType()
competition_region = StringType()
Expand All @@ -236,13 +232,11 @@ class CountryCodeResult(BetfairModel):


class EventResult(BetfairModel):

event = ModelType(Event)
market_count = IntType()


class EventTypeResult(BetfairModel):

event_type = ModelType(EventType)
market_count = IntType()

Expand All @@ -253,7 +247,6 @@ class MarketTypeResult(BetfairModel):


class TimeRangeResult(BetfairModel):

time_range = ModelType(TimeRange)
market_count = IntType()

Expand Down
5 changes: 1 addition & 4 deletions betfair/price.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import division

from decimal import Decimal, ROUND_HALF_UP


CUTOFFS = (
(2, 100),
(3, 50),
Expand All @@ -18,7 +15,6 @@
(1000, 0.1),
)


MIN_PRICE = 1.01
MAX_PRICE = 1000

Expand Down Expand Up @@ -63,6 +59,7 @@ def nearest_price(price, cutoffs=CUTOFFS):
return MAX_PRICE

price = as_dec(price)
step = None
for cutoff, step in cutoffs:
if price < cutoff:
break
Expand Down
10 changes: 4 additions & 6 deletions betfair/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import six
import json
import datetime
import collections

import datetime
import enum
import json

import decorator
import six
from six.moves import http_client as httplib

from betfair import exceptions
Expand Down