🖥️Lighter API

API endpoints to retrieve information about order books.

*Every request requires a valid API_KEY in AUTH param in the HTTP header.

You can request an API Key by filling out this form.

The easiest way to interact with the API is to use the Lighter Python client. You can find example client codes to see how to use API with the client.

Get Supported Blockchains

Endpoint

GET api/v2/blockchains

Description

This endpoint is used to retrieve information on all blockchains in the database.

Response

Blockchain

Reserve

Example Response data

[
    {
        "chain_id": "42161",
        "chain_name": "arbitrum",
        "block_explorer_url": "https://arbiscan.io",
        "native_currency_symbol": "ETH",
        "native_currency_name": "Ether",
        "native_currency_decimals": 18,
        "rpc_url": "https://arb1.arbitrum.io/rpc",
        "router_address": "0x86D4Ef07492605D30124E25B1E08E3C489D39807",
        "factory_address": "0xDa66c2ADFAF2c524283Ff9e72Ef7702a254C9127",
        "reserves": {
            "0x0000000000000000000000000000000000000000": {
                "symbol": "ETH",
                "decimals": 18,
                "pow_decimals": 1000000000000000000,
                "name": "Ether"
            },
            "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1": {
                "symbol": "WETH",
                "decimals": 18,
                "pow_decimals": 1000000000000000000,
                "name": "Wrapped Ether"
            },
            "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8": {
                "symbol": "USDC.e",
                "decimals": 6,
                "pow_decimals": 1000000,
                "name": ""
            },
            "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9": {
                "symbol": "USDT",
                "decimals": 6,
                "pow_decimals": 1000000,
                "name": ""
            },
            "0xaf88d065e77c8cC2239327C5EDb3A432268e5831": {
                "symbol": "USDC",
                "decimals": 6,
                "pow_decimals": 1000000,
                "name": "USD Coin"
            }
        }
    }
]

Python

import os

from lighter.lighter_client import Client

api_auth = os.environ.get("API_KEY")
web3_url = os.environ.get("WEB3_URL")

client = Client(
    api_auth=api_auth,
    web3_provider_url=web3_url,
)

blockchains = client.api.get_blockchains()

Get Supported Order books

Endpoint

GET api/v2/order_book_metas

Description

This endpoint is used to retrieve information on all supported order books in a specific blockchain. It contains detailed information about order books.

Request

Response

OrderbookMeta

Candlestick

Example Response Data

[
    {
        "id": 0,
        "blockchain_id": 42161,
        "address": "0xB8Df652Ccb5CB39Ac1cD98a899639F8463B103a8",
        "symbol": "WETH-USDC",
        "token0_symbol": "WETH",
        "token0_name": "Wrapped Ether",
        "token0_address": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
        "token1_symbol": "USDC",
        "token1_name": "USD Coin (Arb1)",
        "token1_address": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
        "pow_size_tick": 100000000000000,
        "pow_price_tick": 10000,
        "size_tick": 14,
        "price_tick": 4,
        "week_candlesticks": [
            {
                "timestamp": 1686873600,
                "open": 1664.95,
                "close": 1716.89,
                "high": 1726.96,
                "low": 1649.74,
                "volume0": 8090.1223,
                "volume1": 13567339.200085
            },
        ],
        "day_high": "1931.32",
        "day_low": "1371.00",
        "day_change": 5.472315579764136,
        "day_volume0": "2280.6288",
        "day_volume1": "4268345.2353",
        "day_trade_count": 6,
        "size_decimals": 4,
        "price_decimals": 2,
        "last_price": "1911.19",
        "mid_price": "10000.00",
        "min_token0_base_amount": 10000,
        "min_token1_base_amount": 10000000000
    }
]

Python

import os

from lighter.lighter_client import Client

api_auth = os.environ.get("API_KEY")
web3_url = os.environ.get("WEB3_URL")

client = Client(
    api_auth=api_auth,
    web3_provider_url=web3_url,
)

# the blockchain id comes from the given web3 provider url
orderbook_meta = client.api.get_orderbook_meta()

Get Trades

Endpoint

GET api/v2/trades

Description

This endpoint is used to retrieve trade data for a specific order book on a specific blockchain.

Required Parameters

Optional Parameters

Response Data

TradeResponse

Example Response

[
    {
        "side": "buy",
        "price": 1565.45,
        "amount": 0.1497,
        "timestamp": "2023-03-06T21:40:11Z",
        "maker_address": "0x5bC5BA9A7CEF3f44C512a75e146c1e542Cf494b5",
        "taker_address": "0x5bC5BA9A7CEF3f44C512a75e146c1e542Cf494b5",
        "ask_id": 2459,
        "bid_id": 2412
    },
    {
        "side": "buy",
        "price": 1565.47,
        "amount": 0.1293,
        "timestamp": "2023-03-06T21:39:56Z",
        "maker_address": "0x5bC5BA9A7CEF3f44C512a75e146c1e542Cf494b5",
        "taker_address": "0x5bC5BA9A7CEF3f44C512a75e146c1e542Cf494b5",
        "ask_id": 2455,
        "bid_id": 2410
    },
]

Python

import os

from lighter.lighter_client import Client
from lighter.constants import ORDERBOOK_WETH_USDC

api_auth = os.environ.get("API_KEY")
web3_url = os.environ.get("WEB3_URL")

client = Client(
    api_auth=api_auth,
    web3_provider_url=web3_url,
)

trades = client.api.get_trades(orderbook_symbol=ORDERBOOK_WETH_USDC)

Get Candlestick data

Endpoint

GET api/v2/candlesticks

Description

This endpoint is used to retrieve candlestick data for a specific order book on a specific blockchain.

Required Parameters

Optional Parameters

Response Data

CandlestickResponse

Example Response

{
    "candlesticks": [
        {
            "timestamp": 1609276939,
            "open": 10.0,
            "high": 11.0,
            "low": 9.0,
            "close": 9.5,
            "volume0": 100.0,
            "volume1": 50.0
        },
        {
            "timestamp": 1609276940,
            "open": 9.5,
            "high": 10.0,
            "low": 8.5,
            "close": 9.0,
            "volume0": 75.0,
            "volume1": 25.0
        }
    ],
    "resolution": "4h",
}

Python

import os

from lighter.lighter_client import Client
from lighter.constants import ORDERBOOK_WETH_USDC

api_auth = os.environ.get("API_KEY")
web3_url = os.environ.get("WEB3_URL")

client = Client(
    api_auth=api_auth,
    web3_provider_url=web3_url,
)

candlesticks = client.api.get_candles(
    orderbook_symbol=ORDERBOOK_WETH_USDC,
    timestamp_start=1687097397,
    timestamp_end=1687183683,
    resolution="4h",
)

Get Orders

Endpoint

GET api/v2/orders

Description

This endpoint allows a user to retrieve a list of orders for a specific order book.

Required parameters

Optional Parameters:

Response data

OrderResponse Data:

Example response

[
    {
        "id": 1448632,
        "price": 1910.44,
        "size": 2.45,
        "filled_amount": 0,
        "timestamp": 1687430216,
        "type": "limit",
        "status": "cancelled",
        "side": "buy"
    },
    {
        "id": 1448630,
        "price": 1910.8,
        "size": 2.1852,
        "filled_amount": 0,
        "timestamp": 1687430216,
        "type": "limit",
        "status": "cancelled",
        "side": "sell"
    }
]

Python

import os

from lighter.lighter_client import Client
from lighter.constants import ORDERBOOK_WETH_USDC

TEST_OWNER_ADDRESS = "0xE425f4Dfe8b2446b686b2C5a7c17679b7170996e"

api_auth = os.environ.get("API_KEY")
web3_url = os.environ.get("WEB3_URL")

client = Client(
    api_auth=api_auth,
    web3_provider_url=web3_url,
)

orders = client.api.get_orders(
    orderbook_symbol=ORDERBOOK_WETH_USDC, owner=TEST_OWNER_ADDRESS
)

Get Gas Price

Endpoint

GET api/v2/gas_price

Description

This endpoint allows a user to retrieve the current gas price of a given blockchain.

Required parameters

Response data

Example response

{
    "gas_price": 100000000
}

Python

