NAV
curl Node.js Python

Introduction

LN Markets opens a simple REST API to integrate with your program or trading bot.

This API reference provides information on available endpoints and how to interact with it.

The API endpoint for mainnet is: https://api.lnmarkets.com

Authentication

One type of authentication is required, currently we are using a JSON Web Token (JWT)

The JWT can be generated with various scopes such as: - user - positions - deposit - withdraw

The JWT can be valid for a given period of time (15m, 30m, 1h, 6h, 12h, 24h, ... , 30d) or indefinitely. The JWT must be provided within the header AUTHORIZATION like :

Authorization: Bearer <token>

Note : Never share your JWT !

You can revoke any JWT on your profile page.

Limits

Positions

There is a maximum of 50 open positions per account.

Rate

Requests to our REST API are rate limited to 1 request per second.

Endpoints which do not require authentication are limited to 30 requests per minute.

If you throw too much error such as 4XX or 5XX, your IP could be banned for a certain period of time.

Headers

Header Value
Retry-After 14
X-Ratelimit-Remaining 0
X-Ratelimit-Reset 1601997680244


Retry-After : Will tell you how many seconds you need to wait to call this endpoint if your limit is down to 0.

X-Ratelimit-Remaining : This is how many request do you have left.

X-Ratelimit-Reset: This is the timestamp in ms when you will be granted new points.

Websocket

You can find a websocket endpoint where you can gather realtime data from LN Markets such as bid, offer, index and last price.

The websocket endpoint for mainnet is: wss://api.lnmarkets.com/realtime

You are limited to 60 connections per hour.

Authentication to websocket will come soon!

Errors

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Your API key is wrong.
403 Forbidden -- Your api key has the wrong scope.
404 Not Found -- Not Found.
405 Method Not Allowed -- You tried to access a ressource with an invalid method.
418 I'm a teapot.
429 Too Many Requests -- Your connection is being rate limited
500 Internal Server Error -- Something went wrong !
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.

API v1.0.0

Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.

Trade derivatives on the Lightning Network. You can find our website here.

Base URLs:

Login

Here you can find the different way to auth yourself on LN Markets, mostly use for browser.

Request new credentials

Code samples

import requests

url = "https://api.lnmarkets.com/login/credentials"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/login/credentials',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/login/credentials \
  --header 'accept: application/json'

GET /login/credentials

Generates an invoice for future use in the account creation process.

Example responses

200 Response

{
  "invoice": "lntb1u1p0jfxqcpp5ju9y2cur3v7nderx6u6ah7xj82lczem0pmmm4z5n2sn3de4qjqwqdz42pshjgr5dp5hxgrfdemx76trv5s8gmeqvdex2ct5v5s8jmm4wgsxzcmrda6kuapqdahzqnzwypxkzuntv468xcqzpgxqzz6sp53jz0ewjjwvnzkpl9pz8ar506z7dq3e4yw05pj9lulknhrwscncpq9qy9qsqzjvtdmnzptrq8avvynfdkswcts4ll8ffxxu02pgcg2ptyvz4xncsxrx3u32paw4806et6wan6tln60266zpd77a7usyv59jc83mnukqphdr5yx",
  "expiry": 90
}

Responses

Status Meaning Description Schema
200 OK Invoice successfully generated. Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» invoice string false none Invoice string
» expiry integer(int32) false none Invoice expiry timer

Register new credentials

Code samples

import requests

url = "https://api.lnmarkets.com/login/credentials"

payload = "{\"login\":\"lnmarkets\",\"password\":\"mYUNh4x0r48L3P422w0rd\",\"paymentHash\":\"b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'PUT',
  url: 'https://api.lnmarkets.com/login/credentials',
  headers: {'content-type': 'application/json', accept: 'application/json'},
  body: {
    login: 'lnmarkets',
    password: 'mYUNh4x0r48L3P422w0rd',
    paymentHash: 'b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request PUT \
  --url https://api.lnmarkets.com/login/credentials \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"login":"lnmarkets","password":"mYUNh4x0r48L3P422w0rd","paymentHash":"b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5"}'

PUT /login/credentials

Pay the invoice generated through a /login/credentials GET request and then use paymentHash to certify validity and finally create the account.

Body parameter

{
  "login": "lnmarkets",
  "password": "mYUNh4x0r48L3P422w0rd",
  "paymentHash": "b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5"
}

Parameters

Name In Type Required Description
body body object true none
» paymentHash body string true none
» login body string true none
» password body string(password) true none

Example responses

200 Response

{
  "login": "lnmarkets",
  "account_type": "credentials",
  "balance": 1337
}

Responses

Status Meaning Description Schema
200 OK User successfuly created and logged. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» username string true none User chosen username (May differ from login)
» balance string true none User current balance
» account_type string true none User account type, here credentials

Login via credentials

Code samples

import requests

url = "https://api.lnmarkets.com/login/credentials"

payload = "{\"login\":\"lnmarkets\",\"password\":\"mYUNh4x0r48L3P422w0rd\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/login/credentials',
  headers: {'content-type': 'application/json', accept: 'application/json'},
  body: {login: 'lnmarkets', password: 'mYUNh4x0r48L3P422w0rd'},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/login/credentials \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"login":"lnmarkets","password":"mYUNh4x0r48L3P422w0rd"}'

POST /login/credentials

Use existing credentials to log into an account.

Body parameter

{
  "login": "lnmarkets",
  "password": "mYUNh4x0r48L3P422w0rd"
}

Parameters

Name In Type Required Description
body body object true none
» login body string true none
» password body string(password) true none

Example responses

200 Response

{
  "login": "lnmarkets",
  "account_type": "credentials",
  "balance": 1337
}

Responses

Status Meaning Description Schema
200 OK Successfuly logged into the account. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» username string true none User choosen username (May differe from login)
» balance string true none User current balance
» account_type string true none User account type, here credentials

Response Headers

Status Header Type Format Description
200 Set-Cookie string none

Login with a JWT

Code samples

import requests

url = "https://api.lnmarkets.com/login/token"

