Created
September 17, 2018 23:14
-
-
Save Cally99/e51894e7b3bbb365473b6eefcd231f76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, unicode_literals | |
from django.core.management.base import BaseCommand, CommandError | |
from backend.models import MBEvent, MBMarkets, MBRun, MBPrice | |
import requests | |
from matchbook.endpoints.betting import Betting | |
from matchbook.enums import Side, Status, AggregationType | |
from django.conf import settings | |
from django.utils import timezone | |
from backend.client import get_mb_client | |
from matchbook.endpoints.marketdata import MarketData | |
from matchbook.apiclient import APIClient | |
from matchbook.apiclient import APIClient | |
from matchbook.endpoints.marketdata import MarketData | |
from matchbook.enums import Side, MarketStates, MarketNames, Boolean | |
from backend.models import MBData | |
import django | |
django.setup() | |
import json | |
class MBCommand(BaseCommand): | |
is_debug = True | |
sport = {'Tennis': 9} | |
api = APIClient('USERNAME' , 'PASS') | |
def mb_get_events(self): | |
tennis_events = self.api.market_data.get_events(sport_ids=[9],states=MarketStates.All, | |
per_page=10000, offset=0, | |
include_event_participants=Boolean.T, | |
category_ids=None, price_depth=3, side=Side.All) | |
print(tennis_events) | |
for data in tennis_events: | |
id = data['id'] | |
event_name = data['name'] | |
sport_id = data['sport-id'] | |
stat_time = data['start'] | |
is_ip = data['in-running-flag'] | |
te , created = MBEvent.objects.update_or_create(id=id) | |
te.id = id | |
te.event_name = event_name | |
te.sport_id = sport_id | |
te.start_time = stat_time | |
te.is_ip = is_ip | |
te.save() | |
for mar in data['event-participants']: | |
runner_1 = mar[0]['participant-name'] | |
runner_2 = mar[1]['participant-name'] | |
print(runner_1, runner_2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment