> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coingecko.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OnchainSimpleTokenPrice

> Subscribe to receive real-time price updates for tokens, as seen on GeckoTerminal.com

This WebSocket channel allows you to subscribe to real-time updates of price changes for tokens.

* Lookup by Network + Token Address
* It will return price and market data of the top pool of the specified token.

**Update Frequency**: as fast as 1s, for actively traded tokens.

### Data Payload

|      | Field                             | Type    | Description                                                                                                                | Example                                      |
| ---- | --------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |
| `c`  | `channel_type`                    | string  | Indicates the type of channel subscribed to.                                                                               | G1                                           |
| `n`  | `network_id`                      | string  | Identifier of the blockchain network. Check full list of IDs [here](https://api.geckoterminal.com/api/v2/networks?page=1). | `eth`                                        |
| `ta` | `token_address`                   | string  | Contract address of the token on the blockchain.                                                                           | `0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2` |
| `p`  | `usd_price`                       | float   | Current token price in USD.                                                                                                | 3639.78228844745                             |
| `pp` | `usd_price_24h_change_percentage` | float   | Percentage change in token price over the last 24 hours.                                                                   | 3.566                                        |
| `m`  | `usd_market_cap`                  | float   | Market capitalization in USD.                                                                                              | 123                                          |
| `v`  | `usd_24h_vol`                     | float   | 24-hour trading volume in USD.                                                                                             | 31233333.33                                  |
| `t`  | `last_updated_at`                 | integer | Timestamp of the last data update in UNIX time.                                                                            | 1709542750                                   |

**Tips**: The WebSocket payload will use the value `null` when specific data is unavailable. Ensure your application is capable of handling null values for fields that may not always have data.

***

## 1. Establish Connection to WebSocket

<CodeGroup>
  ```bash Bash theme={null}
  wss://stream.coingecko.com/v1?x_cg_pro_api_key=YOUR_KEY

  OR

  wss://stream.coingecko.com/v1  
  x-cg-pro-api-key: YOUR_KEY
  ```
</CodeGroup>

## 2. Subscribe to a specific channel - OnchainSimpleTokenPrice

**Input Example:**

<CodeGroup>
  ```json JSON theme={null}
  {"command":"subscribe","identifier":"{\"channel\":\"OnchainSimpleTokenPrice\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {"type":"confirm_subscription","identifier":"{\"channel\":\"OnchainSimpleTokenPrice\"}"}
  ```
</CodeGroup>

## 3. Stream OnchainSimpleTokenPrice data

**Input Example:**

<CodeGroup>
  ```json JSON theme={null}
  {"command":"message","identifier":"{\"channel\":\"OnchainSimpleTokenPrice\"}","data":"{\"network_id:token_addresses\":[\"bsc:0x55d398326f99059ff775485246999027b3197955\"],\"action\":\"set_tokens\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
    "code": 2000,
    "message": "Subscription successful for bsc:0x55d398326f99059ff775485246999027b3197955"
  }
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
    "c": "G1",
    "n": "bsc",
    "ta": "0x55d398326f99059ff775485246999027b3197955",
    "p": 0.999457718373347,
    "pp": -0.009028866490825653,
    "m": 1317802988326.25,
    "v": 1476864199.38384,
    "t": 1737427063
  }
  ```
</CodeGroup>

The output keys will be in random order.

## Tips:

### Unsubscribe to stop streaming OnchainSimpleTokenPrice data

**Input Example:** Unsubscribe for 1 specific token data:

<CodeGroup>
  ```json JSON theme={null}
  {"command":"message","identifier":"{\"channel\":\"OnchainSimpleTokenPrice\"}","data":"{\"network_id:token_addresses\":[\"bsc:0x55d398326f99059ff775485246999027b3197955\"],\"action\":\"unset_tokens\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
    "code":2000,
    "message":"Unsubscription is successful for bsc:0x55d398326f99059ff775485246999027b3197955"
  }
  ```
</CodeGroup>

**Input Example:** Unsubscribe from OnchainSimpleTokenPrice channel and all token data:

<CodeGroup>
  ```json JSON theme={null}
  {"command":"unsubscribe","identifier":"{\"channel\":\"OnchainSimpleTokenPrice\"}"}
  ```
</CodeGroup>

**Output Example**:

<CodeGroup>
  ```json JSON theme={null}
  {
    "code":2000,
    "message":"Unsubscription is successful for all tokens"
  }
  ```
</CodeGroup>


## AsyncAPI

````yaml websocket/asyncapi.json onchainsimpletokenprice
id: onchainsimpletokenprice
title: Onchainsimpletokenprice
description: ''
servers:
  - id: production
    protocol: wss
    host: stream.coingecko.com
    bindings: []
    variables: []
address: /v1
parameters: []
bindings: []
operations:
  - &ref_1
    id: subscribeToOnchainSimpleTokenPrice
    title: 'OnchainSimpleTokenPrice: Subscribe'
    description: Subscribe to OnchainSimpleTokenPrice channel
    type: receive
    messages:
      - &ref_4
        id: subscribe
        payload:
          - name: Subscribe to OnchainSimpleTokenPrice
            description: Subscribe to the OnchainSimpleTokenPrice channel
            type: object
            properties:
              - name: command
                type: string
                description: Command to subscribe to a channel
                enumValues:
                  - subscribe
                required: true
              - name: identifier
                type: string
                description: JSON string containing channel information
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            command:
              type: string
              enum:
                - subscribe
              default: subscribe
              example: subscribe
              description: Command to subscribe to a channel
              x-parser-schema-id: <anonymous-schema-18>
            identifier:
              type: string
              default: '{"channel":"OnchainSimpleTokenPrice"}'
              example: '{"channel":"OnchainSimpleTokenPrice"}'
              description: JSON string containing channel information
              x-parser-schema-id: <anonymous-schema-19>
          required:
            - command
            - identifier
          x-parser-schema-id: <anonymous-schema-17>
        title: Subscribe to OnchainSimpleTokenPrice
        description: Subscribe to the OnchainSimpleTokenPrice channel
        example: |-
          {
            "command": "<string>",
            "identifier": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribe
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: onchainsimpletokenprice
  - &ref_2
    id: streamOnchainSimpleTokenPrice
    title: 'OnchainSimpleTokenPrice: Stream Data'
    description: Request token price streaming
    type: receive
    messages:
      - &ref_5
        id: streamRequest
        payload:
          - name: Stream OnchainSimpleTokenPrice Data
            description: Set tokens to receive price updates
            type: object
            properties:
              - name: command
                type: string
                description: Command to send a message
                enumValues:
                  - message
                required: true
              - name: identifier
                type: string
                description: JSON string containing channel information
                required: true
              - name: data
                type: string
                description: >-
                  You may edit this. Format is network_id:token_address.
                  Examples: ["bsc:0x55d39..."] or
                  ["eth:0xc02aa...","bsc:0x55d39..."]
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            command:
              type: string
              enum:
                - message
              default: message
              example: message
              description: Command to send a message
              x-parser-schema-id: <anonymous-schema-21>
            identifier:
              type: string
              default: '{"channel":"OnchainSimpleTokenPrice"}'
              example: '{"channel":"OnchainSimpleTokenPrice"}'
              description: JSON string containing channel information
              x-parser-schema-id: <anonymous-schema-22>
            data:
              type: string
              default: >-
                {"network_id:token_addresses":["bsc:0x55d398326f99059ff775485246999027b3197955"],"action":"set_tokens"}
              example: >-
                {"network_id:token_addresses":["bsc:0x55d398326f99059ff775485246999027b3197955"],"action":"set_tokens"}
              description: >-
                You may edit this. Format is network_id:token_address. Examples:
                ["bsc:0x55d39..."] or ["eth:0xc02aa...","bsc:0x55d39..."]
              x-parser-schema-id: <anonymous-schema-23>
          required:
            - command
            - identifier
            - data
          x-parser-schema-id: <anonymous-schema-20>
        title: Stream OnchainSimpleTokenPrice Data
        description: Set tokens to receive price updates
        example: |-
          {
            "command": "<string>",
            "identifier": "<string>",
            "data": "<string>"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: streamRequest
    bindings: []
    extensions: *ref_0
  - &ref_3
    id: receiveOnchainSimpleTokenPriceUpdates
    title: 'OnchainSimpleTokenPrice: Receive Updates'
    description: Receive real-time token price updates
    type: send
    messages:
      - &ref_6
        id: priceUpdate
        payload:
          - name: OnchainSimpleTokenPrice Update
            description: Real-time token price update
            type: object
            properties:
              - name: c
                type: string
                description: Channel type
                required: false
              - name: 'n'
                type: string
                description: Network identifier
                required: false
              - name: ta
                type: string
                description: Token contract address
                required: false
              - name: p
                type: number
                description: Current token price in USD
                required: false
              - name: pp
                type: number
                description: Price change percentage (24h)
                required: false
              - name: m
                type: number
                description: Market cap in USD
                required: false
              - name: v
                type: number
                description: 24-hour trading volume in USD
                required: false
              - name: t
                type: integer
                description: Timestamp (UNIX)
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            c:
              type: string
              example: G1
              description: Channel type
              x-parser-schema-id: <anonymous-schema-25>
            'n':
              type: string
              example: bsc
              description: Network identifier
              x-parser-schema-id: <anonymous-schema-26>
            ta:
              type: string
              example: '0x55d398326f99059ff775485246999027b3197955'
              description: Token contract address
              x-parser-schema-id: <anonymous-schema-27>
            p:
              type: number
              example: 0.999457718373347
              description: Current token price in USD
              x-parser-schema-id: <anonymous-schema-28>
            pp:
              type: number
              example: -0.009028866490825653
              description: Price change percentage (24h)
              x-parser-schema-id: <anonymous-schema-29>
            m:
              type: number
              example: 1317802988326.25
              description: Market cap in USD
              x-parser-schema-id: <anonymous-schema-30>
            v:
              type: number
              example: 1476864199.38384
              description: 24-hour trading volume in USD
              x-parser-schema-id: <anonymous-schema-31>
            t:
              type: integer
              example: 1737427063
              description: Timestamp (UNIX)
              x-parser-schema-id: <anonymous-schema-32>
          x-parser-schema-id: <anonymous-schema-24>
        title: OnchainSimpleTokenPrice Update
        description: Real-time token price update
        example: |-
          {
            "c": "<string>",
            "n": "<string>",
            "ta": "<string>",
            "p": 123,
            "pp": 123,
            "m": 123,
            "v": 123,
            "t": 123
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: priceUpdate
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
  - *ref_2
receiveOperations:
  - *ref_3
sendMessages:
  - *ref_4
  - *ref_5
receiveMessages:
  - *ref_6
extensions:
  - id: x-parser-unique-object-id
    value: onchainsimpletokenprice
securitySchemes:
  - id: cgApiKey
    name: x_cg_pro_api_key
    type: httpApiKey
    description: Insert CoinGecko Pro API key to establish WebSocket connection
    in: query
    extensions: []

````