SwapRate API API Reference

Description

Following specification describes the way to connect to swaprate.finance relayer of Opium Protocol via REST API and Socket.io endpoint.

REST API allows to fetch login message for authentication, load currently supported products, tokens and maturities, user tokens balance and allowance state, form, sign and cancel orders, alongside with getting quotes for fixed rate deposit.

Socket.io endpoint allows to reactively receive updates on current orderbook status (charts). Also using access token it's possible to receive updates on statuses of user's orders, performed swaps and current active positions on third party platforms (e.g. Compound Finance).

Socket.io

socket.io specification which could be found here

Authorization

Some of the HTTP and Socket.io endpoints are protected (user-based), thus require to include access token within a request and connection.

Access token is base64 encoded JSON, which should be used as Bearer authorization token and have the following structure.

{
  ttl: number, // UNIX token expiration timestamp used in signature
  address: string, // User's public key
  signature: string, // Signature of login message
}
API Endpoint
https://api.test.swaprate.finance/v1
Contact: info@opium.team
Request Content-Types: application/json
Response Content-Types: application/json
Schemes: https
Version: 1.1.7

Authentication

AccessToken

Bearer $ACCESS_TOKEN

type
apiKey
in
header
name
Authorization

Authentication

Returns login parameters and login message to sign in EIP712 format

GET /auth/loginData
Response Example (200 OK)
{
  "ttl": "number",
  "data": {
    "types": {
      "EIP712Domain": [
        {
          "name": "string",
          "type": "string"
        }
      ],
      "Login": [
        {
          "name": "string",
          "type": "string"
        }
      ]
    },
    "primaryType": "string",
    "domain": "object",
    "message": "object"
  }
}

Meta

Returns object with relayer configuration

GET /meta/config
Response Example (200 OK)
{
  "networkId": "number",
  "defaults": {
    "productId": "string"
  },
  "supportedTokens": [
    {
      "title": "string",
      "address": "string",
      "decimals": "number"
    }
  ],
  "opiumContracts": {
    "TokenSpender": "string",
    "CompoundSupplyAggregator": "string"
  },
  "supportedMaturities": [
    "number"
  ]
}

Products

Returns list of products currently available to trade

GET /products
Response Example (200 OK)
[
  {
    "productId": "string",
    "title": "string",
    "token": "string",
    "type": "string",
    "subtype": "string",
    "margin": "number",
    "fixedRateSupported": "boolean"
  }
]

Returns the possible fixed rate settlement on product with required nominal and maturity

GET /products/{productId}/quote
productId: string
in path

ID of the product to get the quote from

maturity: integer
in query

UNIX timestamp of one of supported maturities in seconds

nominal: integer
in query

Nominal of quoting order

404 Not Found

Not found

422 Unprocessable Entity

Unprocessable entity

429 Too Many Requests

Too many requests

Response Example (200 OK)
{
  "fixedRate": "number"
}

Wallet

Returns object with user's token balances and allowances

GET /wallet/balance
401 Unauthorized

Unauthorized

403 Forbidden

Forbidden

Response Example (200 OK)
{
  "eth": "number",
  "tokens": [
    {
      "title": "string",
      "total": "number",
      "allowance": "number",
      "compoundSupplyAllowance": "number"
    }
  ]
}

Orders

Forms blockchain order to be signed by user in EIP712 format

POST /orders/form
Request Example
{
  "productId": "string",
  "pay": {
    "type": "string",
    "rate": "number"
  },
  "receive": {
    "type": "string",
    "rate": "number"
  },
  "nominal": "number",
  "maturity": "number",
  "partialFill": "boolean",
  "aggregate": "string"
}
401 Unauthorized

Unauthorized

403 Forbidden

Forbidden

404 Not Found

Not found

412 Precondition Failed

Precondition Failed

422 Unprocessable Entity

Unprocessable entity

429 Too Many Requests

Too many requests

Response Example (200 OK)
{
  "formedOrderId": "string",
  "orderToSign": {
    "types": {
      "EIP712Domain": [
        {
          "name": "string",
          "type": "string"
        }
      ],
      "Order": [
        {
          "name": "string",
          "type": "string"
        }
      ]
    },
    "primaryType": "string",
    "domain": "object",
    "message": "object"
  }
}

Receives signed order and pushes it to matching engine

POST /orders/sign
Request Example
{
  "formedOrderId": "string",
  "signature": "string"
}

Created

401 Unauthorized

Unauthorized

403 Forbidden

Forbidden

404 Not Found

Not found

409 Conflict

Conflict

412 Precondition Failed

Precondition Failed

422 Unprocessable Entity

Unprocessable entity

429 Too Many Requests

Too many requests

Response Example (201 Created)
{
  "orderId": "string"
}

Cancels orders by specified ids

PUT /orders/cancel
orderIds: string[]
in query

An array of order ids to cancel

202 Accepted

Accepted

401 Unauthorized

Unauthorized

403 Forbidden

Forbidden

404 Not Found

Not found

422 Unprocessable Entity

Unprocessable entity

Schema Definitions

GetAuthLoginDataResponse: object

ttl: number
data: object
types: object
EIP712Domain: object[]
object
name: string
type: string
Login: object[]
object
name: string
type: string
primaryType: string
domain: object
message: object
Example
{
  "ttl": "number",
  "data": {
    "types": {
      "EIP712Domain": [
        {
          "name": "string",
          "type": "string"
        }
      ],
      "Login": [
        {
          "name": "string",
          "type": "string"
        }
      ]
    },
    "primaryType": "string",
    "domain": "object",
    "message": "object"
  }
}

GetProductsResponse: array

object
productId: string
title: string
token: string
type: string COMPOUND
subtype: string SUPPLY, BORROW
margin: number
fixedRateSupported: boolean
Example
[
  {
    "productId": "string",
    "title": "string",
    "token": "string",
    "type": "string",
    "subtype": "string",
    "margin": "number",
    "fixedRateSupported": "boolean"
  }
]

GetMetaConfigResponse: object

networkId: number
defaults: object
productId: string
supportedTokens: object[]
object
title: string
address: string
decimals: number
opiumContracts: object
TokenSpender: string
CompoundSupplyAggregator: string
supportedMaturities: number[]
number

UNIX timestamp of supported maturities in seconds

Example
{
  "networkId": "number",
  "defaults": {
    "productId": "string"
  },
  "supportedTokens": [
    {
      "title": "string",
      "address": "string",
      "decimals": "number"
    }
  ],
  "opiumContracts": {
    "TokenSpender": "string",
    "CompoundSupplyAggregator": "string"
  },
  "supportedMaturities": [
    "number"
  ]
}

PostOrdersFormRequestBody: object

productId: string
pay: object
type: string FIXED, FLOATING

pay.type and receive.type are mutually exclusive

rate: number

Only considered if type = FIXED

receive: object
type: string FIXED, FLOATING

pay.type and receive.type are mutually exclusive

rate: number

Only considered if type = FIXED

nominal: number
maturity: number

UNIX timestamp of one of supported maturities in seconds

partialFill: boolean
aggregate: string NONE, FIXED_RATE_COMPOUND NONE
Example
{
  "productId": "string",
  "pay": {
    "type": "string",
    "rate": "number"
  },
  "receive": {
    "type": "string",
    "rate": "number"
  },
  "nominal": "number",
  "maturity": "number",
  "partialFill": "boolean",
  "aggregate": "string"
}

PostOrdersFormResponseBody: object

formedOrderId: string
orderToSign: object
types: object
EIP712Domain: object[]
object
name: string
type: string
Order: object[]
object
name: string
type: string
primaryType: string
domain: object
message: object
Example
{
  "formedOrderId": "string",
  "orderToSign": {
    "types": {
      "EIP712Domain": [
        {
          "name": "string",
          "type": "string"
        }
      ],
      "Order": [
        {
          "name": "string",
          "type": "string"
        }
      ]
    },
    "primaryType": "string",
    "domain": "object",
    "message": "object"
  }
}

PostOrdersSignRequestBody: object

formedOrderId: string
signature: string
Example
{
  "formedOrderId": "string",
  "signature": "string"
}

PostOrdersSignResponseBody: object

orderId: string
Example
{
  "orderId": "string"
}

GetWalletBalanceResponse: object

eth: number
tokens: object[]
object
title: string
total: number
allowance: number
compoundSupplyAllowance: number
Example
{
  "eth": "number",
  "tokens": [
    {
      "title": "string",
      "total": "number",
      "allowance": "number",
      "compoundSupplyAllowance": "number"
    }
  ]
}

OrderQuoteResponseBody: object

fixedRate: number

Necessary for instant match fixedRate

Example
{
  "fixedRate": "number"
}