How to get real-time Crypto Data With Websockets
Mobula's Crypto Data API now provides websocket streaming for trades, pair data, wallet data, price feed, sourced directly from Octopus for accurate real-time data.
The API emphasizes efficient data transmission and detailed documentation for user guidance on connections, data handling, and error management. Explore more on Mobula's documentation page.
Check out our Documentation
Connection
URL
To access real-time data use this URL:
wss://general-api-wss-fgpupeioaa-uc.a.run.app
Octopus
Mobula websockets are now powered by Octopus (the most advanced pricing engine in the industry, offering the largest coverage, the highest accuracy, the lowest latency, and the most cost-efficient pricing)
Check out our open-source benchmark vs CoinMarketCap, CoinGecko, CoincAp, CoinLayer & Moralis.
Communication Flow
The process of communication involves two distinct stages: setting up the connection and then receiving data.
Establishment
To initiate the connection, prepare your message as follows for each endpoint:
- "type": "market", "pair", "wallet"
- "authorization": "MOBULA-API-KEY"
- "payload": "assets": ... (every params you need)
{
"type": "market",
"authorization": "MOBULA-API-KEY",
"payload": {
"assets": [
{ "name": "Bitcoin" },
{
"address": "0x059fd118aa8988f5e97b66fcd489765111e069c9",
"blockchain": "1"
}
],
"interval": 15
}
}
Please note that only Growth and Enterprise plan users can access websockets.
If you provided incorrect credentials you will receive:
{"error":"Invalid auth provided","details":"Please provide valid authorization (read more at docs.mobula.io)"}
Receiving Data
You are now set up to access real-time data on the crypto market!
Submit one or more subscription requests (detailed further on) to start receiving specific data upon confirmation.
For detailed formats of responses and additional insights on websockets, refer to our Documentation.
Client To Server
Authentication
To authenticate correctly, you'll need to setup "authorization" in the message with your api key
"authorization": "MOBULA-API-KEY"
Subscribe
You have the option to subscribe to market
, pair
, and wallet
data for a chosen crypto asset, pair, or wallet. A subscription message needs to specify any new subscriptions to be added, without resending those already active in your session.
{
"type": "pair",
"authorization": "MOBULA-API-KEY",
"payload": {
"address": "0x059fd118aa8988f5e97b66fcd489765111e069c9",
"blockchain": "1"
}
}
Responses
Data points delivered in each server message come in various formats, based on their specific type.
Market
{
"data": {
"CryptoAI": {
"market_cap": 941482,
"market_cap_diluted": 941527,
"liquidity": 68835,
"price": 0.009415273355767471,
"off_chain_volume": 87328,
"volume": 661,
"volume_change_24h": -78.64297485351562,
"volume_7d": 924,
"is_listed": true,
"price_change_24h": 7.7392178,
"price_change_1h": -0.5816689,
"price_change_7d": 30.734856,
"price_change_1m": 38.9072,
"price_change_1y": -82.66283,
"ath": 0.10028909307846398,
"atl": 4.45132284454043e-15,
"rank": 3185,
"logo": "https://metacore.mobula.io/38cca4128883ec20d57420114db385fc40de493b876c9df21d4a97824012cbaf.png",
"name": "CryptoAI",
"symbol": "CAI",
"contracts": [
{
"address": "0xf36c5f04127f7470834ed6f98bddc1be62aba48d",
"blockchain": "Ethereum",
"blockchainId": "1",
"decimals": 18
}
]
}
}
}
Pair
Pair updates
{
data: {
price: number,
priceUSD: number,
pair: string,
}
}
Trades updates
{
{
blockchain: string,
date: number // timestamp MS,
hash: string,
token_amount: number,
token_amount_usd: number,
token_price: number,
token_price_vs: number,
type: 'buy' | 'sell',
}
}
Wallet
{
"data": {
"total_wallet_balance": 0.011641190461236009,
"wallet": "0x53af17ff236c7d438bd6babd8eb369246ec279f9",
"wallets": [
"0x53af17ff236c7d438bd6babd8eb369246ec279f9"
],
"total_realized_pnl": -7.566,
"total_unrealized_pnl": 8.448500000000001,
"assets": [
{
"asset": {
"name": "StaySAFU",
"symbol": "SAFU",
"id": "3",
"contracts": [
"0x890cc7d14948478c98a6cd7f511e1f7f7f99f397"
],
"logo": "https://metacore.mobula.io/4ed4daf3f124fae650cfab146ae7348cdb62920bc25bf6408698654835192a1b.png"
},
"realized_pnl": 3.2941,
"unrealized_pnl": -0.1535,
"allocation": 100,
"price": 2.686500690188377,
"price_bought": 38.103328861521184,
"total_invested": 16.511,
"min_buy_price": 38.103328861521184,
"max_buy_price": 38.103328861521184,
"estimated_balance": 0.011641190461236009,
"token_balance": 0.004333217,
"cross_chain_balances": {
"BNB Smart Chain (BEP20)": {
"balance": 0.004333217,
"balanceRaw": "4333217",
"chainId": "56",
"address": "0x890cc7d14948478c98a6cd7f511e1f7f7f99f397"
}
},
"contracts_balances": [
{
"balance": 0.004333217,
"balanceRaw": "4333217",
"chainId": "56",
"address": "0x890cc7d14948478c98a6cd7f511e1f7f7f99f397",
"decimals": 9
}
]
},
{
"asset": {
"name": "BNB",
"symbol": "BNB",
"id": "100001566",
"contracts": [
"0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
"0xdff772186ace9b5513fb46d7b05b36efa0a4a20d",
"0xb8c77482e45f1f44de1745f52c74426c631bdd52"
],
"logo": "https://metacore.mobula.io/4222eebc08140e722f50099fc8322b28e7c52e1abb92897e716cb2dc89598634.png"
},
"realized_pnl": -10.8599,
"unrealized_pnl": -0.0343,
"allocation": 0,
"price": 564.3032984652975,
"price_bought": 579.442048614297,
"total_invested": 145.24699999999999,
"min_buy_price": 530.9561680794088,
"max_buy_price": 606,
"estimated_balance": 0,
"token_balance": 0,
"cross_chain_balances": {},
"contracts_balances": [
{
"balance": 0,
"balanceRaw": "0",
"chainId": "56",
"address": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"decimals": 18
}
]
},
{
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"id": "100004304",
"contracts": [
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1",
"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",
"0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab",
"0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
"0x2def4285787d58a2f811af24755a8150622f4361",
"0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000",
"0xe44fd7fcb2b1581822d0c862b68222998a0c299a",
"0x2170ed0880ac9a755fd29b2688956bd959f933f8",
"0xc9bdeed33cd01541e1eed10f90519d2c06fe3feb",
"0x639a647fbe20b6c8ac19e48e2de44ea792c62c5c",
"0x3674d64aab971ab974b2035667a4b3d09b5ec2b3",
"0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000",
"0x4200000000000000000000000000000000000006",
"0xdeaddeaddeaddeaddeaddeaddeaddeaddead1111",
"0x4200000000000000000000000000000000000006",
"0x5aea5775959fbc2557cc8789bc1bf90a239d9a91",
"0x0dc808adce2099a9f62aa87d9670745aba741746",
"0x5300000000000000000000000000000000000004",
"0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f",
"0x4f9a0e7fd2bf6067db6994cf12e4495df938e6e9",
"0xc20bfb46f637f688353eea8dc27cf23668c703d2",
"vP6XSUyjmgWCB2B9tD5Rqun56WJqDdExWnfwZVEqzhQb",
"0x4300000000000000000000000000000000000004",
"0x4200000000000000000000000000000000000006"
],
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png"
},
"realized_pnl": -0.0002,
"unrealized_pnl": 8.6363,
"allocation": 0,
"price": 3557.467630588482,
"price_bought": 1546.3934426229507,
"total_invested": 75.464,
"min_buy_price": 1546.3934426229507,
"max_buy_price": 1546.3934426229507,
"estimated_balance": 0,
"token_balance": 0,
"cross_chain_balances": {
"Ethereum": {
"balance": 1e-17,
"balanceRaw": "10",
"chainId": "1",
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
}
},
"contracts_balances": [
{
"balance": 1e-17,
"balanceRaw": "10",
"chainId": "1",
"address": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"decimals": 18
}
]
}
]
}
}