OptSwap
  • What is OptSwap?
  • Quick Start
    • Concepts & Definitions
    • Making Your First Trade
    • Managing Your Orders
    • Managing Your Positions
  • User Manual
    • Trading
      • Limit Orders
      • Option Spreads
      • Advanced Order Types
        • Batch Orders
        • All-or-None Fill Type
        • Multi-Legged Strategies
      • Automated Market Maker (AMM)
        • Managed Orders
        • Aggregated Spot Price
        • Liquidity Provider Rewards
        • Match Finder Rewards
      • Modify & Cancel Orders
      • Positions
        • Converting Positions
      • User Accounts
      • Options Oracles
      • Margin Requirements
      • Fees
    • Settlements
      • Exercise Option
      • Force Cash Settlements
      • Recover Margin
      • Automated Settlements
        • Settlements Execution Rewards
    • Meta Oracle
      • Methodology
      • Fetching Price Data
      • Price Mining
      • Managing Oracles
      • Donations
    • Governance
      • Concepts & Definitions
      • Tokenomics
      • Proposals
      • Proposal Types
      • Voting & Execution
      • Fundraising
      • DAO Treasury
      • Commercial Papers
      • Airdrops
      • Staking
      • OptSwap Miner
      • Contracts Registry
      • Testnet Faucet
      • Donations
  • Technical Reference
    • API Overview
    • Smart Contracts
      • Deployment Addresses
      • MetaOracle
      • OptSwap
      • OptSwapAMM
      • OptSwapDAOAirdrops
      • OptSwapDAOFundraising
      • OptSwapDAOGovernance
      • OptSwapDAOStaking
      • OptSwapDAOToken
      • OptSwapDAOVeToken
      • OptSwapDAOCommercialPaperToken
    • Subgraphs
      • Endpoints
      • Entities
      • Querying
        • Example Queries
    • REST API
      • Endpoints
      • API Methods
  • Other
    • Terms and Conditions
    • Risk Warnings
    • Privacy Policy
Powered by GitBook
On this page
  • My Orders
  • My Positions
  • Latest Blocks

Was this helpful?

  1. Technical Reference
  2. Subgraphs
  3. Querying

Example Queries

Assuming your address is 0xd8da6bf26964af9d7eed9e03e53415d37aa96045 (Hi Vitalik 👋), here are some sample GraphQL queries to get you quickly started with OptSwaps subgraphs. Feel free to explore all the other entities and fields available!

Refer to the associated smart contracts documentation for full details about the various returned enumerated types and denominations.

My Orders

# All My Orders
query MyOrders {
  optSwapOrders(where: { user: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" }) {
    id
    contract
    optionStyle
    optionType
    strike0
    strike1
    expiry
    lotSize
    orderType
    premium
    lots
    user
    timestamp
    blockNumber
  }
}

# Response:
{
  "data": {
    "optSwapOrders": [
      {
        "id": "0x18bb81e4153528cd8823857726b2ca6f994450ae010bd20a9bb5550436fb6498-2",
        "contract": "0xdbebcddf47ea77561ab5f98c40baf2f89a6770d4",
        "optionStyle": 0, # European Style Option
        "optionType": 1, # Call Option
        "strike0": "12000000", # in basis points of the cash token
        "strike1": "170141183460469231731687303715884105728", # 2^127 for Call Options
        "expiry": "1657267200", # Unix timestamp
        "lotSize": "10000", # in basis points
        "orderType": 1, # Buy Order
        "premium": "100", # in basis points of the cash token
        "lots": "10",
        "user": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
        "timestamp": "1656920647", # Unix timestamp
        "blockNumber": "27025991"
      },
      ...
    ]
  }
}

My Positions

# All My Positions for a given expiry timestamp
query MyPositionsForLastExpiry {
  optSwapPositions(where: { expiry: "1657267200",  user: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" }) {
    id
    contract
    optionStyle
    optionType
    strike0
    strike1
    expiry
    lotSize
    orderType
    lots
    lotsLocked
    lotsSettled
    bookedProfitsOrLosses
    user
    createdAt
    timestamp
    blockNumber
  }
}

# Response:
{
  "data": {
    "optSwapPositions": [
      {
        "id": "0xaccd7b5f1adaab6f911d3a944adcb5966ee220cfbf104e5e3cdd6e4803fec876",
        "contract": "0xdbebcddf47ea77561ab5f98c40baf2f89a6770d4",
        "optionStyle": 1, # American Style Option
        "optionType": 0, # Put Option
        "strike0": "12000000", # in basis points of the cash token
        "strike1": "0", # in basis points
        "expiry": "1657267200", # Unix timestamp
        "lotSize": "10000", # in basis points (of the underlying token)
        "orderType": 0, # Sell Order
        "lots": "3",
        "lotsLocked": "0",
        "lotsSettled": "3",
        "bookedProfitsOrLosses": "-372000000", # Negative values mean losses; in subunits of the Cash Token
        "user": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
        "createdAt": "1656919724", # Unix timestamp
        "timestamp": "1656919724", # Unix timestamp
        "blockNumber": "27025831"
      },
      ...
    ]
  }
}

Latest Blocks

# The latest block indexed by the subgraph
query LastIndexedBlock {
  latestBlock(id: "latest") {
    id
    timestamp
    number
  }
}

# Response:
{
  "data": {
    "latestBlock": {
      "id": "latest",
      "timestamp": "1657379691", # Unix timestamp
      "number": "27097838"
    }
  }
}

# Latest blocks in which each contract was interacted with
query ContractInteractionLatestBlocks {
  latestBlocks {
    id
    timestamp
    number
  }
}

# Response:
{
  "data": {
    "latestBlocks": [
      {
        "id": "MetaOracle",
        "timestamp": "1657365133", # Unix timestamp
        "number": "27095701" # Block number
      },
      {
        "id": "OptSwap-0x83577b77c5a0a169883bc5cd5d7585cc77c94358",
        "timestamp": "1656862308",
        "number": "27017041"
      },
      ...
      {
        "id": "OptSwapDAOVeToken",
        "timestamp": "1656863802",
        "number": "27017299"
      },
      {
        "id": "latest",
        "timestamp": "1657386405",
        "number": "27099049"
      }
    ]
  }
}
PreviousQueryingNextREST API

Last updated 10 months ago

Was this helpful?