Examples

Python

Setup

import requests
import json

SERVER_URL = 'http://localhost:8000' # Or whereever your server is hosted
API_PREFIX = '/api/'
ORDERS_RESOURCE_PATH = 'orders/'
SINGLE_ORDER_PATH = 'order/'
ACCOUNT_BALANCES_PATH = 'balances/'

ORDERS_URL = SERVER_URL + API_PREFIX + ORDERS_RESOURCE_PATH
API_TOKEN = '<YOUR_API_TOKEN>'

required_headers = {
  'Authorization': f'Token {API_TOKEN}',
}

Submit Order

submit_order_post_body = {
  'accounts': ['<ACCOUNT_ONE>', '<ACCOUNT_TWO>'], # Use the account "name" you picked
  'pair': 'BTC-USD',
  'side': 'buy',
  'sell_token_amount': 500,
  'duration': 120,
  'strategy': 'TWAP',
  'engine_passiveness': 0.1,
}

response = requests.post(ORDERS_URL, headers=required_headers, json=submit_order_post_body)

if response.status_code >= 400:
  # Handle error response
  print(response.json())
else:
  body = response.json()
  print(body)

Get Order

order_id = body['id']

response = requests.get(SERVER_URL + API_PREFIX + SINGLE_ORDER_PATH + order_id, headers=required_headers)
print(response.json())

Cancel Order

response = requests.delete(SERVER_URL + API_PREFIX + SINGLE_ORDER_PATH + order_id, headers=required_headers)
print(response.json())

Account Management

response = requests.get(SERVER_URL + API_PREFIX + ACCOUNT_BALANCES_PATH, headers=required_headers)
print(response.json())

Was this helpful?