Minimal example demonstrating authentication, market lookup and placing a back order in a sandbox/test environment.
Python
Category: Code Library • Tags: python, order-placement, integration • Published: PUBLISH_DATE Contents
Problem / Context
Quick, copyable example to authenticate with an API, find a market and place a simple back order. Use sandbox/test credentials before going live.
Solution — copyable code
Copy
// Minimal example: authenticate, find market, place a back order.
// Replace API_URL and API_KEY with your provider/test credentials.
import requests
API_URL = 'https://api.example.com'
API_KEY = ''
def headers():
return {'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'}
def find_market(name):
r = requests.get(f"{API_URL}/markets?search={name}", headers=headers(), timeout=8)
r.raise_for_status()
data = r.json()
return data[0] if data else None
def place_back(market_id, selection_id, stake, price):
payload = {'marketId': market_id, 'selectionId': selection_id, 'side': 'BACK', 'stake': stake, 'price': price}
r = requests.post(f"{API_URL}/orders", json=payload, headers=headers(), timeout=8)
r.raise_for_status()
return r.json()
if __name__ == '__main__':
m = find_market('Match Odds')
if m:
print('Market:', m.get('name'))
sel = m.get('selections', [{}])[0].get('id')
if sel:
resp = place_back(m['id'], sel, 5.0, 2.5)
print('Order response:', resp)
else:
print('No selection found')
else:
print('No market found')
Usage notes & warnings
- Test only in sandbox accounts and with tiny stakes.
- Add retries, idempotency tokens, logging and alerting for production systems.
- Respect rate limits and validate all responses.
License: MIT — include full license text in site downloads if desired.