payload = "{\"type\":\"object\",\"additionalProperties\":false,\"required\":[\"token\"],\"properties\":{\"token\":{\"type\":\"string\"}}}"
headers = {
    'content-type': "application/json",
    'accept': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/login/token',
  headers: {'content-type': 'application/json', accept: 'application/json'},
  body: {
    type: 'object',
    additionalProperties: false,
    required: ['token'],
    properties: {token: {type: 'string'}}
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/login/token \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"type":"object","additionalProperties":false,"required":["token"],"properties":{"token":{"type":"string"}}}'

POST /login/token

Use a JWT to log on LN Markets. The token need to have the 'user' scope and the token will be revoked ater the sucessfull login

Body parameter

{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "token"
  ],
  "properties": {
    "token": {
      "type": "string"
    }
  }
}

Parameters

Name In Type Required Description
body body object true none
» token body string true none

Example responses

200 Response

{
  "login": "lnmarkets",
  "account_type": "credentials",
  "balance": 1337
}

Responses

Status Meaning Description Schema
200 OK Successfuly logged into the account. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» username string true none User choosen username (May differe from login)
» balance string true none User current balance
» account_type string true none User account type, here credentials

Response Headers

Status Header Type Format Description
200 Set-Cookie string none

Reset password

Code samples

import requests

url = "https://api.lnmarkets.com/login/credentials/reset"

payload = "{\"login\":\"lnmarkets\",\"paymentHash\":\"b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5\",\"newPassword\":\"PleaseDontStealMySats\"}"
headers = {'content-type': 'application/json'}

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'PUT',
  url: 'https://api.lnmarkets.com/login/credentials/reset',
  headers: {'content-type': 'application/json'},
  body: {
    login: 'lnmarkets',
    paymentHash: 'b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5',
    newPassword: 'PleaseDontStealMySats'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request PUT \
  --url https://api.lnmarkets.com/login/credentials/reset \
  --header 'content-type: application/json' \
  --data '{"login":"lnmarkets","paymentHash":"b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5","newPassword":"PleaseDontStealMySats"}'

PUT /login/credentials/reset

Reset password with your payment hash.

Body parameter

{
  "login": "lnmarkets",
  "paymentHash": "b45dd2e30309aa708a73f0cfa0e38db5bbbbd16055087a692e0711365e7e08f5",
  "newPassword": "PleaseDontStealMySats"
}

Parameters

Name In Type Required Description
body body object true Payload containing login, payment hash and the new password.
» newPassword body string(password) true New password wanted by the user
» paymentHash body string true none
» login body string true none

Detailed descriptions

body: Payload containing login, payment hash and the new password.

Responses

Status Meaning Description Schema
200 OK Password successfuly reset. None
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None

Login via Joule

Code samples

import requests

url = "https://api.lnmarkets.com/login/joule"

payload = "{\"signature\":\"rd1nn7qbnibf58mzaknokqu6eciiqr64gahrzzxy3h8ybdygbun7s86zrms1dedqnh7t4gxz3esqmaqi9pkf85f48rexai7qztbdznfp\",\"alias\":\"LN-BIG 1337\",\"message\":\"Sign this super secret message\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/login/joule',
  headers: {'content-type': 'application/json', accept: 'application/json'},
  body: {
    signature: 'rd1nn7qbnibf58mzaknokqu6eciiqr64gahrzzxy3h8ybdygbun7s86zrms1dedqnh7t4gxz3esqmaqi9pkf85f48rexai7qztbdznfp',
    alias: 'LN-BIG 1337',
    message: 'Sign this super secret message'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/login/joule \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"signature":"rd1nn7qbnibf58mzaknokqu6eciiqr64gahrzzxy3h8ybdygbun7s86zrms1dedqnh7t4gxz3esqmaqi9pkf85f48rexai7qztbdznfp","alias":"LN-BIG 1337","message":"Sign this super secret message"}'

POST /login/joule

Use the browser extension Joule to authenticate user. The message has to be obtained using GET /login/joule

Body parameter

{
  "signature": "rd1nn7qbnibf58mzaknokqu6eciiqr64gahrzzxy3h8ybdygbun7s86zrms1dedqnh7t4gxz3esqmaqi9pkf85f48rexai7qztbdznfp",
  "alias": "LN-BIG 1337",
  "message": "Sign this super secret message"
}

Parameters

Name In Type Required Description
body body object true none
» message body string true Message signed by the wallet private key, who is obtained using GET /login/joule
» signature body string true Signature created by the wallet
» alias body string false Node alias if avalaible

Example responses

200 Response

{
  "account_type": "joule",
  "linkingpublickey": "02b21cc4667e2d5e14920013d187d2af8c3ccfd32a310f63c7767cf8564f126357",
  "balance": 1337,
  "username": "LN-BIG 1337"
}

Responses

Status Meaning Description Schema
200 OK Sucessfuly logged user. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» username string true none Username default to node alias
» balance string true none User balance
» linkingpublickey string true none Pubkey of the node
» account_type string true none Account type

Response Headers

Status Header Type Format Description
200 Set-Cookie string none

Request message

Code samples

import requests

url = "https://api.lnmarkets.com/login/joule"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/login/joule',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/login/joule \
  --header 'accept: application/json'

GET /login/joule

Generates a message that user can sign with POST /login/joule

Example responses

200 Response

{
  "message": "I am signing this message to login on LN Markets : 09d9bc06786d37eae6b60b537475d83d6b97177af22a74160a1fc3b0721f051e"
}

Responses

Status Meaning Description Schema
200 OK Message generated Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» message string false none The message contain a fixed part : "I am signing this message to login on LN Markets"
and a variable one who is a 64 char hex string, the variable one is used to identify which session should be authentificated

Positions

Interactions with the market and retrive your positions

Cancel

Code samples

import requests

url = "https://api.lnmarkets.com/positions/cancel"

payload = "{\"pid\":\"b87eef8a-52ab-2fea-1adc-c41fba870b0f\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/positions/cancel',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {pid: 'b87eef8a-52ab-2fea-1adc-c41fba870b0f'},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/positions/cancel \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"pid":"b87eef8a-52ab-2fea-1adc-c41fba870b0f"}'

POST /positions/cancel

Cancel the position linked to the given pid.Only works on positions that are not currently filled.

Body parameter

{
  "pid": "b87eef8a-52ab-2fea-1adc-c41fba870b0f"
}

Parameters

Name In Type Required Description
body body object true Payload containing the position id that will be cancelled.
» pid body string true Position ID

Example responses

200 Response

{
  "pid": "b87eef8a-52ab-2fea-1adc-c41fba870b0f",
  "canceled": true,
  "closed_ts": "020-11-15T10:50:40.332Z"
}

Responses

Status Meaning Description Schema
200 OK Position is canceled Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» canceled boolean false none Canncel success
» closed_ts string(date-time) false none When the position was canceled
» pid string false none Position ID

Create

Code samples

import requests

url = "https://api.lnmarkets.com/positions"

payload = "{\"type\":\"l\",\"side\":\"b\",\"price\":10000,\"stoploss\":9000,\"takeprofit\":11000,\"quantity\":100,\"leverage\":50}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/positions',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {
    type: 'l',
    side: 'b',
    price: 10000,
    stoploss: 9000,
    takeprofit: 11000,
    quantity: 100,
    leverage: 50
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/positions \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"type":"l","side":"b","price":10000,"stoploss":9000,"takeprofit":11000,"quantity":100,"leverage":50}'

