LogoLogo
  • Overview
    • Introduction
    • Table of Contents
  • Token Information
    • Symmio Foundation
  • Protocol Architecture
    • Protocol Introduction
    • Technical Documentation
      • Building an Application with SYMM
        • Introduction and Diamond Explainer
        • Querying Info from the SYMM Diamond
        • MultiAccount
        • Creating an Account and Depositing Funds
        • Sending a Quote
        • Closing a Quote
        • Instant Trading
          • Instant Login (EOA)
          • Instant Login (Account Abstraction)
          • Sending a Quote (Instant Open)
          • Sending a Quote (Instant Close)
        • Frequently Used Queries
      • Solver Docs
        • Solver Docs (github)
        • Solver Implementation Guide (High Level Overview)
        • Building a Solver on SYMMIO
          • 1. Intent Creation
          • 2. Seeing the Intent
          • 3. Hedging Off-Chain
          • 4. Opening/Closing a Position On-Chain
          • Creating the APIs
            • GET Contract Symbols
            • GET Open Interest
            • GET Notional Cap
            • GET Price Range
            • GET Error Codes
            • GET Get Locked Params
            • GET Get Funding Info
            • POST Position State
          • Solver Flow Summary Example
          • Recommended Architecture for Solvers
          • Glossary
        • Conditional Orders Handler
        • Rasa Solver TP/SL Implementation
        • Instant Trading
          • Instant Trading (Solvers)
          • Rasa Instant Trading Implementation
          • Instant Trading Condition Checks
        • Fetching Gas Prices Script
        • How to Add a Market as a Solver
        • Verifying Account Abstracted Instant Actions (ERC-4337)
      • Frontend Docs
        • Setting up a Frontend with SYMMIO
        • Frontend SDK Setup Guide
        • MultiAccount Deployment Guide
        • Instant Trading (Frontends)
          • Account Abstracted Instant Actions (Frontends)
        • Implement a Trading Bot on Symmio (OLD)
          • Setup
          • Creating a Sub-Account
          • Minting Collateral Tokens (Optional)
          • Depositing and Allocating Tokens
          • Obtaining Muon Signatures
          • Sending a Quote
          • Monitoring Price for Execution
      • Contract Docs
        • SYMMIO CORE v0.82
        • Contracts Documentation 0.8.2
          • Main Flow
          • The SYMM Diamond
          • Facets
            • Account Facet
            • Control Facet
            • Funding Rate Facet
            • PartyA Facet
            • PartyB Facet
            • Liquidation Facet
            • View Facet
          • MultiAccount
            • PartyA
            • PartyB
          • SYMM App (Muon)
            • LibMuon
            • MuonStorage
        • Contracts Documentation 0.8.3
          • Facets
            • Control Facet
            • Account Facet
            • PartyA Facet
            • PartyB Facet
            • View Facet
            • Bridge Facet
            • Liquidation Facet (Implementation)
          • Modified Events
          • New Events
          • MuonStorage
        • Contracts Documentation 0.8.4
          • Main Flow (0.8.4)
          • The SYMM Diamond (0.8.4)
          • Facets
            • Account Facet (0.8.4)
            • Bridge Facet (0.8.4)
            • Control Facet (0.8.4)
            • Force Actions Facet (0.8.4)
            • Funding Rate Facet (0.8.4)
            • Liquidations Facet (0.8.4)
            • PartyA Facet (0.8.4)
            • PartyB Group Actions Facet (0.8.4)
            • PartyB Quote Actions Facet (0.8.4)
            • PartyB Position Actions Facet (0.8.4)
            • Settlement Facet (0.8.4)
            • View Facet (0.8.4)
          • MultiAccount (0.8.4)
            • SymmioPartyA
            • SymmioPartyB
          • SYMM App (Muon)
            • LibMuon (0.8.4)
            • MuonStorage (0.8.4)
      • Contract Addresses / Solver Endpoints
        • Mantle
        • Mode
        • IOTA
        • Base
        • BSC
        • Arbitrum
        • Polygon
        • Berachain
        • Solver Endpoints and Addresses
          • Perps Hub
          • Rasa Capital
          • Rasa Capital (Zero Spread)
          • Zenith
      • How to Query our Contracts
      • Muon API Queries
      • Solver Error Codes
      • Interacting with SYMMIO Contracts
    • Protocol higher level architecture
      • 12-Hour Fraud Proof Window
      • PartyB
      • Solver Settings
      • Max Leverage
      • Maintenance Margin (CVA) Calculations
    • Symmio Whitepaper
  • Building on Symmio
    • Builders introduction
    • Solving for Symmio
      • Solver documentation
      • Solver - Example Flow
    • Trading Fees
      • Perps - Settlement Costs
      • Pair Trading - Settlement costs
    • Exchanges (Frontends)
      • Frontend Introduction
      • SDK - SYMM client
      • Trade on Symmio
  • Legal & Brand & Security
    • Security (Audits / Bugbounty)
      • Bug bounty / Coverage
        • How to contact ?
      • Audits
        • SYMM - V0.8 - 0.81
          • Sherlock Audit - Jun 15, 2023
          • Smart State - Jul 2, 2023
        • SYMM - 0.82
          • Sherlock Audit -Aug 30, 2023
        • SYMM - 0.83
          • Sherlock Audit - Jun 17, 2024
        • SYMM - 0.84
          • Sherlock Audit - Oct 3, 2024
        • Vaults
          • Sherlock Audit - Jan 2, 2024
    • Terms of Service & Licensing
      • TRADEMARK & COPYRIGHT NOTICE
      • CONTACT US
      • TERMS OF SERVICE
      • FRONTEND LICENSE
        • Frontend Modifications
        • Frontend Use Grants
      • CONTRACT LICENSE
        • Contract Use Grants
        • Contract Modifications
    • Brand - Assets Logos
Powered by GitBook
LogoLogo

All rights to the people (c) 2023 Symmetry Labs A.G.

On this page
  • Implementing Instant Actions
  • For Frontends:
  • For Solvers:
  • Overview
  • Authentication and Session Management
  • Nonce Retrieval
  • User Login
  • Get Pending Instant Open Requests
  • Response Schema:
  • Instant Actions
  • Instant Open Position
  • Instant Close Position
  • Get Instant Close Requests
  • Cancel Instant Action
  • Contract Calls for Instant Trading
  • Instant Open
  • Instant Close
  1. Protocol Architecture
  2. Technical Documentation
  3. Solver Docs
  4. Instant Trading

Rasa Instant Trading Implementation

PreviousInstant Trading (Solvers)NextInstant Trading Condition Checks

Last updated 5 months ago

Implementing Instant Actions

For Frontends:

To enable instant actions on the frontend, users must delegate specific functions to solvers so they can perform actions on the user's behalf without requiring signatures for each request.

Front-ends should ensure that the following functions are delegated to the respective solver addresses through the delegateAccess() method on the MultiAccount contract:

  • sendQuote: 0x7f2755b2

  • sendQuoteWithAffiliate: 0x40f1310c

  • requestToClosePosition: 0x501e891f

  • requestToCancelQuote: 0xa8ffc7ab

  • requestToCancelCloseRequest: 0xa63b9363

  • allocate: 0x90ca796b

The delegation should be initiated by calling delegateAccesses() on the contract, specifying the user’s sub-account, the target (solver) address, and the function selectors that need to be delegated.

For Solvers:

Overview

This document outlines how to implement Instant Trading for Solvers. Instant trading involves creating sessions for users allowing solvers to open and close positions on traders' behalf without requiring signatures for each action.

Users must first delegate certain functions to the solver to manage positions on behalf of them (sendQuote, sendQuoteWithAffiliate, requestToClosePosition)

The frontend then prompts to authenticate the user for instant actions and generates a message to sign. This message includes the following details:

  • Wallet Address (address): The multiaccount address to be used with instant trading.

  • Nonce (nonce): The nonce related to the request.

  • Domain (domain): The domain of the application.

  • URI (uri): The specific endpoint the request is associated with (e.g., the login endpoint).

  • Issued At (issuedAt): The timestamp when the message was created.

  • Expiration Time (expirationTime): The time after which the signature is no longer valid.

Once the message is signed, the frontend sends this signed message along with other necessary data (such as the nonce, expiration time, and wallet address) to the solver API via a request (e.g., to the /login endpoint).

The solver should issue an access token which the frontend stores and includes it in the headers of future requests until the token expires. Solvers should validate the stored access token before proceeding with any API request. The expiration time can be set by the frontend and should be checked before every API call.

This section covers the API endpoints and request/response structures needed for instant trading.

Authentication and Session Management

Before executing any trading actions, solvers must authenticate the user and manage sessions via the following endpoints.

Nonce Retrieval

Endpoint: GET /nonce/{activeAddress}

  • Description: Retrieve a nonce for signing the login message.

Parameters:

  • activeAddress (string): The user's active multiaccount wallet address.

Response:

{
 "nonce": "string"
}

User Login

Endpoint: POST /login

  • Description: Authenticates the user and retrieves an access token. The nonce is obtained in the previous API call. The access token is saved to the browser locally, meaning the user won't have to log in again after closing and reopening the browser.

Request Body:

{
 "account_address": "string",
 "expiration_time": "ISO8601 datetime string",
 "issued_at": "ISO8601 datetime string",
 "signature": "string",
 "nonce": "string"
}

Response:

{
 "access_token": "string"
}

Get Pending Instant Open Requests

Endpoint: GET /instant_open/{account_address}

Description: This endpoint retrieves a statement for all pending instant open requests for a given account.

Parameters:

  • account_address (string): The user's multi-account wallet address.

Response: A list of pending instant open requests for the given account. Each object in the list contains details of the requested positions.

Response Schema:

