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
Authentication
Returns login parameters and login message to sign in EIP712
format
Ok
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
Ok
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
Ok
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
ID of the product to get the quote from
UNIX timestamp of one of supported maturities in seconds
Nominal of quoting order
OK
Not found
Unprocessable entity
Too many requests
Response Example (200 OK)
{
"fixedRate": "number"
}
Wallet
Returns object with user's token balances and allowances
Ok
Unauthorized
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
undefined
Request Example
{
"productId": "string",
"pay": {
"type": "string",
"rate": "number"
},
"receive": {
"type": "string",
"rate": "number"
},
"nominal": "number",
"maturity": "number",
"partialFill": "boolean",
"aggregate": "string"
}
OK
Unauthorized
Forbidden
Not found
Precondition Failed
Unprocessable entity
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
undefined
Request Example
{
"formedOrderId": "string",
"signature": "string"
}
Created
Unauthorized
Forbidden
Not found
Conflict
Precondition Failed
Unprocessable entity
Too many requests
Response Example (201 Created)
{
"orderId": "string"
}
Cancels orders by specified ids
An array of order ids to cancel
Accepted
Unauthorized
Forbidden
Not found
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
- 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
andreceive.type
are mutually exclusive - rate: number
-
Only considered if
type = FIXED
- receive: object
-
- type: string FIXED, FLOATING
-
pay.type
andreceive.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"
}
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"
}
]
}