Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.99 KB | None | 0 0
  1. import requests as req
  2. import logging
  3. from datetime import datetime
  4. from time import sleep
  5.  
  6. # Input your thunderpick token here after you login (available in HTTP headers)
  7. THUNDERPICK_TOKEN = ''
  8.  
  9. def calculate_tp_odds(bet_amount, total_amount):
  10.     n = bet_amount/total_amount
  11.     return max(1.01, round(0.93/n, 2))
  12.  
  13. def get_live_matches():
  14.     res = req.get('https://thunderpick.com/api/matches?gameIds=1&gameIds=2&gameIds=3&gameIds=4&gameIds=6&gameIds=7&gameIds=8&gameIds=9&gameIds=19&gameIds=20&gameIds=21&gameIds=22&gameIds=23', headers = {'thunderpick-token': THUNDERPICK_TOKEN}).json()
  15.     return [r for r in res['data'] if (
  16.             (r['hasInPlayMarkets'] == True) and (
  17.             ((r['isLive'] == False) and (r['matchBet']['timeToLock'] <= 300000) and (r['matchBet']['timeToLock'] > 0))
  18.             or ((r['isLive'] == True) and (r['matchBet']['timeToLock'] > 0))
  19.             ))]
  20.  
  21. def get_match_detail(match_id):
  22.     return req.get('https://thunderpick.com/api/matches/%i' % match_id).json()['data']
  23.  
  24. def get_match_inplays(match_id):
  25.     return req.get('https://thunderpick.com/api/in-plays?matchId=%i' % match_id).json()['data']
  26.  
  27. def str_to_datetime(string):
  28.     return datetime.strptime(string[:24], '%Y-%m-%dT%H:%M:%S.%f')
  29.  
  30. def calculate_min_odds_from_favorite(o):
  31.     return 1./(1-1./o)
  32.  
  33. def place_outplay_bet(marketId, choice, stake):
  34.     payload = {'amount': int(stake),
  35.                 'betId': int(marketId),
  36.                 'value': choice }
  37.     res = req.post('https://thunderpick.com/api/bet/mutual',
  38.         json = payload, headers = {'thunderpick-token': THUNDERPICK_TOKEN, 'content-type': 'application/json;charset=UTF-8'})
  39.     return res.json()
  40.  
  41. def place_inplay_bet(marketId, choice, stake, odds):
  42.     payload = {'amount': int(stake),
  43.                 'marketId': int(marketId),
  44.                 'selectionId': choice,
  45.                 'selectionOdds': odds}
  46.     res = req.post('https://thunderpick.com/api/in-plays',
  47.         json = payload, headers = {'thunderpick-token': THUNDERPICK_TOKEN, 'content-type': 'application/json;charset=UTF-8'})
  48.     return res.json()
  49.  
  50. def find_outplay_info_from_name(bet, name):
  51.     for s in bet['buckets']:
  52.         if s['label'] == name:
  53.             return {'name': s['label'], 'marketId': bet['id'], 'value': s['value']}
  54.        
  55. def find_inplay_info_from_name(bet, name):
  56.     for s in bet['selections']:
  57.         if s['name'] == name:
  58.             return {'name': s['name'], 'marketId': bet['id'], 'selectionId': s['id'], 'selectionOdds': s['odds']}
  59.  
  60. def test_token():
  61.     res = req.get('https://thunderpick.com/api/user', headers = {'thunderpick-token': THUNDERPICK_TOKEN})
  62.     if res.json()['ok'] == True:
  63.         return True
  64.     else:
  65.         raise Exception('BAD TOKEN')
  66.  
  67. if __name__ == '__main__':
  68.     logger = logging.getLogger('thunderpick_arb')
  69.     logger.setLevel(logging.DEBUG)
  70.     fh = logging.FileHandler('eggs.log')
  71.     fh.setLevel(logging.INFO)
  72.     ch = logging.StreamHandler()
  73.     ch.setLevel(logging.INFO)
  74.     logger.addHandler(fh)
  75.     logger.addHandler(ch)
  76.    
  77.     while True:
  78.         logger.info(test_token())
  79.         logger.info('Fetching...')
  80.         live_matches = get_live_matches()
  81.         for match in live_matches:
  82.             if len(match['matchBet']['buckets']) != 2:
  83.                 continue
  84.            
  85.             if match['matchBet']['private']['userAmount'] > 0:
  86.                 continue
  87.            
  88.             total_pool_amt = sum([bucket['amount'] for bucket in match['matchBet']['buckets']])
  89.             outplay_slip = {team['label']:  calculate_tp_odds(team['amount'], total_pool_amt) for team in match['matchBet']['buckets']}
  90.             logger.info('Found Out-play odds - %s' % outplay_slip)
  91.             match_inplays = get_match_inplays(match['id'])
  92.             match_winner_bet = [m for m in match_inplays['inPlays'] if (m['name'] == 'Match Up Winner')]
  93.             if (match_winner_bet and match_winner_bet[0]['status'] == 1):
  94.                 inplay_slip = {team['name']: team['odds'] for team in match_winner_bet[0]['selections']}
  95.                 logger.info('Found In-play odds - %s - %s' % (match_winner_bet[0]['name'], inplay_slip))
  96.                 best_odds = [max(outplay_slip[team], inplay_slip[team]) for team in outplay_slip.keys()]
  97.                 if min(best_odds) > (calculate_min_odds_from_favorite(max(best_odds)) + 0.1):
  98.                     logger.info('ARB Opportunity Found! %.2f vs %.2f' % (min(best_odds), calculate_min_odds_from_favorite(max(best_odds))))
  99.                    
  100.                     # place bets
  101.                     ratio = max(best_odds) / min(best_odds)
  102.                     if ratio < 6:
  103.                         for t,o in outplay_slip.items():
  104.                             slip = find_outplay_info_from_name(match['matchBet'], t)
  105.                             if o == min(best_odds):
  106.                                 amt = 100*ratio # lowest sizing for testing
  107.                                 break
  108.                             elif o == max(best_odds):
  109.                                 amt = 100/ratio
  110.                                 break
  111.                         logger.info((slip, amt))
  112.                         res = place_outplay_bet(slip['marketId'], slip['value'], round(amt))
  113.                         logger.info(res)
  114.                         for t,o in inplay_slip.items():
  115.                             slip = find_inplay_info_from_name(match_winner_bet[0], t)
  116.                             amt = 100
  117.                             if o == min(best_odds):
  118.                                 break
  119.                             elif o == max(best_odds):
  120.                                 break
  121.                         logger.info((slip, amt))
  122.                         res = place_inplay_bet(slip['marketId'], slip['selectionId'], round(amt), slip['selectionOdds'])
  123.                         logger.info(res)
  124.                     else:
  125.                         logger.info('Ratio way too high - skipping')
  126.                        
  127.         logger.handlers[0].flush()
  128.         sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement