@lnmarkets/api-connector v1.0.1
Node Connector
Install
You can install this package with npm:
$> npm install @lnmarkets/api-connectorThen go to on your LN Markets account under the API section of the Profile to generate an API Token with the right scopes and the right expiry to fit your needs. You'll need to copy this token as it is needed to authenticate yourself and make requests to the API.

All you have to do now is to instanciate a LNMarkets object this way:
const LNMarkets = require('@lnmarkets/api-connector')
const API = new LNMarkets({ token: <YOUR-TOKEN> })After this, you'll be able to use all the documented API methods below.
Options
This connector require an object as parameter. Here is the list of its possible properties.
token:
type: String
required: true
network:
type: String
required: false
default: 'mainnet'
version:
type: String
required: false
default: 'v1'Route Methods
All these functions are wrappers for documented public endpoints from LN Markets API v1. See specification here.
Be careful, all methods expect an object as parameter with the correct parameters in it.
addMarginPositionapiStatecancelAllPositionscancelPositioncashinPositioncloseAllPosisitionsclosePositiondepositdepositHistoryfuturesDataHistorygetAnnouncementsgetLeaderboardgetPositionsgetUsernewPositionnodeStateupdatePositionupdateUserwithdrawwithdrawHistorywithdrawLNURL
Generic Methods
These methods are designed to fill the gaps if the API evolves and the future but this package isn't up to date.
Documentation
addMargin
Add more margin to an existing position.
amount:
type: Integer
required: true
pid:
type: String
required: trueExample:
await API.addMargin({
amount: 20000,
pid: '249dc818-f8a5-4713-a3a3-8fe85f2e8969'
})POST /futures/add-margin documentation for more details.
apiState
Retrieve informations related to LN Markets API.
# No parametersExample:
await API.apiState()GET /state documentation for more details.
cancelAllPositions
Cancel all oponed (not running) positions for this user.
# No parametersExample:
await API.cancelAllPositions()DELETE /futures/all/cancel documentation for more details.
cancelPosition
Cancel a particular position for this user.
pid:
type: String
required: trueExample:
await API.cancelPosition({
pid: 'b87eef8a-52ab-2fea-1adc-c41fba870b0f'
})POST /futures/cancel documentation for more details.
cashinPosition
Retrieve a part of the general PL of a running position.
amount:
type: Integer
required: true
pid:
type: String
required: trueExample:
await API.cashinPosition({
amount: 1000,
pid: "99c470e1-2e03-4486-a37f-1255e08178b1"
})POST /futures/cash-in documentation for more details.
closeAllPosisitions
Close all running position for this user.
# No parametersExample:
await API.closeAllPosisitions()DELETE /futures/all/close documentation for more details.
closePosition
Close a particular running position for this user.
pid:
type: String
required: trueExample:
await API.closePosition({
pid: 'a2ca6172-1078-463d-ae3f-8733f36a9b0e'
})DELETE /futures documentation for more details.
deposit
Add funds to your LN Markets balance.
amount:
type: Integer
required: true
unit:
type: String
required: false
default: 'sat'Example:
await API.deposit({
amount: 25000
})POST /user/deposit documentation for more details.
depositHistory
Retrieve deposit history for this user.
nbItem:
type: Integer
required: false
default: 50
index:
type: Integer
required: false
default: 0
getLength:
type: Boolean
required: false
default: false
start:
type: Integer
required: false
end:
type: Integer
required: falseExample:
await API.depositHistory({
nbItem: 30
})GET /user/deposit documentation for more details.
futuresDataHistory
Retrieve the past bid, offer and index data recorded.
table:
type: String
required: true
enum: ['bid_offer', 'index']
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 1000Example:
await API.futuresDataHistory({
table: 'index',
limit: 250
})GET /futures/history documentation for more details.
getAnnouncements
Retrieve announcements made by LN Markets.
# No parametersExample:
await API.getAnnouncements()GET /state/announcemenets documentation for more details.
getLeaderboard
Queries the 10 users with the biggest positive PL.
# No parametersExample:
await API.getLeaderboard()GET /state/leaderboard documentation for more details.
getPositions
Retrieve all or a part of user positions.
type:
type: String
required: false
enum: ['all', 'open', 'running', 'closed']
default: 'all'Example:
await API.getPositions({
type: 'running'
})GET /futures documentation for more details.
getUser
Retrieve user informations.
# No parametersExample:
await API.getUser()GET /user documentation for more details.
newPosition
Open a new position on the market.
type:
type: String
required: true
enum: ['l', 'm']
side:
type: String
required: true
enum: ['b', 's']
margin:
type: Integer
required: false
leverage:
type: Float
required: true
quantity:
type: Integer
required: false
takeprofit:
type: Integer
required: false
stoploss:
type: Integer
required: false
price:
type: Float
required: falseExample:
await API.newPosition({
type: 'm',
side: 's',
margin: 10000,
leverage: 25.5,
})POST /futures documentation for more details.
nodeState
Show informations about LN Markets lightning node.
# No parametersExample:
await API.nodeState()GET /state/node documentation for more details.
updatePosition
Modify stoploss or takeprofit parameter of an existing position.
pid:
type: String
required: true
type:
type: String
required: true
enum: ['takeprofit', 'stoploss']
value:
type: Float
required: trueExample:
await API.updatePosition({
pid: 'b87eef8a-52ab-2fea-1adc-c41fba870b0f',
type: 'stoploss',
value: 13290.5
})PUT /futures documentation for more details.
updateUser
Modify user account parameters.
show_leaderboard:
type: Boolean
required: false
show_username:
type: Boolean
required: false
username:
type: String
required: false
email:
type: String
required: false
resend_email:
type: Boolean
required: falseExample:
await API.updateUser({
show_username: true,
show_leaderboard: true,
username: 'API-Connector',
})PUT /user documentation for more details.
withdraw
Move funds from LN Markets to your wallet via BOLT11 invoice.
amount:
type: Integer
required: true
unit:
type: String
required: false
default: 'sat'
invoice:
type: String
required: trueExample:
await API.withdraw({
amount: 1000,
invoice: 'lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz'
})POST /user/withdraw documentation for more details.
withdrawHistory
Retrieve user withdraw history.
nbItem:
type: Integer
required: false
default: 50
index:
type: Integer
required: false
default: 0
getLength:
type: Boolean
required: false
default: false
start:
type: Integer
required: false
end:
type: Integer
required: falseExample:
await API.withdrawHistory({
nbItem: 25
})GET /user/withdraw documentation for more details.
withdrawLNURL
Create a LNURL to withdraw from user account.
amount:
type: Integer
required: true
unit:
type: String
required: false
default: 'sat'Example:
await API.withdrawLNURL({
amount: 40000,
})POST /lnurl/withdraw documentation for more details.
Use LNURL to withdraw directly from the user balance to the wallet
requestAPI
This method is used in case where no wrapper is (yet) available for a particular endpoint.
method:
type: String
required: true
enum: ['GET', 'PUT', 'POST', 'DELETE']
endpoint:
type: String
required: true
params:
type: Object
required: false
credentials:
type: Boolean
required: false
default: falseendpoint is which route you want to communicate with, credentials is your generated token.
Example:
await API.requestAPI({
method: 'GET',
endpoint: '/user',
credentials: true
})