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
  • Overview
  • Authorize Websocket
  • Subscribe to Quotes (Orderbook & RFQ)
  • Publish RFQ Request(s)
  • Subscribe to RFQ Requests

Was this helpful?

  1. Developer Center
  2. APIs
  3. Orderbook API

WEBSOCKET

Websocket Functionality

PreviousREST APINextSubgraph API

Last updated 1 year ago

Was this helpful?

Overview

Chain
Websocket Url

Arbitrum Goerli (421613)

wss://test.quotes.premia.finance

Arbitrum One (42161)

wss://quotes.premia.finance

Using the WEBSOCKET connection, it is possible to:

  • public/RFQ quotes from the orderbook in realtime

  • an RFQ requests (for market takers) to receive personalized quotes

  • RFQ requests (for market makers) to subsequently provide personalize quotes

Authorize Websocket

Upon connection with the Websocket server, users must send an AUTH message with an api key. If this step is not done, any requests to Stream quotes or Publish RFQ requests will be denied.

// Javascript Sample Code
const { WebSocket } = require('ws')

const wsUrl = 'test.quotes.premia.finance'
const MOCK_API_KEY = '3423ee2bfd89491f82b351404ea8c3b7'

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


const ws = new WebSocket(`wss://${wsUrl}`)
function connectWebsocket() {
  ws.onopen = (event) => {
    console.log("Websocket connection open")
    ws.send(JSON.stringify(authMessage))
    ws.onmessage = (event) => {
      console.log(JSON.parse(event.data).message)
      ws.close()
    }
  }
}

connectWebsocket()

Subscribe to Quotes (Orderbook & RFQ)

// Javascript Sample Code
const { WebSocket } = require('ws')
const { parseEther } = require("ethers");

const wsUrl = 'test.quotes.premia.finance'
const MOCK_API_KEY = '3423ee2bfd89491f82b351404ea8c3b7'

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

/*
Optional params in body include:
poolAddress -> specific option market
size -> stringified 10^18 value
side -> 'bid' or 'ask'
taker -> taker address (use if publishing RFQ and want to receive personal quotes)
provider -> quote provider address
 */
const filterMessage = {
  type: 'FILTER',
  channel: 'QUOTES',
  body: {
    chainId: '421613',
    poolAddress: '0xeB785e131784ea28b6B64B605CF8aa83D69793b5'
  }
}

const ws = new WebSocket(`wss://${wsUrl}`)
function connectWebsocket() {
  ws.onopen = (event) => {
    console.log("Websocket connection open")
    ws.send(JSON.stringify(authMessage))
    ws.onmessage = (event) => {
      console.log(JSON.parse(event.data).message)
      sendMessage(filterMessage)
    }
  }
}

function sendMessage(_message){
  ws.onmessage = (event) => {
    console.log(JSON.parse(event.data).message)
  }
  ws.send(JSON.stringify(_message))
  setTimeout(() => {
    console.log("Closing connection")
    ws.close()
  }, 1000)
}

connectWebsocket()
		

Publish RFQ Request(s)

// Javascript Sample Code
const { WebSocket } = require('ws')
const { parseEther } = require("ethers");

const wsUrl = 'test.quotes.premia.finance'
// or quotes.premia.finance for prod environment

const MOCK_API_KEY = '3423ee2bfd89491f82b351404ea8c3b7'

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

// All fields are required
const rfqPublishMessage = {
  type: 'RFQ',
  body: {
    poolKey: {
      	base: '0x7F5bc2250ea57d8ca932898297b1FF9aE1a04999'
	quote: '0x53421DB1f41368E028A4239954feB5033C7B3729'
	oracleAdapter: string
	// serialised bigint
	strike: parseEther('1700').toString()
	// make sure maturities either tomorrow, 
	// the day after tomorrow, 
	// each Friday of current month, 
	// last Friday of each next month
	// 8:00 AM UTC
	maturity: 1702022400
	isCallPool: boolean
    },
    side: 'ask',
    chainId: '421613', // or '42161' for prod environment
    size: parseEther('1').toString(),
    taker: '0x3D1dcc44D65C08b39029cA8673D705D7e5c4cFF2'
  }
}

const ws = new WebSocket(`wss://${wsUrl}`)
function connectWebsocket() {
  ws.onopen = (event) => {
    console.log("Websocket connection open")
    ws.send(JSON.stringify(authMessage))
    ws.onmessage = (event) => {
      console.log(JSON.parse(event.data).message)
      sendMessage(rfqPublishMessage)
    }
  }
}

function sendMessage(_message){
  ws.onmessage = (event) => {
    console.log(JSON.parse(event.data).message)
  }
  ws.send(JSON.stringify(_message))
  setTimeout(() => {
    console.log("Closing connection")
    ws.close()
  }, 1000)
}

connectWebsocket()

Subscribe to RFQ Requests

As a market maker who would like to provide quotes to users who want to utilize RFQ, it will require subscribing to requests to be alerted when a request is made. In order to respond to an RFQ, market maker must publish quotes (via rest api), with the takerAddress populated with the requesters address, otherwise the quote is fillable by any party and will likely be missed by the requester who is listening for quotes with their address populated in the takerAddress field of a quote.

// Javascript Sample Code
const { WebSocket } = require('ws')

const wsUrl = 'test.quotes.premia.finance'
const MOCK_API_KEY = '3423ee2bfd89491f82b351404ea8c3b7'

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

/*
chainId is required.
Optional params in body include:
poolAddress -> specific option market
side -> 'bid' or 'ask'
 */
const rfqListenMessage = {
  type: 'FILTER',
  channel: 'RFQ',
  body: {
    chainId: '421613',
  },
}

const ws = new WebSocket(`wss://${wsUrl}`)
function connectWebsocket() {
  ws.onopen = (event) => {
    console.log("Websocket connection open")
    ws.send(JSON.stringify(authMessage))
    ws.onmessage = (event) => {
      console.log(JSON.parse(event.data).message)
      sendMessage(rfqListenMessage)
    }
  }
}

function sendMessage(_message){
  ws.onmessage = (event) => {
    console.log(JSON.parse(event.data).message)
  }
  ws.send(JSON.stringify(_message))
  setTimeout(() => {
    console.log("Closing connection")
    ws.close()
  }, 1000)
}

connectWebsocket()

Subscribing to quotes allows a user to stream real time quotes that are published to the orderbook along with any private quotes that may also be available from an . By default, ALL public quotes are subscribed to upon authorization of a websocket connection. FILTER messages are required.

If the desire is to send an RFQ request to receive personalized quotes, it must be done by sending an RFQ message type. Please note that in order to RECEIVE these personalized quotes via websocket, the FILTER message when subscribing to quotes must include the taker address. Alternatively, it is possible to use the get REST API endpoint.

Stream
Publish
Stream
RFQ request
rfqQuotes