POST /positions

Send the order form parameters to add a new position in database. If type="l", the property price must be included in the request to know when the position should be filled. You can choose to use the margin or the quantity as a parameter, the other will be calculated with the one you choosed

Body parameter

{
  "type": "l",
  "side": "b",
  "price": 10000,
  "stoploss": 9000,
  "takeprofit": 11000,
  "quantity": 100,
  "leverage": 50
}

Parameters

Name In Type Required Description
body body object true Payload with all the information needed to setup a new position.
» type body string true Type of the order (Market or Limit)
» side body string true Side of the order (Buy or Sell)
» margin body integer(int32) false Margin or quantity should be filled
» leverage body number(double) true Leverage of the order
» quantity body number false Quantity or margin should be filled
» takeprofit body number(double) false Takeprofit level
» stoploss body number(double) false Stoploss level
» price body number(double) false Required when using a limit order

Detailed descriptions

body: Payload with all the information needed to setup a new position.

Enumerated Values

Parameter Value
» type l
» type m
» side b
» side s

Example responses

200 Response

{
  "pid": "249dc818-f8a5-4713-a3a3-8fe85f2e8969",
  "id": 666,
  "type": "m",
  "takeprofit_wi": "running",
  "takeprofit": 13337,
  "stoploss_wi": "running",
  "stoploss": 1337,
  "side": "s",
  "quantity": 42,
  "price": 8888,
  "pl": -13640,
  "market_wi": "filled",
  "market_filled_ts": "020-09-15T10:50:40.332Z",
  "margin_wi": "running",
  "margin": 424242,
  "liquidation": 1000,
  "leverage": 50,
  "creation_ts": "020-09-15T10:50:40.332Z"
}

Responses

Status Meaning Description Schema
200 OK Position sucessfully created. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» pid string false none UUID of the position
» id string false none Position ID to be deprecated
» type string false none Position type [l,m]
» side string false none Side of the position [s,b]
» price string false none Entry price of the position
» quantity string false none Quantity of the position
» margin string false none Margin used for the position creation
» leverage string false none Leverage of the position
» liquidation string false none Liquidation level when the position will be closed
» market_filled_ts string(date-time)¦null false none When the order was filled
» market_wi string false none Market working indicator [filled, running, closed, canceled]
» pl string false none PL of the position
» margin_wi string false none Margin working indicator [filled, running, closed, canceled]
» stoploss string¦null false none stoploss level
» stoploss_wi string¦null false none Stoploss working indicator [filled, running, closed, canceled]
» takeprofit string¦null false none Takeprofit level
» takeprofit_wi string¦null false none Takeprofit working indicator [filled, running, closed, canceled]
» creation_ts string(date-time) false none When the position was created

Update

Code samples

import requests

url = "https://api.lnmarkets.com/positions"

