Package: ln-markets
LN Markets Python APIA simple way to connect your Python application toLN Markets!InstallYou can install this package with pip:pip3installln-marketsUseYou can import the rest class from lnmarketsfromlnmarketsimportrestAnd the websocket class as wellfromlnmarketsimportwebsocketsAuthenticationFor authentication you need your apikeysecretandpassphraseWithout you will not bet able to authenticate:warning:Never share your API Key, Secret or PassphraseWebsocket APIConfigurationUse 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()Checkexamplesfor more details as you'll need to extend this class most of the time.SubscriptionYou can subscribe to LNM Markets public event such as futures last price ('futures:btc_usd:last-price') and index ('futures:btc_usd:index').REST API AuthenticationUsing API keyUse the LNMarketsRest and your key / passphrase to instanciate a new api connector:fromlnmarketsimportrestoptions={'key':'your_api_key','secret':'your_api_secret','passphrase':'your_api_passphrase','network':'testnet'}lnm=rest.LNMarketsRest(**options)lnm.futures_get_ticker()Using Mnemonic seedUse the LNMarketsRest withBIP39mnemonic phrase
to instanciate a new api connector:fromlnmarketsimportrestmnemonic='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()REST APIfutures_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_swapsswapget_userupdate_userget_new_bitcoin_addressget_bitcoin_addressesget_depositget_depositsnew_depositget_withdrawalget_withdrawalsnew_withdrawnew_internal_transferget_oracle_indexget_oracle_lastfetch_notificationsmark_notifications_readapp_configurationapp_nodeSee the API documentationfor more details.futures_add_marginAdd more margin to an existing trade.amount:
  type: Integer
  required: true
id:
  type: String
  required: trueExample:lnm.futures_add_margin({'amount':20000,'id':'249dc818-f8a5-4713-a3a3-8fe85f2e8969'})POST /futures/add-margindocumentation for more details.futures_cancel_allCancel all opened (not running) trades for this user.# No parametersExample:lnm.futures_cancel_all()DELETE /futures/all/canceldocumentation for more details.futures_close_allClose all running trades for this user.# No parametersExample:lnm.futures_close_all_positions()DELETE /futures/all/closedocumentation for more details.futures_cancelCancel a specific trade for this user.id:
  type: String
  required: trueExample:lnm.futures_cancel_position({'id':'b87eef8a-52ab-2fea-1adc-c41fba870b0f'})POST /futures/canceldocumentation for more details.futures_cashinCash in a part of the PL of a running trade.amount:
  type: Integer
  required: true
id:
  type: String
  required: trueExample:lnm.futures_cashin({'amount':1000,'id':"99c470e1-2e03-4486-a37f-1255e08178b1"})POST /futures/cash-indocumentation for more details.futures_carry_feesGet carry-fees history.from:
  type: Integer
  required: true

to:
  type: Integer
  required: tue

limit:
  type: Integer
  required: false
  default: 100Example:lnm.futures_carry_fees({'limit':20})GET /futures/carry-feesdocumentation for more details.futures_closeClose a specific running trade for this user.id:
  type: String
  required: trueExample:lnm.futures_close({'id':'a2ca6172-1078-463d-ae3f-8733f36a9b0e'})DELETE /futuresdocumentation for more details.futures_get_tradesRetrieve 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: 100Example:lnm.futures_get_trades({'type':'running'})GET /futuresdocumentation for more details.futures_new_tradeOpen 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: falseExample:lnm.futures_new_trade({'type':'m','side':'s','margin':10000,'leverage':25,})POST /futuresdocumentation for more details.futures_update_tradeModify 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: trueExample:lnm.futures_update_trade({'id':'b87eef8a-52ab-2fea-1adc-c41fba870b0f','type':'stoploss','value':13290.5})PUT /futuresdocumentation for more details.futures_get_priceGet Futures price data over time.from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit: Integer
  required: false
  default: 100Example:lnm.futures_price({'limit':20})GET /futures/history/pricedocumentation for more details.futures_fixingGet fixing data history.from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit:
  type: Integer
  required: false
  default: 100Example:lnm.futures_fixing({'limit':20})GET /futures/history/fixingdocumentation for more details.futures_indexGet index history data.from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit:
  type: Integer
  required: false
  default: 100Example:lnm.futures_index({'limit':20})GET /futures/history/indexdocumentation for more details.futures_get_tickerGet the futures ticker.# No parametersExample:lnm.futures_get_ticker()GET /futures/tickerdocumentation for more details.futures_get_leaderboardQueries the 10 users with the biggest positive PL on a daily, weekly, monthly and all-time basis.# No parametersExample:lnm.futures_get_leaderboard()GET /futures/leaderboarddocumentation for more details.futures_get_marketGet the futures market details.# No parametersExample:lnm.futures_get_market()GET /futures/marketdocumentation for more details.options_get_instrumentsGet the options instruments list.# No parametersExample:lnm.options_get_instruments()GET /options/instrumentsdocumentation for more details.options_get_instrumentGet a specific option instrument detail.instrument_name:
  type: String
  required: trueExample:lnm.options_get_instrument({'instrument_name':'BTC.2024-01-05.43000.C'})GET /options/instrumentdocumentation for more details.options_close_allClose 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 parametersExample:lnm.options_close_all()DELETE /options/close-alldocumentation for more details.options_closeClose 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: trueExample:lnm.options_close({'id':'a61faebc-7cc9-47e4-a22d-9d3e95c98322'})DELETE /optionsdocumentation for more details.options_get_tradesGet user's options trades.status:type:Stringenum:['running','closed']default:runningrequired:truefrom:type:Integerrequired:falseto:type:Integerrequired:falselimit:type:Integerrequired:falseExample:lnm.options_get_trades({limit:25,status:'closed'})GET /optionsdocumentation for more details.options_new_tradeCreate a new options tradeside:type:Stringenum:['b']required:truequantity:type:Integerrequired:truesettlement:type:Stringenum:['physical','cash']required:trueinstrument_name:type:Stringrequired:trueExample:lnm.options_new_trade({'side':'b','quantity':10,'settlement':'physical','instrument_name':'BTC.2024-01-05.43000.C'})POST /optionsdocumentation for more details.options_update_tradeAllows 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 /optionsdocumentation for more details.options_get_volatilityReturn the volatilityinstrument:
  type: String
  required: falseExample:lnm.options_get_volatility({'instrument':'BTC.2016-01-14.20000.C'})GET /options/volatilitydocumentation for more details.options_get_marketGet the options market details.# No parametersExample:lnm.options_get_market()GET /options/marketdocumentation for more details.get_swapsGet swap historyfrom:
  type: Integer
  required: false
  
to:
  type: Integer
  required: false
  
limit:
  type: Integer
  required: FalseExample:lnm.get_swaps({'from':1669980001000,'to':'1669990201000','limit':100})GET /swapdocumentation for more details.swapSwap betweem sats and synthetic USDin_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: falseExample:lnm.swap({'in_asset':'BTC','out_asset':'USD','out_amount':100})POST /swapdocumentation for more details.