LogoLogo
AppBlogGovSocials
  • What is Premia?
    • Premia Origins
      • History
      • Principles
      • Mission, Vision, & Values
  • Quick Start
  • The Premia Protocol
    • Options on Premia
      • Options Primer
      • Order-book vs. AMM
    • Key Protocol Features
      • Base Layer (Exchange)
      • Depot Layer (Vaults)
      • Messaging Layer (RFQ & OB)
      • Fee Schedule
      • Differentiators
    • Concepts
      • LP Range Orders
      • Trading
      • Orderbook & Request-for-Quote (RFQ)
      • Fees
      • Exercise & Settlement
      • Margin
      • Oracles
      • Liquidity Mining
      • Referral Programs
      • Advanced Exchange Concepts
        • Token Integration Requirements
        • Flash Swaps and Loans
      • Vault Depot
        • What is a Depot?
        • APY Calculation
        • Underwriter Depot
    • Governance
      • Premian Civitas
        • Parliament
        • Blue Descent
        • Premian Assembly
        • "Influence" Politics
      • Voting (vxPremia)
        • vxPremia Manifold
        • vxPremia Rewards
          • Options Liquidity Mining
          • Protocol Commissions
          • AirDrip Initiative
      • Operator & Facilitator Role
        • Operational Expenditure and Maintenance Costs
        • Insurance Fund
      • Meta Economics
  • Developer Center
    • APIs
      • Orderbook API
        • REST API
        • WEBSOCKET
      • Subgraph API
      • Containerized API
        • API Reference
          • Orderbook
            • Quotes
            • Orders
          • Pool
            • Settle
            • Exercise
            • Annihilate
          • Account
            • Collateral Approval
            • Orders
            • Collateral Balances
            • Native Balance
            • Option Balances
          • Pools
            • Find Pools
            • Create Pools
            • Valid Maturities
            • Valid Strikes
          • Oracles
            • IV
            • Spot
          • Vaults
            • Quote
            • Trade
        • WebSockets Reference
          • Authorization
          • Connection
          • Quotes Channel
          • RFQ Channel
    • SDK
      • Guides
      • SDK Technical Docs
    • Contracts
      • Multi-Signature Wallets
      • V3 Protocol
        • Overview
        • Guides
        • Smart Contract Technical Documentation
      • Margin
      • Orderbook
      • vxPremia
      • Universal Router
      • Vaults
    • Integrations
      • Use Cases
      • Code Snippets
    • Subgraph
    • V3 Change log
  • Bots
    • Range Order Bot
  • Resources
    • VIP & Institutional Services
    • Media Kit
    • Bug Bounty
    • Audits
    • Community Groups
    • Research
      • SSVI
    • Legal, Terms, & Disclaimers
      • Terms of Service
      • Privacy Policy
      • Cookie Policy
      • Prohibited Use
      • Affiliate & Advocate Program
      • Self-Service Affiliate Agreement
      • Bug Bounty Terms
      • Academy/Newsletter Disclaimer
      • Trading Competition Terms and Disclaimers
      • Blue Descent
      • Legal Disclaimer
      • Media Disclaimer
      • AML/KYC Policies
      • Intellectual Property
      • Amendments & Updates
      • Contact Us
      • FAQs (WIP)
    • 📰Newsletter
    • 🌊Crypto News Blotter
    • 🎓Academy
    • 🔵Premia Blue (V3)
    • 💎Premia V2 Docs
Powered by GitBook

Terms and Disclaimers

  • Privacy Policy
On this page

Was this helpful?

  1. Developer Center
  2. APIs
  3. Containerized API
  4. WebSockets Reference

Quotes Channel

The Quote channel is where ALL quotes (limit orders) and state changes to the orderbook can be found. Additionally, quotes from an RFQ request can also be retrieved here.

Filter Message (Quotes)

All channels require a filter message prior to streaming. Filter messages will define what data is streamed along with activating the stream itself. There are several parameters that can be used to refine the stream.

chainId (Required) : Designate whether the stream is for a production chain or testnet chain

poolAddress (Optional): filter by specific option market

side (Optional): filter by either bid only or ask only

size (Optional): filter by minimum size

The size parameter must be represented in a string that is in 10^18 format. For example, if the filter for size is mean to be 2, then value here must be '2000000000000000000'.

provider (Optional): filter by quote providers

