Skip to content

Instantly share code, notes, and snippets.

@timxyz
Created April 20, 2022 10:27
Show Gist options
  • Save timxyz/32e61440a0c7def699c804a73aed87d0 to your computer and use it in GitHub Desktop.
Save timxyz/32e61440a0c7def699c804a73aed87d0 to your computer and use it in GitHub Desktop.
Sync bets API
def sync_bets_for_event(
betfair_client,
betfair_markets,
proposed_bets
):
'''
Make a best effort to synchronize proposed bets with Betfair.
Arguments:
betfair_client - betfairlightweight instance with which to interface with Betfair
betfair_markets - Dictionary of SS market IDs to Betfair market info
betfair_markets[ss_market_id].marketId - Betfair Market ID
betfair_markets[ss_market_id].runners - Dictionary of SS runner IDs to Betfair runner IDs
proposed_bets - Array of proposed bets to be synced with Betfair.
proposed_bets[n].id - SS internal ID
proposed_bets[n].market - SS market ID
proposed_bets[n].runner - SS runner ID
proposed_bets[n].odds - The minimum odds to match
proposed_bets[n].stake - The maximum stake to match
'''
# TODO: This will split out all the event markets and call sync_bets_for_market
updated_bets = []
for ss_market_id in betfair_markets.keys():
proposed_bets_for_market = [bet for bet in proposed_bets if bet['market'] == ss_market_id]
report = sync_bets_for_market(
betfair_client=betfair_client,
betfair_market=betfair_markets[ss_market_id],
proposed_bets=proposed_bets_for_market,
)
updated_bets_for_market = update_bet_models(report, proposed_bets_for_market)
updated_bets.extend(updated_bets_for_market)
return updated_bets
def sync_bets_for_market(
betfair_client,
betfair_market,
proposed_bets
):
'''
Make a best effort to synchronize proposed bets with Betfair.
Arguments:
betfair_client - betfairlightweight instance with which to interface with Betfair
betfair_market - Information about the Betfair market.
betfair_market.marketId - Betfair Market ID
betfair_market.runners - Dictionary of SS runner IDs to Betfair runner IDs
proposed_bets - Array of proposed bets to be synced with Betfair.
proposed_bets[n].id - SS internal ID
proposed_bets[n].market - SS market ID (always the same)
proposed_bets[n].runner - SS runner ID
proposed_bets[n].odds - The minimum odds to match
proposed_bets[n].stake - The maximum stake to match
Returns PlaceExecutionReport
'''
# TODO
def update_bet_models(
report,
bets
):
'''
Update SS bet models to reflect outcome of Betfair place request.
Arguments:
report - Betfair PlaceExecutionReport
bets - Array of SS bet models
Returns updated SS bet models
'''
# TODO: Define what this needs to do. e.g. update status. store betId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment