# Quoter

# auth

Get a JWT access token to connect to a quoter server

# Parameters:

Name Type
authInfo AuthInfo

# Code sample:

const signer = new Signer(ethers.provider)
const authInfo = await signer.signAuthToken()

const chainId = await ethers.provider.getNetwork().chainId
const quoter = new Quoter(chainId)
const accessToken = await quoter.auth(authInfo)

# Response:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmMzlmZDZlNTFhYWQ4OGY2ZjRjZTZhYjg4MjcyNzljZmZmYjkyMjY2IiwiYWRkcmVzcyI6ImYzOWZkNmU1MWFhZDg4ZjZmNGNlNmFiODgyNzI3OWNmZmZiOTIyNjYiLCJpYXQiOjE2MzUxMzI4NjF9.JLYYeVxyrmmIZj_Ihh2dF0Wnw4bkql1Lms4FSDVOQWg

# checkOrder

To check a transaction order status

# Parameters:

Name Type
order OrderResponse

# Code sample:

const quoter = new Quoter(chainId)
const order = await quoter.getNewOrderAsync({
  base: 'ETH',
  quote: 'LON',
  side: 'SELL',
  amount: '1.10',
  protocols: [Protocol.AMMV1],
})
const orderResult = quoter.checkOrder(order)

# Response:

{
  isValidOrder: true,
  errorMessage: undefined
}

# connect

To connect to the quoter server with one access token

# Parameters:

Name Type
accessToken string
connectCallback (frame: Frame) => void
errorCallback (error: Frame | string) => void

# Code sample:

const quoter = new Quoter(chainId)
const accessToken = await quoter.auth(authInfo)
quoter.connect(
  accessToken,
  frame => console.log(frame),
  error => {},
)

# Response:

{
  command: 'CONNECTED',
  headers: { 'heart-beat': '0,0', version: '1.1' },
  body: ''
}

# disconnect

To disconnect to the quoter server

# Code sample:

const quoter = new Quoter(chainId)
const accessToken = await quoter.auth(authInfo)
quoter.isConnected()
quoter.connect(
  accessToken,
  () => {},
  () => {},
)
quoter.isConnected()
quoter.disconnect()

# getNewOrder

To get a new transaction order with a callback

# Parameters:

Name Type Optional
base string
quote string
side 'BUY' | 'SELL'
amount number | string true
protocols Protocol[] true
callback (err: Error, topic: string, order: any, subscription: Subscription) => void): void true

# Code sample:

const quoter = new Quoter(chainId)
quoter.getNewOrder(
  {
    base: 'ETH',
    quote: 'LON',
    side: 'SELL',
    amount: 1.1,
  },
  (err, topic, order, subscription) => console.log(order),
)

# Response:

{
  exchangeable: true,
  order: {
    makerAddress: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
    makerAssetAmount: '7261144179280000000000',
    makerAssetData: '0xf47261b00000000000000000000000006da0e6abd44175f50c563cd8b860dd988a7c3433',
    makerFee: '0',
    takerAddress: '0x97959853a0fb9a28432f1d4f46654fe524a12d81',
    takerAssetAmount: '1100000000000000000',
    takerAssetData: '0xf47261b00000000000000000000000000000000000000000000000000000000000000000',
    takerFee: '0',
    senderAddress: '0xc23dc48e847ea67cde9a93d0df242f9584abc90d',
    feeRecipientAddress: '0xb9e29984fe50602e7a619662ebed4f90d93824c7',
    expirationTimeSeconds: '1635134664',
    exchangeAddress: '0xb17dfecab333cae320fed9b84d8caddc61f9a687',
    salt: '43811021524320977824550734425727913146541637971384397012923810506603185278237',
    makerWalletSignature: 'e508706a3720d82315eb2b7b270efc90dbefcc36',
    quoteId: '22--a4e50b76-ad0d-4db5-830d-4099b9e1a6d0',
    feeFactor: 10,
    feeDetail: {
      stdFee: 30,
      tokenlonFee: 10,
      gasFee: 0,
      refuelSendETH: 0,
      refuelApprove: 0,
      vendorFee: 0
    },
    protocol: 'AMMV1',
    makerAssetAddress: '0x6da0e6abd44175f50c563cd8b860dd988a7c3433',
    takerAssetAddress: '0x0000000000000000000000000000000000000000',
    payload: ''
  },
  rate: 6601.04016299,
  timestamp: 0,
  minAmount: 0.1,
  maxAmount: 15.149127,
  message: null,
  reason: null,
  mmCode: 'V5AMM-QUOTER',
  requestTime: 1635132863657,
  responseTime: 1635132863715,
  serialNo: 1
}

# getNewOrderAsync

To get a new transaction order asynchronously

# Parameters:

Name Type Optional
base string
quote string
side 'BUY' | 'SELL'
amount number | string true
protocols Protocol[] true

# Code sample:

const quoter = new Quoter(chainId)
const order = await quoter.getNewOrderAsync({
  base: 'ETH',
  quote: 'LON',
  side: 'SELL',
  amount: '1.10',
  protocols: [Protocol.AMMV1],
})

# Response:

