class Command(BaseCommand): def __init__(self, *args, **kwargs): super(Command, self).__init__(*args, **kwargs) # Setup connection to Betfair API-NG self.client = Betfair(settings.BETFAIR_APP, settings.BETFAIR_CERT) self.client.login(settings.BETFAIR_USER, settings.BETFAIR_PASS) def handle(self, *args, **kwargs): # XXX: Hardcodign msk = timezone('Europe/Moscow') utc = timezone('UTC') # Loop over configured targets for competition in settings.TARGETS: cid = self.get_competition_id(competition) # Get event list for each target team for target in settings.TARGETS[competition]: events = self.client.list_events( MarketFilter(text_query=target, competition_ids=cid) ) # Event processing for e in events: event_id = int(e.event.id) raw_time = make_aware(e.event.open_date, utc) start_time = localtime(raw_time, msk) # Save persistent data try: event = Event.objects.create(id=event_id, title=e.event.name, start_time=start_time) event.save() self.stdout.write('Event #%d \'%s\' saved' % (event.id, event.title)) except IntegrityError: pass def get_competition_id(self, name): competitions = self.client.list_competitions( MarketFilter(text_query=name) ) for obj in competitions: return obj.competition.id
client = Betfair('fxmlhjiDhNghfmLP', 'C:/Users/Cong/Desktop/betfair/keys/shang.pem') client.login('*****@*****.**', 'wabjtam@123') print 'login successful' sys.exit from betfair.models import MarketFilter event_types = client.list_event_types(MarketFilter(text_query='basketball')) #print (len(event_types)) #print (event_types[0].event_type.name) football_event_type = event_types[0] competitions = client.list_competitions() for comp in competitions: a = comp['competition'] if a.name == u'NBA Matches': id_NBA = a.id events = client.list_events(MarketFilter(competition_ids=[id_NBA])) f = open('C:/Users/Cong/Desktop/betfair/log_basketball.txt', 'w') for eventResult in events: e = eventResult.event c = eventResult.market_count # print "id:" + e.id + ", name=" + e.name + ", market_count:" + str(c) markets = client.list_market_catalogue(MarketFilter(event_ids=[e.id])) for m in markets: f.write(m.market_id + ' ' + m.market_name + ' ' + ' ' + str(e['id']) + ' ' + str(e['name']) + '\n')