Links

Web Socket Streams

General WSS information

  • The base endpoint is: wss://open-api.openocean.finance/socket

Live Subscribing to streams

  • The following data can be sent through the websocket instance in order to subscribe from streams. Examples can be seen below.

quote

  • params:
    parameter
    type
    example
    description
    chain
    string
    bsc
    bsc, eth, polygon, fantom, avax, heco, okex, xdai, arbitrum, optimism, moonriver, boba, ont, tron, solana, terra
    inTokenAddress
    string
    0x783C08b5F26E3daf8C4681F3bf49844e425b6393
    token address
    outTokenAddress
    string
    0xD81D45E7635400dDD9c028839e9a9eF479006B28
    out token address
    amount
    string
    5
    token amount(without decimals)
    gasPrice
    string
    5
    without decimals
    second
    number
    4000
    default 3000 = 3s
  • Request
    {
    chain: 'bsc',
    inTokenAddress: '0x0782b6d8c4551B9760e74c0545a9bCD90bdc41E5',
    outTokenAddress: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
    amount: 100,
    gasPrice: 3
    }
  • Response
    {
    "code": 200,
    "data": {
    "inToken": {
    "symbol": "AUSD",
    "name": "Avaware USD",
    "address": "0x783C08b5F26E3daf8C4681F3bf49844e425b6393",
    "decimals": 18
    },
    "outToken": {
    "symbol": "EMBR",
    "name": "EmbrToken",
    "address": "0xD81D45E7635400dDD9c028839e9a9eF479006B28",
    "decimals": 18
    },
    "inAmount": "5000000000000000000",
    "outAmount": "126261357830302882735",
    "estimatedGas": "189669",
    "dexes": [
    {
    "dexIndex": 1,
    "dexCode": "SushiSwap",
    "swapAmount": "0"
    },
    ...
    ],
    "path": {
    }
    },
    "params": {
    "monitorId": "/socket#qGxi0-p3kmDJskQoAAAAla0i7bpy"
    }
    }

getTransaction

  • params:
parameter
type
example
description
chain
string
bsc
bsc, eth, polygon, fantom, avax, heco, okex, xdai, arbitrum, optimism, moonriver, boba, ont, tron, solana, terra
hash
string
​
transaction hash
second
number
4000
default 3000 = 3s
  • Request:
{
chain: 'bsc',
hash: '0x14922a6ca4994a8b44b3c058d38ab96b006c051d4797845511f4c87cac9074f1'
}
  • Response:
    {
    "code": 200,
    "data": {
    "id": 25144,
    "tx_id": null,
    "block_number": 12091885,
    "tx_index": 8,
    "address": "0x6352a56caadC4F1E25CD6c75970Fa768A3304e64",
    "tx_hash": "0x57e752d311c347008a5d66286096b62d6a0687834a3df8b0dd06265ff16ee575",
    "sender": "0x7fFadA80929a732f93D648D92cc4E052e2b9C4Aa",
    "in_token_address": "0x0000000000000000000000000000000000000000",
    "in_token_symbol": "AVAX",
    "out_token_address": "0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664",
    "out_token_symbol": "USDC.e",
    "referrer": "0x40603469C577B1Db3D401155901A276F604436f4",
    "in_amount": "1400000000000000000",
    "out_amount": "97659580",
    "fee": "",
    "referrer_fee": "",
    "usd_valuation": 97.38,
    "create_at": "2022-03-14T08:39:18.000Z",
    "update_at": "2022-03-14T08:39:18.000Z",
    "tx_fee": "0.010181825",
    "tx_fee_valuation": "0.72993503",
    "in_token_decimals": 18,
    "out_token_decimals": 6,
    "in_amount_value": "1.4",
    "out_amount_value": "97.65958"
    },
    "params": {
    "monitorId": "/socket#qGxi0-p3kmDJskQoAAAAla0i7bpy"
    }
    }

getGasPrice

  • params:
    parameter
    type
    example
    description
    chain
    string
    bsc
    bsc, eth, polygon, fantom, avax, heco, okex, xdai, arbitrum, optimism, moonriver, boba, ont, tron, solana, terra
    second
    number?
    4000
    default 3000 = 3s
  • Request
    {
    chain: 'bsc'
    }
  • Response
    {"code":200,"data":{"standard":5000000000,"fast":5000000000,"instant":5000000000},
    "params": {
    "monitorId": "/socket#qGxi0-p3kmDJskQoAAAAla0i7bpy"
    }}

unsubscribe

  • params:
    parameter
    type
    example
    description
    monitorId
    string
    /socket#qGxi0-p3kmDJskQoAAAAla0i7bpy
    ​
  • Request
    {
    monitorId: '/socket#qGxi0-p3kmDJskQoAAAAla0i7bpy'
    }
  • code example: NodeJS
recommended version: socket.io-client 2.0
const socket = require('socket.io-client')('wss://open-api.openocean.finance/socket');
​
socket.on('connect', () => {
console.log('connect!');
});
​
const quoteData = {
chain: 'bsc',
inTokenAddress: '0x0782b6d8c4551B9760e74c0545a9bCD90bdc41E5',
outTokenAddress: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
amount: '100',
second: 4000
};
socket.emit('quote', quoteData);
socket.on('quote_result', msg => {
console.log('quote_result-----------: %s!',JSON.stringify(msg));
});
​
const gaspriceData = {chain: 'bsc'};
socket.emit('getGasPrice', gaspriceData);
socket.on('getGasPrice_result', msg => {
​
console.log('getGasPrice_result-----------: %s!',JSON.stringify(msg));
});
​
const txData = {chain: 'avax', second: 4000, hash: '0x57e752d311c347008a5d66286096b62d6a0687834a3df8b0dd06265ff16ee575'};
socket.emit('getTransaction', txData);
socket.on('getTransaction_result', msg => {
​
console.log('getTransaction_result-----------: %s!',JSON.stringify(msg));
});
​
const unsubscribeData = {monitorId: '/socket#UUSOYaJT4lZAl6-AAAABla0ihim2'};
socket.emit('unsubscribe', unsubscribeData);