Closing a Position
Preparing the Close Request
# Fetch Muon price and apply -1% slippage (for long positions)
muon_price = fetch_muon_price()
close_price = str(muon_price * Decimal("0.99")) # 1% slippage for sellingSending the Close Request
payload = {
"quote_id": quote_id,
"quantity_to_close": CONFIG["QUANTITY"],
"close_price": close_price
}
response = requests.post(f"{HEDGER_URL}/instant_close", json=payload, headers=headers)Verifying the Close
if response.status_code == 200:
print("[CLOSE] Position closed successfully")
return True
else:
print(f"[CLOSE] Error: {response.status_code}, {response.text}")
return FalseLast updated