[
  {
    "position_type": 0 // 0 for long, 1 for short,
    "temp_quote_id": "string",
    "symbol_id": "string",
    "requested_open_price": "string",
    "quantity": "string",
    "party_a_address": "string",
    "cva": "string",
    "partyAmm": "string",
    "partyBmm": "string",
    "lf": "string",
    "order_type": 0 // 0 for limit, one for market
  }
]

Instant Actions

These endpoints allow solvers to execute instant open and close actions on the user's behalf.

Instant Open Position

Endpoint: POST /instant_open

Opens a position instantly on behalf of the user. The user’s account balance is checked, including allocated balance, unrealized PnL, and locked amounts (cva, lf, partyAmm). If the user has too many pending instant RFQs, or if their available balance does not cover the new RFQ's requirements, the request should be rejected.

A temporary quote ID is generated, and the necessary request data is emitted and stored in Redis. The request is registered as a pending instant open action (stored in the InstantRFQs table).

Response:

Upon successful registration, the details of the newly created instant RFQ are returned, including position type, symbol ID, quote ID, and other relevant data.

Request Body:

{
 "symbolId": "string",
 "positionType": 0, // 0 for long, 1 for short
 "orderType": 0,    // 0 for limit, 1 for market
 "price": "string",
 "quantity": "string",
 "cva": "string",
 "lf": "string",
 "partyAmm": "string",
 "partyBmm": "string",
 "maxFundingRate": "string",
 "deadline": 1625234523 // Unix timestamp
}

Headers:

headers: {
   "Content-Type": "application/json",
   Authorization: `Bearer ${token}`,
},

Response:

[
  {
    "position_type": 0 // 0 for long, 1 for short,
    "temp_quote_id": "string",
    "symbol_id": "string",
    "requested_open_price": "string",
    "quantity": "string",
    "party_a_address": "string",
    "cva": "string",
    "partyAmm": "string",
    "partyBmm": "string",
    "lf": "string",
    "order_type": 0 // 0 for limit, one for market
  }
]

This response includes the temporary temp_quote_id which allows the system to track the quote before it is confirmed on-chain. Once confirmed, the real quote_id will be resolved and stored.

How Temporary Quote IDs Work:

  • A temporary quote ID is generated as a negative decremental integer when the instant open request is made.

  • The temporary quote ID is used to track the status of the position until the actual on-chain quote_id is confirmed.

  • Once the on-chain transaction is confirmed, the real quote_id replaces the temporary one.

  • The position state endpoint will provide the real quote_id after the resolution, allowing the user to track the final status.

Instant Close Position

Endpoint: POST /instant_close

  • Description: Closes an open position instantly on behalf of the user. The API checks the validity of the request based on the user's access, the state of the position, and available balance The close is always processed as a MARKET order.

Request Body:

{
 "quote_id": number,
 "quantity_to_close": "string",
 "close_price": "string"
}

Headers:

headers: {
   "Content-Type": "application/json",
   Authorization: `Bearer ${token}`,
},

Response:

{
 "successful": "boolean",
 "message": "string"
}

Get Instant Close Requests

Endpoint: GET /instant_close/{account_address}

Description: Retrieves all pending instant close requests for the provided user's account (account_address). The system returns a list of pending close requests for both instant close requests and any regular close requests that are still being processed.

Headers:

{
  "Authorization": `Bearer ${token}`   // Access token obtained during login
}

Response:

[
  {
    "quote_id": number,             
    "quantity_to_close": "string",  
    "close_price": "string"           },
  {
    "quote_id": number,
    "quantity_to_close": "string",
    "close_price": "string"
  }
]

Cancel Instant Action

Endpoints:

  • DELETE /instant_close/{quoteId}

  • DELETE /instant_open/{quoteId}

Description: Cancel an open or close request.

Parameters:

  • quoteId (integer): The temporary ID of the instant quote to be canceled.

Headers:

headers: {
   "Content-Type": "application/json",
   Authorization: `Bearer ${token}`,
},

Response:

{
 "successful": "boolean",
 "message": "string"
}

Contract Calls for Instant Trading

In order to implement instant actions it’s necessary for the user to call delegateAccess() on the MultiAccount contract for the respective sub-account to the partyB address, which performs actions on behalf of the user. This transaction should include the function signatures which partyB needs access to for instant trading.

To execute functions on behalf of partyA, the partyB should use the _call() function on the MultiAccount contract and pass the partyA address as a parameter with the _callDatas.

After this step the user should then sign the message from the solver.

Instant Open

For Instant Opens, delegateAccess() should be called from the trader’s wallet with the following parameters:

  • account (address): The User’s sub-account

  • target (address) : The address of the PartyB

  • selector (bytes4[]): 0x7f2755b2 (Function selector for sendQuote) AND 0x40f1310c (Function selector for sendQuoteWithAffiliate)

  • state (bool): true

Instant Close

For Instant Close, delegateAccess() should be called from the trader’s wallet with the following parameters:

  • account(address): The User’s sub-account

  • target(address) : The address of the PartyB

  • selector(bytes4[]): 0x501e891f (Function selector for requestToClosePosition)

  • state (bool): true

MultiAccount