import os

from lighter.lighter_client import Client

api_auth = os.environ.get("API_KEY")
web3_url = os.environ.get("WEB3_URL")

client = Client(
    api_auth=api_auth,
    web3_provider_url=web3_url,
)

gas_price = client.api.get_gas_price()

Get Hint IDs

Endpoint

GET api/v2/hint_id

Description

This endpoint allows a user to retrieve the order IDs for a given price and sides.

Required parameters

Response data

Example response

{
    "hint_ids": [
        1448733,
        1448770
    ]
}

Websocket API

Websocket API is available on wss://api.lighter.xyz/v2/stream which can be used for listening to the following streams, each stream sends a confirmation message on a successful subscription following messages will be updated messages. Each subscription request needs to be in JSON format with the following properties included type: "subscribe", auth: "auth_token" (Market Maker only) and channel: <stream_name/chain_id:orderbook_symbol>.

Notice confirmation responses have type: subscribed/stream_name and channel: <blockchain_id:orderbook_symbol> properties in common other properties depends on the stream.

Orderbook Channel

Subscription Request

{
    "type": "subscribe",
    "channel": "order_book/421613:WETH-USDC",
    "auth": "xxxx", (MM only)
 }

Confirmation Message

{
    "channel": "421613:WETH-USDC",
    "order_book": {
        "asks": [
            {"price": "1232.0", "size": "4.711"},
            {"price": "1236.9", "size": "4.596"}
        ],
        "bids": [
            {"price": "1217.56", "size": "3.286"},
            {"price": "1216.34", "size": "2.007"}
        ],
    }
    "type": "subscribed/order_book",
}

Update Message

It overwrites the order at the given price.

{
    "channel": "421613:WETH-USDC",
    "orders": {"asks": [], "bids": [{"price": "1232.0", "size": "0.0"}]},
    "type": "update/order_book",
}

Trade Channel

Subscription Request

{
    "type": "subscribe",
    "channel": "trade/421613:WETH-USDC",
    "auth": "xxxx" (MM only)
 }

Confirmation Message

{
    "owner": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48", # included since we sent a filter
    "trades": [
        {
            "ask_id": 1384,
            "bid_id": 1429,
            "maker_address": "0xF1658AE20F8da53e9D052eA29b2DEF433cDBbB92",
            "taker_address": "0xF1658AE20F8da53e9D052eA29b2DEF433cDBbB92",
            "price": "1649.48",
            "side": "buy",
            "size": "1.0",
            "timestamp": 1675947491,
            "tx_hash": "0xf8ebbed51b795fb09e3daf582444d0774b21c751a1b999a06aaa6b8805a5f759"
	}
    ],
    "type": "subscribed/trade",
}

Update Message

{
    "channel": "421613:WETH-USDC",
    "owner": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
    "trades": [
        {
            "size": 0.0001,
            "maker_address": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
            "price": 1232.0,
            "side": "buy",
            "ask_id": 1,
            "bid_id": 2,
            "taker_address": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
            "timestamp": 1673445801,
            "tx_hash": "0xf8ebbed51b795fb09e3daf582444d0774b21c751a1b999a06aaa6b8805a5f759"
        }
    ],
    "type": "update/trade",
}

Account Channel

Subscription Request

{
    "type": "subscribe",
    "channel": "account/421613:WETH-USDC",
    "auth": "xxxx", (MM only)
    "account": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
}

Confirmation Message

{
    "account": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
    "channel": "421613:WETH-USDC",
    "orders": [
        {
	    "fillable_size": "1.4647",
	    "filled_size": "0.0",
	    "id": 630,
	    "initial_size": "1.4647",
	    "owner": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
            "price": "1206.55",
	    "side": "buy",
            "status": "PARTIALLY_FILLED"
	}
    ],
    "trades": [
        {
            "ask_id": 1384,
            "bid_id": 1425,
            "maker_address": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
            "price": "1649.48",
            "side": "buy",
            "size": "0.0001",
            "taker_address": "0xF1658AE20F8da53e9D052eA29b2DEF433cDBbB92",
            "timestamp": 1675895319,
            "tx_hash": "0xc446d5af0bc38acfbb14e4af27decfb81b037d2711bec1272d801ada019abff3"
	}
    ],
    "type": "subscribed/account",
}

Update Message

{
    "account": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
    "balance": {
            "WETH_unlocked": "12.2351531",
            "WETH_locked": "132.314314",
            "USDC_unlocked": "124134314.13413",
            "USDC_locked": "134234234.13413",
    },
    "channel": "421613:WETH-USDC",
    "orders": [
        {
            "fillable_size": "0.0001",
            "filled_size": "0.0",
            "id": 1438,
            "initial_size": "0.0001",
            "owner": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
            "price": "1649.48",
            "side": "buy",
            "status": "PARTIALLY_FILLED"
	}
    ],
    "trades": [
        {
	    "ask_id": 1384,
	    "bid_id": 1438,
	    "maker_address": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
    	    "taker_address": "0xF1658AE20F8da53e9D052eA29b2DEF433cDBbB92",
	    "price": "1649.48",
	    "side": "buy",
	    "size": "0.0001",
	    "timestamp": 1676022193,
	    "tx_hash": "0x3ca49c12b2053aee3d742330b9a3e59ba303c4460e04e8c59d75e7051b1bae35"
	}
    ],
    "type": "update/account",
}

User Stats Channel

Subscription Request

{
    "type": "subscribe",
    "channel": "user_stats/421613",
    "account": "0xaa25881ec80d252E87Ade9275AaE4183b83F9581"
}

Confirmation Message

{
  "account": "0xaa25881ec80d252E87Ade9275AaE4183b83F9581",
  "channel": "user_stats:421613:",
  "type": "subscribed/user_stats",
  "user_stats": {
    "blockchain_id": 421613,
    "address": "0xaa25881ec80d252E87Ade9275AaE4183b83F9581",
    "user_stats": [
      {
        "pair": "USDC-USDC.e",
        "base_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "WBTC-USDC.e",
        "base_token_address": "0xF133Eb356537F0B3B4fDfB98233b45Ef8138aA56",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "open_position_base": 100000,
        "open_position_quote": 99999.99915804001,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      }
    ]
  }
}

Update Message

{
  "account": "0xaa25881ec80d252E87Ade9275AaE4183b83F9581",
  "channel": "user_stats:421613:",
  "type": "update/user_stats",
  "user_stats": {
    "blockchain_id": 421613,
    "address": "0xaa25881ec80d252E87Ade9275AaE4183b83F9581",
    "user_stats": [
      {
        "pair": "USDC-USDC.e",
        "base_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "WBTC-USDC.e",
        "base_token_address": "0xF133Eb356537F0B3B4fDfB98233b45Ef8138aA56",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "open_position_base": 100000,
        "open_position_quote": 99999.99915804001,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "open_position_base": 0,
        "open_position_quote": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "24h_trades_count": 0
      }
    ]
  }
}

Market Stats Channel

Subscription Request

{
    "type": "subscribe",
    "channel": "market_stats/421613"
}

Confirmation Message

{
  "channel": "market_stats:421613:",
  "market_stats": {
    "blockchain_id": 421613,
    "market_stats": [
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "price": 0,
        "price_decimals": 6,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 0,
        "total_open_position_quote": 0
      },
      {
        "pair": "WBTC-USDC.e",
        "base_token_address": "0xF133Eb356537F0B3B4fDfB98233b45Ef8138aA56",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "price": 25000,
        "price_decimals": 1,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 0.999,
        "total_open_position_quote": 17957.998
      },
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "price": 1,
        "price_decimals": 6,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 100000,
        "total_open_position_quote": 99999.99915804001
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "price": 1540.9100341796875,
        "price_decimals": 2,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 102.89999999999999,
        "total_open_position_quote": 92210.92
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "price": 1544.3800048828125,
        "price_decimals": 2,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 12,
        "total_open_position_quote": 0
      },
      {
        "pair": "USDC-USDC.e",
        "base_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "price": 1,
        "price_decimals": 6,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 2,
        "24h_volume_base": 10100,
        "24h_volume_quote": 100100,
        "total_open_position_base": 30000,
        "total_open_position_quote": 29999.85
      }
    ]
  },
  "type": "subscribed/market_stats"
}