taker (Optional): filter by taker address is IMPORTANT for RFQ network users. There are 3 ways to configure this:

  1. omit: if this filter param is omitted, then only public quotes will stream. If there is no intention of using the RFQ network, omit this filter.

  2. address: if the intention is to use the RFQ network to request quotes, populate this field with the wallet address of the requester to see all relevant PostQuote messages from quote providers

  3. * -> if the intention is to use the RFQ network to provide/request quotes, populate this field with a star to see all relevant FillQuote messages.

/*
TypeScript Sample Code
NOTE: since this is an API,  WS logic can be written in any language. This example
is in typescript, but the overall sequence will be the same for any language.
*/

import { RawData, WebSocket } from 'ws'

// Example if Containerized API runtime is local
const url = `ws://localhost:${process.env.HTTP_PORT}`
const wsConnection = new WebSocket(url)
const MOCK_API_KEY = '3423ee2bfd89491f82b351404'


const authMessage: AuthMessage = {
  type: 'AUTH',
  apiKey: MOCK_API_KEY,
  body: null
}

// send AuthMessage
wsConnection.send(JSON.stringify(authMsg))

/*
This filter message will listen to all PUBLIC quote and will additionally
receive PRIVATE quotes from the RFQ network.
*/

const webSocketFilter: FilterMessage = {
  type: 'FILTER',
  channel: 'QUOTES',
  body: {
    chainId: '42161',
    taker: '0x170f9e3eb81ed29491a2efdcfa2edd34fdd24a71' // mock address
  }
}

// handle message ingestion from ws
const wsCallback = (data: RawData) => {
  const message: InfoMessage | PostQuoteMessage | FillQuoteMessage | DeleteQuoteMessage = JSON.parse(data.toString())
    switch (message.type) {
        case 'INFO': {
            // auth result message will arrive here
            break
        }
        case 'POST_QUOTE': {
            // new quotes will arrive here
    	    break
        }
        case 'FILL_QUOTE': {
            // filled quotes will arrive here
    	    break
        }
        case 'DELETE_QUOTE': {
            // cancelled quotes will arrive here
    	    break
        }
        case 'ERROR': {
            // any error message will arrive here
    	    break
        }
        // throw error if case not covered
        default: {
      	    throw `Unexpected message type ${message.type}`
        }
    }
}

// subscribe to WS messages
wsConnection.on('message', wsCallback)

// send FilterMessage to start getting quotes stream
wsConnection.send(JSON.stringify(webSocketFilter))


// unsubscribe to WS messages
// NOTE: unsubscribing does NOT close the ws connection
const unsubscribeMsg: WSUnsubscribeMessage = {
    type: 'UNSUBSCRIBE',
    channel: 'QUOTES',
    body: null,
}

wsConnection.send(JSON.stringify(unsubscribeMsg))
// auth message 
interface AuthMessage {
  type: 'AUTH'
  apiKey: string
  body: null
}

// filter message
interface FilterMessage {
  type: 'FILTER'
  channel: 'QUOTES' | 'RFQ' // which channel to subscribe to
  body: {
    chainId: '42161' | '421613'
    poolAddress?: string
    side?: 'bid' | 'ask'
    size?: string
    provider?: string
    taker?: string
  }
}

// INFO message from Premia orderbook
interface InfoMessage {
  type: 'INFO'
  body: null
  message: string
}

// Quote messages
interface PostQuoteMessage {
  type: 'POST_QUOTE'
  body: ReturnedOrderbookQuote
}

interface FillQuoteMessage {
  type: 'FILL_QUOTE'
  body: ReturnedOrderbookQuote
  size: string
}

interface DeleteQuoteMessage {
  type: 'DELETE_QUOTE'
  body: ReturnedOrderbookQuote
}

// ERROR message from Premia orderbook
interface ErrorMessage {
  type: 'ERROR'
  body: null
  message: string
}

// Quote object
interface ReturnedOrderbookQuote {
  base: string // token name
  quote: string // token name
  expiration: string
  strike: number
  type: 'C' | 'P'
  side: 'bid' | 'ask'
  size: number
  price: number
  deadline: number
  quoteId: string
  ts: number
}

// Unsubscribe message
interface WSUnsubscribeMessage {
    type: 'UNSUBSCRIBE'
    channel: 'QUOTES' | 'RFQ'
    body: null
}
PreviousConnectionNextRFQ Channel

Last updated 1 year ago

Was this helpful?