
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
ln-markets
Advanced tools
A simple way to connect your Python application to LN Markets!
You can install this package with pip:
pip3 install ln-markets
You can import the rest class from lnmarkets
from lnmarkets import rest
And the websocket class as well
from lnmarkets import websockets
For authentication you need your api key secret and passphrase
Without you will not bet able to authenticate
:warning: Never share your API Key, Secret or Passphrase
Use the LNMarketsWebsocket and your key / passphrase to instanciate a new api connector:
options = {'key': 'your_api_key',
'secret': 'your_api_secret',
'passphrase': 'your_api_passphrase',
'network': 'testnet'}
lnm = websockets.LNMarketsWebsocket(**options)
lnm.connect()
Check examples for more details as you'll need to extend this class most of the time.
You can subscribe to LNM Markets public event such as futures last price ('futures:btc_usd:last-price') and index ('futures:btc_usd:index').
Use the LNMarketsRest and your key / passphrase to instanciate a new api connector:
from lnmarkets import rest
options = {'key': 'your_api_key',
'secret': 'your_api_secret',
'passphrase': 'your_api_passphrase',
'network': 'testnet'}
lnm = rest.LNMarketsRest(**options)
lnm.futures_get_ticker()
Use the LNMarketsRest with BIP39 mnemonic phrase to instanciate a new api connector:
from lnmarkets import rest
mnemonic = 'struggle goddess action cheap endorse venue force tomato exercise cactus charge such'
lnm = rest.LNMarketsRest(mnemonic=mnemonic)
lnm.futures_get_ticker()
Mnemonic seed auth is a "hack" using the cookie used by LNM WebApp, so for avoid risk of stolen cookie, you should logout, when your program stop running:
lnm.logout()
The cookie have a lifetime (about 1 week), so if your program running for more than that time you might renew the cookie before expiry date (note that it can also be a safety measure tu renew your cookie often to avoid stolen cookies risk):
lnm.renew_cookie()
futures_add_marginfutures_cancel_allfutures_close_allfutures_cancelfutures_cashinfutures_closefutures_get_tradesfutures_new_tradefutures_update_tradefutures_carry_feesfutures_get_pricefutures_fixingfutures_indexfutures_get_leaderboardfutures_get_tickerfutures_get_marketoptions_get_instrumentsoptions_get_instrumentoptions_close_alloptions_closeoptions_get_tradesoptions_new_tradeoptions_update_tradeoptions_get_volatilityoptions_get_marketget_swapsswapSee the API documentation for more details.
Add more margin to an existing trade.
amount:
type: Integer
required: true
id:
type: String
required: true
Example:
lnm.futures_add_margin({
'amount': 20000,
'id': '249dc818-f8a5-4713-a3a3-8fe85f2e8969'
})
POST /futures/add-margin documentation for more details.
Cancel all opened (not running) trades for this user.
# No parameters
Example:
lnm.futures_cancel_all()
DELETE /futures/all/cancel documentation for more details.
Close all running trades for this user.
# No parameters
Example:
lnm.futures_close_all()
DELETE /futures/all/close documentation for more details.
Cancel a specific trade for this user.
id:
type: String
required: true
Example:
lnm.futures_cancel_position({
'id': 'b87eef8a-52ab-2fea-1adc-c41fba870b0f'
})
POST /futures/cancel documentation for more details.
Cash in a part of the PL of a running trade.
amount:
type: Integer
required: true
id:
type: String
required: true
Example:
lnm.futures_cashin({
'amount': 1000,
'id': "99c470e1-2e03-4486-a37f-1255e08178b1"
})
POST /futures/cash-in documentation for more details.
Get carry-fees history.
from:
type: Integer
required: true
to:
type: Integer
required: tue
limit:
type: Integer
required: false
default: 100
Example:
lnm.futures_carry_fees({
'limit': 20
})
GET /futures/carry-fees documentation for more details.
Close a specific running trade for this user.
id:
type: String
required: true
Example:
lnm.futures_close({
'id': 'a2ca6172-1078-463d-ae3f-8733f36a9b0e'
})
DELETE /futures documentation for more details.
Retrieve all or a part of user's trades.
type:
type: String
required: true
enum: ['open', 'running', 'closed']
default: 'open'
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 100
Example:
lnm.futures_get_trades({
'type': 'running'
})
GET /futures documentation for more details.
Open a new trade. If type="l", the property price must be included in the request to know when the trade 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 chose.
type:
type: String
required: true
enum: ['l', 'm']
side:
type: String
required: true
enum: ['b', 's']
margin:
type: Integer
required: true
leverage:
type: Float
required: true
quantity:
type: Integer
required: false
takeprofit:
type: Integer
required: false
stoploss:
type: Integer
required: false
price:
type: Float
required: false
Example:
lnm.futures_new_trade({
'type': 'm',
'side': 's',
'margin': 10000,
'leverage': 25,
})
POST /futures documentation for more details.
Modify stoploss or takeprofit parameter of an existing trade.
id:
type: String
required: true
type:
type: String
required: true
enum: ['takeprofit', 'stoploss']
value:
type: Float
required: true
Example:
lnm.futures_update_trade({
'id': 'b87eef8a-52ab-2fea-1adc-c41fba870b0f',
'type': 'stoploss',
'value': 13290.5
})
PUT /futures documentation for more details.
Get Futures price data over time.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit: Integer
required: false
default: 100
Example:
lnm.futures_price({
'limit': 20
})
GET /futures/history/price documentation for more details.
Get fixing data history.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 100
Example:
lnm.futures_fixing({
'limit': 20
})
GET /futures/history/fixing documentation for more details.
Get index history data.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 100
Example:
lnm.futures_index({
'limit': 20
})
GET /futures/history/index documentation for more details.
Get the futures ticker.
# No parameters
Example:
lnm.futures_get_ticker()
GET /futures/ticker documentation for more details.
Queries the 10 users with the biggest positive PL on a daily, weekly, monthly and all-time basis.
# No parameters
Example:
lnm.futures_get_leaderboard()
GET /futures/leaderboard documentation for more details.
Get the futures market details.
# No parameters
Example:
lnm.futures_get_market()
GET /futures/market documentation for more details.
Get the options instruments list.
# No parameters
Example:
lnm.options_get_instruments()
GET /options/instruments documentation for more details.
Get a specific option instrument detail.
instrument_name:
type: String
required: true
Example:
lnm.options_get_instrument({
'instrument_name': 'BTC.2024-01-05.43000.C'
})
GET /options/instrument documentation for more details.
Close all of the user option trades, the PL will be calculated against the current bid or offer depending on the type of the options.
# No parameters
Example:
lnm.options_close_all()
DELETE /options/close-all documentation for more details.
Close the user option trade, the PL will be calculated against the current bid or offer depending on the type of the option.
id:
type: String
required: true
Example:
lnm.options_close({
'id': 'a61faebc-7cc9-47e4-a22d-9d3e95c98322'
})
DELETE /options documentation for more details.
Get user's options trades.
status:
type: String
enum: ['running', 'closed']
default: running
required: true
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
Example:
lnm.options_get_trades({
limit: 25,
status: 'closed'
})
GET /options documentation for more details.
Create a new options trade
side:
type: String
enum: ['b']
required: true
quantity:
type: Integer
required: true
settlement:
type: String
enum: ['physical', 'cash']
required: true
instrument_name:
type: String
required: true
Example:
lnm.options_new_trade({
'side': 'b',
'quantity': 10,
'settlement': 'physical',
'instrument_name': 'BTC.2024-01-05.43000.C'
})
POST /options documentation for more details.
Allows user to update settlement parameter in running option trade.
id:
type: String
required: true
settlement:
type: String
required: true
enum: ['physical', 'cash']
Example:
lnm.options_update_trade({
'id': 'a2ca6172-1078-463d-ae3f-8733f36a9b0e',
'settlement': 'physical'
})
PUT /options documentation for more details.
Return the volatility
instrument:
type: String
required: false
Example:
lnm.options_get_volatility({
'instrument': 'BTC.2016-01-14.20000.C'
})
GET /options/volatility documentation for more details.
Get the options market details.
# No parameters
Example:
lnm.options_get_market()
GET /options/market documentation for more details.
Get swap history
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: False
Example:
lnm.get_swaps({
'from': 1669980001000,
'to': '1669990201000',
'limit': 100
})
GET /swap documentation for more details.
Swap betweem sats and synthetic USD
in_asset:
type: String
required: true
enum: ['USD', 'BTC']
out_asset:
type: String
required: true
enum: ['USD', 'BTC']
in_amount:
type: Integer
required: False
out_amount:
type: Integer
required: false
Example:
lnm.swap({
'in_asset': 'BTC',
'out_asset': 'USD',
'out_amount': 100
})
POST /swap documentation for more details.
FAQs
LN Markets API python implementation
We found that ln-markets demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.