# NodeJS

[GitHub](https://github.com/velodataorg/velo-node/tree/main), [npm](https://www.npmjs.com/package/velo-node)

### Examples

<details>

<summary>Quick Start</summary>

```javascript
const velo = require('velo-node')

async function doWork() {
  const futures = await client.futures()
  const future = futures[0]

  const columns = client.futuresColumns()
  const twoColumns = columns.slice(0, 2)

  const params = {
    type: 'futures',
    columns: twoColumns,
    exchanges: [future.exchange],
    products: [future.product],
    begin: Date.now() - 1000 * 60 * 11, // 10 minutes
    end: Date.now(),
    resolution: '1m' // 1 minute
  }

  const rows = client.rows(params)
  for await (const row of rows) {
    console.log(row)
  }
}

const client = new velo.Client('api_key')

doWork()
```

</details>

<details>

<summary>Orderbook Data</summary>

```javascript
const velo = require('velo-node')

async function doWork() {
  const futures = await client.futures()
  const future = futures.filter((f) => f.depth)[0]

  const dayInMs = 1000 * 60 * 60 * 24

  const params = {
    exchange: future.exchange,
    product: future.product,
    begin: Date.now() - dayInMs,
    end: Date.now(),
    resolution: '5m'
  }

  const iter = client.depth(params)
  for await (const depth of iter) {
    console.log(depth)
  }
}

const client = new velo.Client('api_key')

doWork()
```

</details>

***

### Helper Methods

* Key status: `status()`
* Supported futures: `futures(delisted=False)`
* Supported options: `options()`
* Supported spot pairs: `spot(delisted=False)`
* Supported futures columns: `futuresColumns()`
* Supported options columns: `optionsColumns()`
* Supported spot columns: `spotColumns()`

***

### Data Methods

<details>

<summary>Get rows</summary>

`rows(params)`

* type: 'futures', 'options', or 'spot'
* exchanges, products, coins, columns: arrays
* begin, end: millisecond timestamps
* resolution: minutes (integer) or resolution (string)

Asynchronously returns individual rows (Objects)

*If both \`coins\` and \`products\` are specified, only \`products\` will be used*

</details>

<details>

<summary>Get options term structure</summary>

`termStructure(params)`

* coins: array

Returns Object

*Latest values only*

</details>

<details>

<summary>Get market caps</summary>

`marketCaps(params)`

* coins: array

Returns Object

*Latest values only*

</details>

<details>

<summary>Get orderbook data</summary>

`depth(params)`

* exchange, product, coin: string
* begin, end: millisecond timestamps
* resolution: minutes (integer) or resolution (string)

Asynchronously returns Object with `time`, `mid`, and `price:value` pairs.

*Use 'coin' only for aggregated orderbook data. Use 'product' and 'exchange' for a specific product.*

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.velo.xyz/api/nodejs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