Update Message

{
  "channel": "market_stats:421613:",
  "market_stats": {
    "blockchain_id": 421613,
    "market_stats": [
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "price": 0,
        "price_decimals": 6,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 0,
        "total_open_position_quote": 0
      },
      {
        "pair": "WBTC-USDC.e",
        "base_token_address": "0xF133Eb356537F0B3B4fDfB98233b45Ef8138aA56",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "price": 25000,
        "price_decimals": 1,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 0.999,
        "total_open_position_quote": 17957.998
      },
      {
        "pair": "USDT-USDC.e",
        "base_token_address": "0x03fc54FD8572B76b6F4f5177A016Bac11688Fc5F",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "price": 1,
        "price_decimals": 6,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 100000,
        "total_open_position_quote": 99999.99915804001
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "price": 1540.9100341796875,
        "price_decimals": 2,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 102.89999999999999,
        "total_open_position_quote": 92210.92
      },
      {
        "pair": "WETH-USDC.e",
        "base_token_address": "0x4d541F0B8039643783492F9865C7f7de4F54eB5f",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "price": 1544.3800048828125,
        "price_decimals": 2,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 0,
        "24h_volume_base": 0,
        "24h_volume_quote": 0,
        "total_open_position_base": 12,
        "total_open_position_quote": 0
      },
      {
        "pair": "USDC-USDC.e",
        "base_token_address": "0xcC4a8FA63cE5C6a7f4A7A3D2EbCb738ddcD31209",
        "quote_token_address": "0x6170DAebf32cC9D3E1aFF987895dA7d19c8Db16C",
        "price": 1,
        "price_decimals": 6,
        "24h_chart": [],
        "24h_price_change": 0,
        "24h_trades_count": 2,
        "24h_volume_base": 10100,
        "24h_volume_quote": 100100,
        "total_open_position_base": 30000,
        "total_open_position_quote": 29999.85
      }
    ]
  },
  "type": "update/market_stats"
}

Sample Websocket Connection Code

Note following is a sample code, not intented to run in a production environment.
import asyncio
import websockets
import json
from pprint import pprint


async def subscribe_to_orderbook(ws, auth):
    req = {
        "type": "subscribe",
        "channel": "order_book/421613:WETH-USDC",
        "auth": auth,
        "topK": 10
    }
    await ws.send(json.dumps(req))
    confirmation = json.loads(await ws.recv())
    print(">>> Sent orderbook subscription req")
    pprint(req)
    print("<<< Received orderbook subscription confirmation")
    pprint(confirmation)
    print("===\n\n")


async def subscribe_to_account(ws, auth):
    req = {
        "type": "subscribe",
        "channel": "account/421613:WETH-USDC",
        "auth": auth,
        "account": "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48",
    }
    await ws.send(json.dumps(req))
    confirmation = json.loads(await ws.recv())
    print(">>> Sent account subscription req")
    pprint(req)
    print("<<< Received account subscription confirmation")
    pprint(confirmation)
    
    print("===\n\n")


async def subscribe_to_trades(ws, auth, owner_filter):
    req = {
        "type": "subscribe",
        "channel": "trade/421613:WETH-USDC",
        "auth": auth,
    }
    await ws.send(json.dumps(req))
    confirmation = json.loads(await ws.recv())
    print(">>> Sent trades subscription req")
    pprint(req)
    print("<<< Received trades subscription confirmation")
    pprint(confirmation)
   
    print("===\n\n")


async def listen_for_updates(ws):
    async for msg in ws:
        pprint(json.loads(msg))
        print("======\n\n")


async def connect():
    auth = "XXXXXXXXX"
    lighter_ws_url = "XXXXXXXXXX"
    async with websockets.connect(lighter_ws_url) as websocket:
        await subscribe_to_orderbook(websocket, auth)
        await subscribe_to_account(websocket, auth)
        await subscribe_to_trades(
            websocket, auth, "0xd057E08695d1843FC21F27bBd0Af5D4B06203F48"
        )
        await listen_for_updates(websocket)


asyncio.run(connect())

Last updated