### Installing @ln-markets/api with npm (Shell) Source: https://github.com/ln-markets/api-js/blob/master/README.md Installs the @ln-markets/api package using the npm package manager. This command downloads the package and its dependencies. ```shell $> npm install @ln-markets/api ``` -------------------------------- ### Installing @ln-markets/api with yarn (Shell) Source: https://github.com/ln-markets/api-js/blob/master/README.md Installs the @ln-markets/api package using the yarn package manager. This command downloads the package and its dependencies. ```shell $> yarn add @ln-markets/api ``` -------------------------------- ### Installing @ln-markets/api with pnpm (Shell) Source: https://github.com/ln-markets/api-js/blob/master/README.md Installs the @ln-markets/api package using the pnpm package manager. This command downloads the package and its dependencies. ```shell $> pnpm install @ln-markets/api ``` -------------------------------- ### Creating REST Client with API Key/Secret from Variables (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client with API key and secret provided as variables. This example implies the passphrase may be sourced from environment variables if required by the API. ```javascript // process.env.LNM_API_KEY = `` // process.env.LNM_API_SECRET = `` // process.env.LNM_API_PASSPHRASE = `` const client = new createRestClient({ key, secret }) const trades = await client.futuresGetTrades() console.log(trades) ``` -------------------------------- ### Creating Websocket Client and Subscribing to Channels (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes an asynchronous Websocket client, subscribes to public price and index channels using `publicSubscribe`, and sets up event listeners for general responses and specific channel updates. ```javascript import { createWebsocketClient } from '@ln-markets/api' // Need to be async const client = await createWebsocketClient() await client.publicSubscribe([ 'futures:btc_usd:last-price', 'futures:btc_usd:index' ]) // Event on all response client.on('response', console.log) // Event emitter on subscribed channels client.on('futures:btc_usd:last-price', console.log) client.on('futures:btc_usd:index', console.log) // Handle websocket error here client.ws.on('error', console.error) ``` -------------------------------- ### Creating REST Client for Testnet (Config Object) (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client configured to connect to the LN Markets testnet environment by passing the `network: 'testnet'` option to the constructor. ```javascript import { createRestClient } from '@ln-markets/api' const client = createRestClient({ network: 'testnet' }) ``` -------------------------------- ### Creating Default REST Client (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a new REST client instance using `createRestClient` with default configuration, which connects to the mainnet API. ```javascript import { createRestClient } from '@ln-markets/api' const client = createRestClient() ``` -------------------------------- ### Creating Websocket Client for Testnet (Config Object) (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a Websocket client configured to connect to the LN Markets testnet environment by passing the `network: 'testnet'` option to the constructor. ```javascript import { createWebsocketClient } from '@ln-markets/api' const client = createWebsocketClient({ network: 'testnet' }) ``` -------------------------------- ### Creating REST Client for Testnet (Environment Variable) (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client configured for the testnet by relying on the `LNM_API_NETWORK` environment variable being set to 'testnet'. ```javascript // process.env.LNM_API_NETWORK = 'testnet' import { createRestClient } from '@ln-markets/api' const client = createRestClient() ``` -------------------------------- ### Creating REST Client with API Key/Secret/Passphrase from Variables (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client with authentication credentials (key, secret, passphrase) provided directly as variables. These credentials are required for authenticated API routes. ```javascript import { createRestClient } from '@ln-markets/api' const key = `` const secret = `` const passphrase = `` const client = new createRestClient({ key, secret, passphrase }) const trades = await client.futuresGetTrades() console.log(trades) ``` -------------------------------- ### Creating REST Client with Specific API Version (Config Object) (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client configured to use a specific API version by passing the `version` option to the constructor. ```javascript import { createRestClient } from '@ln-markets/api' const client = createRestClient({ version: 'v42' }) ``` -------------------------------- ### Creating Websocket Client for Testnet (Environment Variable) (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a Websocket client configured for the testnet by relying on the `LNM_API_NETWORK` environment variable being set to 'testnet'. ```javascript // process.env.LNM_API_NETWORK = 'testnet' import { createWebsocketClient } from '@ln-markets/api' const client = createWebsocketClient() ``` -------------------------------- ### Creating REST Client with Specific API Version (Environment Variable) (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client configured to use a specific API version by relying on the `LNM_API_VERSION` environment variable being set. ```javascript // process.env.LNM_API_VERSION = 'v42' import { createRestClient } from '@ln-markets/api' const client = createRestClient() ``` -------------------------------- ### Importing REST and Websocket Clients (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Imports the necessary functions `createRestClient` and `createWebsocketClient` from the @ln-markets/api package. This syntax is for use in an ES module environment. ```javascript import { createRestClient, createWebsocketClient } from '@ln-markets/api' ``` -------------------------------- ### Creating REST Client with Custom Headers (JavaScript) Source: https://github.com/ln-markets/api-js/blob/master/README.md Initializes a REST client configured to include custom HTTP headers in all outgoing requests by providing a `headers` object. ```javascript import { createRestClient } from '@ln-markets/api' const client = createRestClient({ headers: { 'X-My-Header': 'My value' } }) ``` -------------------------------- ### Set API Version - LN Markets API - JavaScript Source: https://github.com/ln-markets/api-js/blob/master/README.md Demonstrates how to explicitly set the API version when initializing the LN Markets websocket client by passing the `version` option to `createWebsocketClient`. Requires the `@ln-markets/api` library. ```javascript import { createWebsocketClient } from '@ln-markets/api' const client = createWebsocketClient({ version: 'v42' }) ``` -------------------------------- ### Use Env Var for API Version - LN Markets API - JavaScript Source: https://github.com/ln-markets/api-js/blob/master/README.md Shows how the LN Markets websocket client can pick up the API version from the `LNM_API_VERSION` environment variable if not explicitly set in the options. Requires the `@ln-markets/api` library. ```javascript // process.env.LNM_API_VERSION = 'v42' import { createWebsocketClient } from '@ln-markets/api' const client = createWebsocketClient() ``` -------------------------------- ### Disable Heartbeat - LN Markets API - JavaScript Source: https://github.com/ln-markets/api-js/blob/master/README.md Illustrates how to disable the automatic heartbeat (ping) mechanism for the LN Markets websocket client by setting the `heartbeat` option to `false` during initialization. Requires the `@ln-markets/api` library. ```javascript import { createWebsocketClient } from '@ln-markets/api' const client = createWebsocketClient({ heartbeat: false }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.