import os, uuid, requests
API = "https://bravado-api-k7kaq.ondigitalocean.app"
KEY = os.environ["BRAVADO_API_KEY"]
H = {"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"}
def new_key():
return {"Idempotency-Key": str(uuid.uuid4())}
symbol = "71321045679252212594626385532706912750332728571942532289631379312455583992646"
target_size = "20000"
# 1. Enter with TWAP + ICEBERG.
entry = requests.post(f"{API}/v2/trade/order", headers={**H, **new_key()}, json={
"symbol": symbol,
"side": "buy",
"type": "TWAP",
"size": target_size,
"limit_price": "0.65",
"twap": {"duration_sec": 1800, "interval_sec": 60, "randomize": True},
"iceberg": {"display_size": "150"},
}).json()
parent_id = entry["order_id"]
print(f"Entry: {parent_id}")
# 2. Attach a trailing stop for the exit.
exit_stop = requests.post(f"{API}/v2/trade/order", headers={**H, **new_key()}, json={
"symbol": symbol,
"side": "sell",
"type": "TRAILING_STOP",
"size": target_size,
"trailing": {"delta": "0.03"},
"trigger_after_order_id": parent_id,
}).json()
print(f"Trailing stop: {exit_stop['order_id']}")