{
  exchangeable: true,
  order: {
    makerAddress: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
    makerAssetAmount: '7261144179280000000000',
    makerAssetData: '0xf47261b00000000000000000000000006da0e6abd44175f50c563cd8b860dd988a7c3433',
    makerFee: '0',
    takerAddress: '0x97959853a0fb9a28432f1d4f46654fe524a12d81',
    takerAssetAmount: '1100000000000000000',
    takerAssetData: '0xf47261b00000000000000000000000000000000000000000000000000000000000000000',
    takerFee: '0',
    senderAddress: '0xc23dc48e847ea67cde9a93d0df242f9584abc90d',
    feeRecipientAddress: '0xb9e29984fe50602e7a619662ebed4f90d93824c7',
    expirationTimeSeconds: '1635134664',
    exchangeAddress: '0xb17dfecab333cae320fed9b84d8caddc61f9a687',
    salt: '43811021524320977824550734425727913146541637971384397012923810506603185278237',
    makerWalletSignature: 'e508706a3720d82315eb2b7b270efc90dbefcc36',
    quoteId: '22--a4e50b76-ad0d-4db5-830d-4099b9e1a6d0',
    feeFactor: 10,
    feeDetail: {
      stdFee: 30,
      tokenlonFee: 10,
      gasFee: 0,
      refuelSendETH: 0,
      refuelApprove: 0,
      vendorFee: 0
    },
    protocol: 'AMMV1',
    makerAssetAddress: '0x6da0e6abd44175f50c563cd8b860dd988a7c3433',
    takerAssetAddress: '0x0000000000000000000000000000000000000000',
    payload: ''
  },
  rate: 6601.04016299,
  timestamp: 0,
  minAmount: 0.1,
  maxAmount: 15.149127,
  message: null,
  reason: null,
  mmCode: 'V5AMM-QUOTER',
  requestTime: 1635132863657,
  responseTime: 1635132863715,
  serialNo: 1
}

# getRate

To get the exchange rate with a callback

# Parameters:

Name Type Optional
base string
quote string
side 'BUY' | 'SELL'
amount number | string true
protocols Protocol[] true
callback (err: Error, topic: string, quote: any, subscription: Subscription) => void): void true

# Code sample:

const quoter = new Quoter(chainId)
quoter.getRate(
  {
    base: 'ETH',
    quote: 'LON',
    side: 'SELL',
    amount: 1,
  },
  (err, topic, quote, subscription) => console.log(quote),
)

# Response:

{
  exchangeable: true,
  minAmount: 0.002,
  rate: '6602.32778604',
  maxAmount: 5000111
}

# getRateAsync

To get the exchange rate asynchronously

# Parameters:

Name Type Optional
base string
quote string
side 'BUY' | 'SELL'
amount number | string true
protocols Protocol[] true

# Code sample:

const quoter = new Quoter(chainId)
const quote = await quoter.getRateAsync({
  base: 'ETH',
  quote: 'LON',
  side: 'SELL',
  amount: 1,
})

# Response:

{
  exchangeable: true,
  minAmount: 0.002,
  rate: '6602.32778604',
  maxAmount: 5000111
}

# getTradeTokenList

To get a list of all tradable tokens

# Parameters:

Name Type
protocols Protocol[]

# Code sample:

const quoter = new Quoter(chainId)
const tokens = await quoter.getTradeTokenList([Protocol.AMMV1])

# Response:

[
  ...
  {
    contractAddress: '0x0000000000000000000000000000000000000000',
    decimal: 18,
    logo: 'https://v2-cdn.token.im/app-mainnet-production/tokens/icons/eth%403x.png',
    maxTradeAmount: '888',
    minTradeAmount: '0.025',
    opposites: [
      'KEEP', 'USDT',  'DAI',  'USDC',
      'WBTC', '1INCH', 'LON',  'BOND',
      'FEI',  'BANK',  'TORN', 'ALCX',
      'WOO',  'LUNA',  'BAL',  'ILV',
      'MCB',  'MIR',   'POOL', 'GTC',
      'DYDX', 'CEL',   'ERN',  'NU',
      'SLP',  'AXS',   'SHIB', 'INJ',
      'GNO',  'FLOAT', 'AMP',  'LPT',
      'QNT',  'LIT',   'POLS'
    ],
    precision: 4,
    recommend: true,
    symbol: 'ETH'
  }
]

# isConnected

To check whether connect to the quote server

# Code sample:

const quoter = new Quoter(chainId)
const accessToken = await quoter.auth(authInfo)
quoter.connect(
  accessToken,
  () => {},
  () => {},
)
quoter.isConnected()

# Response:

true

# previewOrder

To preview a transaction order details, like gas fee

# Parameters:

Name Type Optional
order OrderResponse
slippagePercent number true

# Code sample:

const quoter = new Quoter(chainId)
const order = await quoter.getNewOrderAsync({
  base: 'ETH',
  quote: 'LON',
  side: 'SELL',
  amount: '1.10',
  protocols: [Protocol.AMMV1],
})
const orderPreview = quoter.previewOrder(order, 1)

# Response:

{
  protocol: 'AMMV1',
  marketMaker: 'V5AMM-QUOTER',
  makerAddress: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
  makerAssetSymbol: 'LON',
  makerAssetAddress: '0x6da0e6abd44175f50c563cd8b860dd988a7c3433',
  makerAssetAmount: '7261.14417928',
  takerAddress: '0x97959853a0fb9a28432f1d4f46654fe524a12d81',
  takerAssetSymbol: 'ETH',
  takerAssetAddress: '0x0000000000000000000000000000000000000000',
  takerAssetAmount: '1.1',
  feeAmount: '7.26114417928',
  receivedAmount: '7253.88303510072',
  minimalReceivedAmount: '7181.3442047497128'
}