Opening a Position

When the entry condition is met, we need to open a position using the solver's instant trading API. More details on this can be found here.

Fetching Price from Muon Oracle

For on-chain verification of price and solvency, we need to fetch the price and a signature from the Muon oracle:

def fetch_muon_price():
    try:
        response = requests.get(MUON_URL)
        data = response.json()
        fetched_price_wei = data["result"]["data"]["result"]["price"]
        return Decimal(fetched_price_wei) / Decimal('1e18')
    except Exception as e:
        print(f"[ERROR] Failed to fetch Muon price: {e}")
        return None

Applying Slippage

Since we're going LONG, we increase the price by 1% to ensure our order gets filled:

# For long positions, add 1% slippage
adjusted_price = fetched_price * Decimal('1.01')

Preparing Trade Parameters

We need to calculate collateral parameters based on the notional value and parameters returned from the get_locked_params solver endpoint.

Sending the Trade Request

The API will return a temporary quote ID that we'll use to track our order.

Last updated