payload = "{\"pid\":\"b87eef8a-52ab-2fea-1adc-c41fba870b0f\",\"type\":\"takeprofit\",\"value\":13290.5}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'PUT',
  url: 'https://api.lnmarkets.com/positions',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {
    pid: 'b87eef8a-52ab-2fea-1adc-c41fba870b0f',
    type: 'takeprofit',
    value: 13290.5
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request PUT \
  --url https://api.lnmarkets.com/positions \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"pid":"b87eef8a-52ab-2fea-1adc-c41fba870b0f","type":"takeprofit","value":13290.5}'

PUT /positions

Allows user to modify stoploss or takeprofit parameters of an existing position.

Body parameter

{
  "pid": "b87eef8a-52ab-2fea-1adc-c41fba870b0f",
  "type": "takeprofit",
  "value": 13290.5
}

Parameters

Name In Type Required Description
body body object true none
» pid body string true none
» type body string true none
» value body number true none

Enumerated Values

Parameter Value
» type takeprofit
» type stoploss

Example responses

200 Response

{
  "pid": "b87eef8a-52ab-2fea-1adc-c41fba870b0f"
}

Responses

Status Meaning Description Schema
200 OK Says whether or not the position was updated. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» pid string false none Position id

Close

Code samples

import requests

url = "https://api.lnmarkets.com/positions"

querystring = {"pid":"a2ca6172-1078-463d-ae3f-8733f36a9b0e"}

headers = {
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("DELETE", url, headers=headers, params=querystring)

print(response.text)
const request = require('request');

const options = {
  method: 'DELETE',
  url: 'https://api.lnmarkets.com/positions',
  qs: {pid: 'a2ca6172-1078-463d-ae3f-8733f36a9b0e'},
  headers: {accept: 'application/json', authorization: 'Bearer {access-token}'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request DELETE \
  --url 'https://api.lnmarkets.com/positions?pid=a2ca6172-1078-463d-ae3f-8733f36a9b0e' \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}'

DELETE /positions

Close the user position, the PL will be calculated against the current bid or offer depending on the side of the position

Parameters

Name In Type Required Description
pid query string true ID of the position to close.

Example responses

200 Response

{
  "pid": "a2ca6172-1078-463d-ae3f-8733f36a9b0e",
  "exit_price": 2000,
  "closed_ts": "020-10-15T10:50:40.332Z",
  "closed": true,
  "pl": 1337
}

Responses

Status Meaning Description Schema
200 OK Position is closed Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» closed boolean false none Is position closed
» closed_ts string(date-time)¦null false none Position closed ts
» exit_price string false none At which price the position was closed
» pid string false none Position id
» pl integer false none PL of the position

History

Code samples

import requests

url = "https://api.lnmarkets.com/positions"

headers = {
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/positions',
  headers: {accept: 'application/json', authorization: 'Bearer {access-token}'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/positions \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}'

GET /positions

Retrieves either opened, closed or all positions.

If no parameters are sent, all positions are fetched.

Parameters

Name In Type Required Description
type query string false List opened positions.

Enumerated Values

Parameter Value
type all
type open
type closed

Example responses

200 Response

{
  "positions": [
    {
      "pid": "249dc818-f8a5-4713-a3a3-8fe85f2e8969",
      "id": 666,
      "type": "m",
      "takeprofit_wi": "canceled",
      "takeprofit": 13337,
      "stoploss_wi": "canceled",
      "stoploss": 1337,
      "sign": -1,
      "side": "s",
      "quantity": 42,
      "price": 8888,
      "pl": -13640,
      "market_wi": "filled",
      "market_filled_ts": "020-09-15T10:50:40.332Z",
      "margin_wi": "closed",
      "margin": 424242,
      "liquidation": 1000,
      "leverage": 50,
      "exit_price": 2000,
      "creation_ts": "020-09-15T10:50:40.332Z",
      "closed_ts": "020-10-15T10:50:40.332Z",
      "closed": false,
      "canceled": true
    }
  ]
}

Responses

Status Meaning Description Schema
200 OK Positions history sucessfully fetched. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» pid string false none UUID of the position
» id string false none Position ID to be deprecated
» type string false none Position type [l,m]
» side string false none Side of the position [s,b]
» pl string false none PL of the position
» price string false none Entry price of the position
» quantity string false none Quantity of the position
» leverage string false none Leverage of the position
» liquidation string false none Liquidation level when the position will be closed
» margin string false none Margin used for the position creation
» margin_wi string false none Margin working indicator [filled, running, closed, canceled]
» market_filled_ts string(date-time)¦null false none When the order was filled
» market_wi string false none Market working indicator [filled, running, closed, canceled]
» canceled boolean false none Is the position canceled
» closed boolean false none Is the position closed
» closed_ts string(date-time)¦null false none When the position was closed
» creation_ts string(date-time) false none When the position was created
» exit_price string¦null false none At which price the position was closed
» stoploss string¦null false none stoploss level
» stoploss_wi string¦null false none Stoploss working indicator [filled, running, closed, canceled]
» takeprofit string¦null false none Takeprofit level
» takeprofit_wi string¦null false none Takeprofit working indicator [filled, running, closed, canceled]

User

You can retrieve your user data and modify it

Informations

Code samples

import requests

url = "https://api.lnmarkets.com/user"

headers = {
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/user',
  headers: {accept: 'application/json', authorization: 'Bearer {access-token}'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/user \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}'

GET /user

Get the user account Information

Example responses

200 Response

{
  "uid": "d068f829-26e6-4743-b10d-ebb5a83b3624",
  "balance": 361086,
  "account_type": "Joule",
  "username": "Testnet-node",
  "linkingpublickey": "035555cbdd2b5642bbd196b31df477fad20125ae99119fd5ffb1d42c7f4811dd3a",
  "last_ip": "127.0.0.1",
  "show_username": false,
  "show_leaderboard": true
}

Responses

Status Meaning Description Schema
200 OK User information Inline
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» uid string false none User's UUID
» balance string false none User current balance (avalaible)
» username string false none Username
» account_type string false none One of ['lnurl', 'credentials', 'joule']
» linkingpublickey string false none Public key used for lnurl or joule account
» last_ip string false none Last login ip
» show_leaderboard boolean false none Show the user PL in the leaderboard
» show_username boolean false none Show the username on LN Marktes public data, if false show 'Anonymous'

Update user

Code samples

import requests

url = "https://api.lnmarkets.com/user"

payload = "{\"show_username\":false,\"show_leaderboard\":true,\"username\":\"Cryptoking\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'PUT',
  url: 'https://api.lnmarkets.com/user',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {show_username: false, show_leaderboard: true, username: 'Cryptoking'},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request PUT \
  --url https://api.lnmarkets.com/user \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"show_username":false,"show_leaderboard":true,"username":"Cryptoking"}'

PUT /user

Modifies account parameters

Body parameter

{
  "show_username": false,
  "show_leaderboard": true,
  "username": "Cryptoking"
}

Parameters

Name In Type Required Description
body body object true none
» show_leaderboard body boolean false Show the user PL in the leaderboard
» show_username body boolean false Show the username on LN Marktes public data, if false show 'Anonymous'
» username body string false Username displayed on LN Markets public data

Example responses

200 Response

{
  "uid": "d068f829-26e6-4743-b10d-ebb5a83b3624",
  "balance": 361086,
  "account_type": "Joule",
  "username": "Testnet-node",
  "linkingpublickey": "035555cbdd2b5642bbd196b31df477fad20125ae99119fd5ffb1d42c7f4811dd3a",
  "last_ip": "127.0.0.1",
  "show_username": false,
  "show_leaderboard": true
}

Responses

Status Meaning Description Schema
200 OK User information Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» uid string false none User's UUID
» balance string false none User current balance (avalaible)
» username string false none Username
» account_type string false none One of ['lnurl', 'credentials', 'joule']
» linkingpublickey string false none Public key used for lnurl or joule account
» last_ip string false none Last login ip
» show_leaderboard boolean false none Show the user PL in the leaderboard
» show_username boolean false none Show the username on LN Marktes public data, if false show 'Anonymous'

Update password

Code samples

import requests

url = "https://api.lnmarkets.com/user/update-password"

payload = "{\"previousPassword\":\"previousUnguessablePassword\",\"newPassword\":\"PleaseDontStealMySats\"}"
headers = {
    'content-type': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'PUT',
  url: 'https://api.lnmarkets.com/user/update-password',
  headers: {'content-type': 'application/json', authorization: 'Bearer {access-token}'},
  body: {
    previousPassword: 'previousUnguessablePassword',
    newPassword: 'PleaseDontStealMySats'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request PUT \
  --url https://api.lnmarkets.com/user/update-password \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"previousPassword":"previousUnguessablePassword","newPassword":"PleaseDontStealMySats"}'

PUT /user/update-password

Update the current password to the requested one.

Body parameter

{
  "previousPassword": "previousUnguessablePassword",
  "newPassword": "PleaseDontStealMySats"
}

Parameters

Name In Type Required Description
body body object true Payload containing user credentials.
» previousPassword body string(password) true Old password
» newPassword body string(password) true New password wanted by the user

Detailed descriptions

body: Payload containing user credentials.

Responses

Status Meaning Description Schema
200 OK Password successfuly updated. None
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Transactions

Code samples

import requests

url = "https://api.lnmarkets.com/user/history"

querystring = {"type":"deposit"}

headers = {
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/user/history',
  qs: {type: 'deposit'},
  headers: {accept: 'application/json', authorization: 'Bearer {access-token}'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url 'https://api.lnmarkets.com/user/history?type=deposit' \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}'

GET /user/history

Retrieves all withdraw or deposit you did with LN Markets or just one page

Parameters

Name In Type Required Description
type query string true Which kind of transactions will be fetched.
nbItem query integer false Maximum length of the returned table.
index query integer false Which page we want (offset = nbItem * (index - 1)).
getLength query boolean false Return the length of the date slice given.
start query integer false Start of the time interval (UNIX UTC timestamp)
end query integer false End of the time interval (UNIX UTC timestamp)

Enumerated Values

Parameter Value
type withdraw
type deposit

Example responses

200 Response

{
  "transaction": [
    {
      "did": "269157f3-d4a1-4493-afcb-5e8fdaa49288",
      "amount": 99400,
      "creation_ts": "020-09-15T10:50:40.332Z",
      "details": null,
      "fail": false,
      "success": true,
      "fail_reason": null,
      "fail_ts": null,
      "payment_hash": "33f45c13c7ddcae46c6732414552893ca599f9399c62ffc2cfae209e8b17c5c3",
      "sucess_ts": "020-09-15T10:50:40.332Z"
    }
  ]
}

Responses

Status Meaning Description Schema
200 OK History sucessfully pulled. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» transaction [object] false none none
»» did string false none Deposit ID in case of deposit
»» wid string false none Withdraw ID in case of withdraw
»» amount integer false none Amount in sat
»» creation_ts string(date-time) false none When the transaction was initiated
»» details string¦null false none none
»» fail boolean false none Is the transaction failed
»» fail_reason string¦null false none none
»» fail_ts string(date-time)¦null false none When did the transaction failed ?
»» payment_hash string false none none
»» success boolean false none none
»» sucess_ts string(date-time)¦null false none none

List API Tokens

Code samples

import requests

url = "https://api.lnmarkets.com/user/jwt"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/user/jwt',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/user/jwt \
  --header 'accept: application/json'

GET /user/jwt

Retrieves the list of active JSON Web Token user currently holds.

Example responses

200 Response

[
  {
    "aud": [
      "withdraw",
      "deposit"
    ],
    "exp": "020-09-15T10:50:40.332Z",
    "iat": "020-09-15T10:50:40.332Z",
    "jti": "ckea35me20019r8u36374585f",
    "revoked": false
  }
]

Responses

Status Meaning Description Schema
200 OK Token list retrieved. Inline
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» aud [string] false none Scopes of the token
» exp string(date-time) false none Expiration of the token
» iat string(date-time) false none When the token was issued
» jti string false none Unique id of the token
» revoked boolean false none Is it revoked or not

Revoke API Token

Code samples

import requests

url = "https://api.lnmarkets.com/user/jwt"

response = requests.request("DELETE", url)

print(response.text)
const request = require('request');

const options = {method: 'DELETE', url: 'https://api.lnmarkets.com/user/jwt'};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request DELETE \
  --url https://api.lnmarkets.com/user/jwt

DELETE /user/jwt

Using the jti parameter, identifies and revoke usage of a given JWT.

Parameters

Name In Type Required Description
jti query string false Token unique identifier.

Responses

Status Meaning Description Schema
200 OK Token successfuly revoked. None
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Generate API Token

Code samples

import requests

url = "https://api.lnmarkets.com/user/jwt"

payload = "{\"expiry\":86400,\"scopes\":[\"deposit\",\"withdraw\"]}"
headers = {
    'content-type': "application/json",
    'accept': "application/json"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/user/jwt',
  headers: {'content-type': 'application/json', accept: 'application/json'},
  body: {expiry: 86400, scopes: ['deposit', 'withdraw']},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/user/jwt \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"expiry":86400,"scopes":["deposit","withdraw"]}'

POST /user/jwt

Using the given scopes, allow the token bearer to get access to different parts of the public API.

Body parameter

{
  "expiry": 86400,
  "scopes": [
    "deposit",
    "withdraw"
  ]
}

Parameters

Name In Type Required Description
body body object true Scopes of authorization that the token will grant to the bearer.
» scopes body [string] true Scopes of the token
» expiry body integer(int32) true Expiration of the token

Detailed descriptions

body: Scopes of authorization that the token will grant to the bearer.

Enumerated Values

Parameter Value
» scopes deposit
» scopes withdraw
» scopes positions
» scopes user

Example responses

200 Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAiLCJpYXQiOjE1OTgwNTg2NDQsInNjb3BlcyI6WyJ3aXRoZHJhdyIsImRlcG9zaXQiXX0.xJ3f5eMeRiN0eSzo3IDviny9B9v_-bLg4t_EWmXFBxc"
}

Responses

Status Meaning Description Schema
200 OK Token successfuly created, its Base64URL encoded signature is returned for future use. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» token string false none JWT

Deposit

Code samples

import requests

url = "https://api.lnmarkets.com/user/deposit"

payload = "{\"amount\":1000,\"unit\":\"sat\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/user/deposit',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {amount: 1000, unit: 'sat'},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/user/deposit \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"amount":1000,"unit":"sat"}'

POST /user/deposit

Add fund to your LN Markets balance

Body parameter

{
  "amount": 1000,
  "unit": "sat"
}

Parameters

Name In Type Required Description
body body object true Payload that contains all informations to initialize a new deposit.
» amount body integer true Amount of sat to deposit on the account
» unit body string false Should be sat by default

Detailed descriptions

body: Payload that contains all informations to initialize a new deposit.

Example responses

200 Response

{
  "paymentRequest": "lntb100u1p0jrfz0pp5q0ntrkf052dvep8w6vf0z77rek3fz8xm6c2yau4zhy7f4mzauqgsdzcf3hy6ctjddjhgueqg3jhqmmnd96zqgmxxquryvesvv6z6dehv43z6drpvycj6wfevs6j6dmyxcunxefcxccxxvn9cqzpgxqzpdsp5z40mxcrfqtsxf55u9ju3lvqdw36htsjh4xl2ujrzdff3953fg2yq9qy9qsqv7gfvp0tryme3e8r5xfrpg39j645302fkggps4h5j0aj708lzdgh2dq3pdz6lqazgvkt3wm7qq20vcff46vu5549m3v2d6h0uw3sjacqrkjqcv",
  "expiry": 45
}

Responses

Status Meaning Description Schema
200 OK New deposit entry in database waiting for payment. Using paymentRequest afterwards, user will confirm the deposit and funds will be added to his account. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» paymentRequest string false none Invoice you should pay to add balance to your account
» expiry integer false none When the invoice will expiry

Withdraw via invoice

Code samples

import requests

url = "https://api.lnmarkets.com/user/withdraw"

payload = "{\"amount\":1000,\"unit\":\"sat\",\"invoice\":\"lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz\"}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/user/withdraw',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {
    amount: 1000,
    unit: 'sat',
    invoice: 'lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz'
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/user/withdraw \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"amount":1000,"unit":"sat","invoice":"lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz"}'

POST /user/withdraw

Move funds from the Lightning channel with LN Markets to user wallet by using an invoice directly.

Body parameter

{
  "amount": 1000,
  "unit": "sat",
  "invoice": "lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz"
}

Parameters

Name In Type Required Description
body body object true Payload that countains all informations to initiate a new withdraw.
» amount body integer true Amount you want to withdraw
» unit body string false Unit (Only sat for now)
» invoice body string true Bolt 11 invoice with the same amount as the request withdraw amount

Detailed descriptions

body: Payload that countains all informations to initiate a new withdraw.

Example responses

200 Response

{
  "amount": 1000,
  "paymentsecret": "1b84c9852e929f99700b6cbabc4ca9d1593afc3736938b348c4d3d143e418bd4",
  "wid": "3fcbd8b7-c35b-4e83-87bc-111d5bd186b7",
  "paymenthash": "fb4d1e4ce4de84fe3a466bcf1d8543c0df56a9ac7a6c6f28bd9434a080a14c80"
}

Responses

Status Meaning Description Schema
200 OK Funds are removed from user account and added to user wallet. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» amount integer false none Amount withdrawnd
» paymentsecret string false none Payment secret of the settled invoice
» wid string false none Withdraw ID
» paymenthash string false none Payment hash for the settled invoice

Withdraw via LNURL

Code samples

import requests

url = "https://api.lnmarkets.com/user/withdraw/lnurl"

payload = "{\"amount\":1000}"
headers = {
    'content-type': "application/json",
    'accept': "application/json",
    'authorization': "Bearer {access-token}"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'POST',
  url: 'https://api.lnmarkets.com/user/withdraw/lnurl',
  headers: {
    'content-type': 'application/json',
    accept: 'application/json',
    authorization: 'Bearer {access-token}'
  },
  body: {amount: 1000},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/user/withdraw/lnurl \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {access-token}' \
  --header 'content-type: application/json' \
  --data '{"amount":1000}'

POST /user/withdraw/lnurl

Create a LNURL Withdraw.

Body parameter

{
  "amount": 1000
}

Parameters

Name In Type Required Description
body body object true Amount the user wants to withdraw.
» amount body integer true amount you want to withdraw
» unit body string false Unit (Only sat for now)

Detailed descriptions

body: Amount the user wants to withdraw.

Enumerated Values

Parameter Value
» unit sat
» unit msat

Example responses

200 Response

{
  "lnurl": "LNURL1DP68GURN8GHJ7UM9WFMXJCM99E3K7MF0V9CXJ0M385EKVCENXC6R2C35XVUKXEFCV5MKVV34X5EKZD3EV56NYD3HXQURZEPEXEJXXEPNXSCRVWFNV9NXZCN9XQ6XYEFHVGCXXCMYXYMNSERXFQ5FNS"
}

Responses

Status Meaning Description Schema
200 OK LNURL Bech32 encoded string Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» lnurl string false none LNURL for the users wallet

Logout

Code samples

import requests

url = "https://api.lnmarkets.com/user/logout"

response = requests.request("POST", url)

print(response.text)
const request = require('request');

const options = {method: 'POST', url: 'https://api.lnmarkets.com/user/logout'};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request POST \
  --url https://api.lnmarkets.com/user/logout

POST /user/logout

Delete the session cookie.

Responses

Status Meaning Description Schema
200 OK Sucessfully logged out. None

State

LN Markets state with data about our node and api availability

API informations

Code samples

import requests

url = "https://api.lnmarkets.com/state"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/state',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/state \
  --header 'accept: application/json'

GET /state

Shows informations about api.

Example responses

200 Response

{
  "ts": 1600244845097,
  "version": {
    "api": "74958cef7d4416dfa7f2c13fd23cd4aa7b469047",
    "soec": "31a4964e0ab4c77e7235ce5a0b458ba32dd8ace8"
  },
  "withdraw": true,
  "newPosition": true,
  "accountCreation": true
}

Responses

Status Meaning Description Schema
200 OK The API is online. Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» ts integer(int64) false none Timestamp reported by the API
» version object false none none
»» api string false none API version hash
»» spec string false none Open API version hash
» withdraw boolean false none Are withdraw enabled ?
» newposition boolean false none Are new position enabled ?
» accountCreation boolean false none Are account creation enabled ?

Node informations

Code samples

import requests

url = "https://api.lnmarkets.com/state/node"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/state/node',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/state/node \
  --header 'accept: application/json'

GET /state/node

Shows informations about the lightning node.

Example responses

200 Response

{
  "version": "0.11.0-beta commit=v0.11.0-beta'",
  "alias": "LN Markets",
  "pubkey": "03bae2db4b57738c1ec1ffa1c5e5a4423968cc592b3b39cddf7d495e72919d6431",
  "blockHeigth": 1835008,
  "remoteBalance": 266903254,
  "example": "localBalance",
  "channels": 1337,
  "peers": 42,
  "onionUri": "03bae2db4b57738c1ec1ffa1c5e5a4423968cc592b3b39cddf7d495e72919d6431@3pv4ci27cnahbztwlqtbez36rblecanoyxthrtjvxpk3en2y7dxfr3id.onion:9735",
  "uri": "03bae2db4b57738c1ec1ffa1c5e5a4423968cc592b3b39cddf7d495e72919d6431@34.192.102.161:9735"
}

Responses

Status Meaning Description Schema
200 OK The Node is online. Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» version string false none LND version
» alias string false none Node Alias
» pubkey string false none Node pubkey
» uri string false none Node URI
» onionUri string false none Node URI on tor
» peers integer(int64) false none Number of peers
» channels integer(int64) false none Number of channels
» localBalance integer(int64) false none Node local balance
» remoteBalance integer(int64) false none Node remote balance
» blockHeigth integer(int64) false none Node block heigth

History

LN Markets collected data over time

Bid & offer history

Code samples

import requests

url = "https://api.lnmarkets.com/history/bid-offer"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/history/bid-offer',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/history/bid-offer \
  --header 'accept: application/json'

GET /history/bid-offer

Retrieves at most 1000 entries between two given timestamps.

Parameters

Name In Type Required Description
from query integer(int64) false Starting timestamp (in ms).
to query integer(int64) false Ending timestamp (in ms).

Example responses

200 Response

{
  "data": [
    {
      "time": 1605633250615990,
      "bid": 15853,
      "offer": 15885
    }
  ]
}

Responses

Status Meaning Description Schema
200 OK Data history Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» time integer(int64) false none Timestamp at which the data was recorded (in µs)
» bid number false none Bid value at that time
» offer number false none Offer value at that time

Index history

Code samples

import requests

url = "https://api.lnmarkets.com/history/index"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/history/index',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/history/index \
  --header 'accept: application/json'

GET /history/index

Retrieves at most 1000 entries between two given timestamps.

Parameters

Name In Type Required Description
from query integer(int64) false Starting timestamp (in ms).
to query integer(int64) false Ending timestamp (in ms).

Example responses

200 Response

{
  "data": [
    {
      "time": 1605633250615990,
      "index": 15853
    }
  ]
}

Responses

Status Meaning Description Schema
200 OK Data history Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None
401 Unauthorized Unauthorized None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» time string false none Timestamp at which the data was recorded (in µs)
» index number false none Index value at that time

LNURL

Interaction with the lightning network using the LNURL procotocol LNURL enable simple auth process and easier withdraw

Auth 1

Code samples

import requests

url = "https://api.lnmarkets.com/lnurl/a/c"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/lnurl/a/c',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/lnurl/a/c \
  --header 'accept: application/json'

GET /lnurl/a/c

LNURL string used to create an account or connect to a existing account. The user wallet will sign a message using the provided k1 inside the LNURL. You need to have a session cookie on the browser you are using to log in.

Example responses

200 Response

{
  "lnurl": "lnurl1dp68gup69uhkcmmrv9kxsmmnwsarxvpsxqhkcmn4wfkz7cflw3skw0tvdankjm3xdvcn6venvgcrjenpx3nrwdtpxsur2vfsvdjk2dfkxe3kgceexymkgcmrxpjkgc3jvgmrqdnzvvurjwtr89jk2dp4vccrxvmrvvmxzdehxuejv6rdv93n6wpkv56rxcf4xqcxgwfsvsuxget9vymnqcfnv43rgwfjv5ex2cn9vyckgwtyvejrgc3excekyetpx43rvd3nxeskxvm9xqcxvwtpv5mq9uwr0k"
}

Responses

Status Meaning Description Schema
200 OK Bech32 encoded string. Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» lnurl string false none LNURL used by the wallet

Auth 2

Code samples

import requests

url = "https://api.lnmarkets.com/lnurl/a"

querystring = {"k1":"kyNVmR6HDtAW2aplYk6XmmpDrIhvzzq6","tag":"login","sig":"qep5sAqwleQS27UdKLGNsCBTWB4soS45us9vJAbk1hMEdCAXoeB6IESi3Nz7SXJM","key":"Yc4h1Z5BZVmgmVQfIbdPWRVj9kHAo3uf","hmac":"kuSHSXXDiP4qofiL2LGelesLLlRXUCJd"}

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/lnurl/a',
  qs: {
    k1: 'kyNVmR6HDtAW2aplYk6XmmpDrIhvzzq6',
    tag: 'login',
    sig: 'qep5sAqwleQS27UdKLGNsCBTWB4soS45us9vJAbk1hMEdCAXoeB6IESi3Nz7SXJM',
    key: 'Yc4h1Z5BZVmgmVQfIbdPWRVj9kHAo3uf',
    hmac: 'kuSHSXXDiP4qofiL2LGelesLLlRXUCJd'
  },
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url 'https://api.lnmarkets.com/lnurl/a?k1=kyNVmR6HDtAW2aplYk6XmmpDrIhvzzq6&tag=login&sig=qep5sAqwleQS27UdKLGNsCBTWB4soS45us9vJAbk1hMEdCAXoeB6IESi3Nz7SXJM&key=Yc4h1Z5BZVmgmVQfIbdPWRVj9kHAo3uf&hmac=kuSHSXXDiP4qofiL2LGelesLLlRXUCJd' \
  --header 'accept: application/json'

GET /lnurl/a

Verify the public key with the signature and the k1 to create a account or connect into a existing account. If JWT is set to true, a JWT will be returned with by default all scopes and an expiry of 1h, they can be changed by setting the query paramater expiry or scopes like POST /user/jwt. Else the connected state will be push over websocketsto the client.

Parameters

Name In Type Required Description
k1 query string true Hex encoded 32 bytes of challenge which is going to be signed by user private key.
tag query string true LNURL type.
sig query string true Signature generated by the lightning wallet.
key query string true Public key of the lightning wallet.
hmac query string true HMAC signature used to secure LNURL.
t query string false Timestamp.
jwt query boolean false Request will responsd with a JWT token instead of pushing auth state to websocket
expiry query integer(int32) false JWT expiration, default to 3600
scopes query string false Scope of the jwt, default to 'deposit', 'withdraw', 'positions', 'user'

Enumerated Values

Parameter Value
tag login

Example responses

200 Response

{
  "status": "OK",
  "event": "LOGGEDIN"
}

Responses

Status Meaning Description Schema
200 OK Sucessfuly logged in. Inline
400 Bad Request The request query and / or body does not fit the schema requirements. It can also be raised by parameters leading to unexpected behaviour / results. None

Response Schema

Status Code 200

Name Type Required Restrictions Description
» status string false none Does the request suceed ?
» event string false none State of the user
» token string false none JWT if asked

Withdraw 2

Code samples

import requests

url = "https://api.lnmarkets.com/lnurl/w/r"

querystring = {"signature":"type,string","n":"type,string,minLength,64,maxLength,64","expiry":"1599841538304"}

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/lnurl/w/r',
  qs: {
    signature: 'type,string',
    n: 'type,string,minLength,64,maxLength,64',
    expiry: '1599841538304'
  },
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url 'https://api.lnmarkets.com/lnurl/w/r?signature=type%2Cstring&n=type%2Cstring%2CminLength%2C64%2CmaxLength%2C64&expiry=1599841538304' \
  --header 'accept: application/json'

GET /lnurl/w/r

Ask the Lightning wallet to create an invoice with amount and description.

Parameters

Name In Type Required Description
signature query string true HMAC payload signature.
n query string true Nonce.
expiry query integer true Timestamp when the LNURL is expired.

Example responses

200 Response

{
  "k1": "31c92c1bd79d2ae5f96a153ceda105cb67888c61bfb76baa1d2505a6bf8a06ca",
  "tag": "withdrawRequest",
  "maxWithdrawable": 1000,
  "minWithdrawable": 1000,
  "defaultDescription": "LN Markets withdraw",
  "callback": "https://api.lnmarkets.com/lnurl/w"
}

Responses

Status Meaning Description Schema
200 OK LNURL withdraw invoice parameter. Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» callback string false none Callback URL used by the wallet
» defaultDescription string false none Invoice default description
» tag string false none Kind of LNURL
» maxWithdrawable integer(int32) false none Max withdrawable amount
» minWithdrawable integer(int32) false none Min withdrawable amount
» k1 string false none Random hex string to identify the user Lightning Wallet.

Withdraw 3

Code samples

import requests

url = "https://api.lnmarkets.com/lnurl/w"

querystring = {"k1":"kyNVmR6HDtAW2aplYk6XmmpDrIhvzzq6","pr":"<invoice>"}

response = requests.request("GET", url, params=querystring)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/lnurl/w',
  qs: {k1: 'kyNVmR6HDtAW2aplYk6XmmpDrIhvzzq6', pr: '<invoice>'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url 'https://api.lnmarkets.com/lnurl/w?k1=kyNVmR6HDtAW2aplYk6XmmpDrIhvzzq6&pr=%3Cinvoice%3E'

GET /lnurl/w

Use LNURL to withdraw from the user balance.

Parameters

Name In Type Required Description
k1 query string true Random hex string to identify the user Lightning Wallet.
pr query string true Bolt 11 invoice.

Responses

Status Meaning Description Schema
200 OK Sucessfuly withdrawn funds from channel. None

Leaderboard

Get current Leaderboard

Code samples

import requests

url = "https://api.lnmarkets.com/state/leaderboard"

headers = {'accept': 'application/json'}

response = requests.request("GET", url, headers=headers)

print(response.text)
const request = require('request');

const options = {
  method: 'GET',
  url: 'https://api.lnmarkets.com/state/leaderboard',
  headers: {accept: 'application/json'}
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

curl --request GET \
  --url https://api.lnmarkets.com/state/leaderboard \
  --header 'accept: application/json'

GET /state/leaderboard

Queries the database to get the 10 users with the biggest posititve PL

Example responses

200 Response

[
  {
    "username": "Bob",
    "pl": 4242424242
  },
  {
    "username": "Jean-Kevin",
    "pl": 3491941
  },
  {
    "username": "Roger",
    "pl": 24013441
  },
  {
    "username": "Laura",
    "pl": 23126094
  },
  {
    "username": "Marcus",
    "pl": 1414019
  },
  {
    "username": "Charles",
    "pl": 242918
  },
  {
    "username": "Antoine",
    "pl": 99999
  },
  {
    "username": "XXxRoBeRtLeBgDu24xXX",
    "pl": 61491
  },
  {
    "username": "CRYPTOKING",
    "pl": 10000
  },
  {
    "username": "HEY",
    "pl": 3
  }
]

Responses

Status Meaning Description Schema
200 OK Leaderboard successfully fetched Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
» username string false none Username or 'Anonymous' if the Leaderboard view is disabled
» pl integer false none Sum of every profits and losses of the user

undefined