Skip to main content

LN Markets REST API python implementation

Project description

LN Markets Python API

A simple way to connect your Python application to LN Markets!

Install

You can install this package with pip:

pip install ln-markets

Usage

You can import rest class from ln_markets

from lnmarkets import rest

Authentication

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

Configuration

Use the LNMarketsRest and your key / passphrase to instanciate a new api connector:

options = {'key': 'your_api_key', 
           'secret': 'your_api_secret', 
           'passphrase': 'your_api_passphrase'}

lnm = rest.LNMarketsRest(**options)

lnm.futures_get_ticker()

REST API

futures_new_position

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: false

Example:

  lnm.futures_new_position({
    'type': 'm',
    'side': 's',
    'margin': 10000,
    'leverage': 25.5,
  })

POST /futures documentation for more details.

futures_get_positions

Retrieve all or a part of user positions.

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_positions({
    'type': 'running'
  })

GET /futures documentation for more details.

futures_update_position

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: true

Example:

lnm.futures_update_position({
    'pid': 'b87eef8a-52ab-2fea-1adc-c41fba870b0f',
    'type': 'stoploss',
    'value': 13290.5
  })

PUT /futures documentation for more details.

add_margin

Add more margin to an existing position.

amount:
  type: Integer
  required: true
pid:
  type: String
  required: true

Example:

lnm.add_margin({
    'amount': 20000,
    'pid': '249dc818-f8a5-4713-a3a3-8fe85f2e8969'
  })

POST /futures/add-margin documentation for more details.

futures_cancel_all_positions

Cancel all oponed (not running) positions for this user.

# No parameters

Example:

lnm.futures_cancel_all_positions()

DELETE /futures/all/cancel documentation for more details.

futures_cancel_position

Cancel a particular position for this user.

pid:
  type: String
  required: true

Example:

lnm.futures_cancel_position({
    'pid': 'b87eef8a-52ab-2fea-1adc-c41fba870b0f'
  })

POST /futures/cancel documentation for more details.

futures_cashin_position

Retrieve a part of the general PL of a running position.

amount:
  type: Integer
  required: true
pid:
  type: String
  required: true

Example:

lnm.futures_cashin_position({
    'amount': 1000,
    'pid': "99c470e1-2e03-4486-a37f-1255e08178b1"
  })

POST /futures/cash-in documentation for more details.

futures_close_all_posisitions

Close all running position for this user.

# No parameters

Example:

lnm.futures_close_all_positions()

DELETE /futures/all/close documentation for more details.

futures_close_position

Close a particular running position for this user.

pid:
  type: String
  required: true

Example:

lnm.futures_close_position({
    'pid': 'a2ca6172-1078-463d-ae3f-8733f36a9b0e'
  })

DELETE /futures documentation for more details.

futures_index_history

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_history({
    'limit': 20
  })

GET /futures/history/index documentation for more details.

futures_bid_offer_history

Get bid and offer data over time.

from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit: Integer
  required: false
  default: 100

Example:

lnm.futures_bid_offer_history({
    'limit': 20
  })

GET /futures/history/bid-offer documentation for more details.

futures_fixing_history

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_history({
    'limit': 20
  })

GET /futures/history/fixing documentation for more details.

futures_carry_fees_history

Get carry-fees history.

from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit:
  type: Integer
  required: false
  default: 100

Example:

lnm.futures_carry_fees_history({
    'limit': 20
  })

GET /futures/carry-fees 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:

lnm.deposit({
    'amount': 25000
  })

POST /user/deposit documentation for more details.

deposit_history

Retrieve deposit history for this user.

from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit:
  type: Integer
  required: false

Example:

lnm.deposit_history({
    'limit': 30
  })

GET /user/deposit documentation for more details.

get_announcements

Retrieve announcements made by LN Markets.

# No parameters

Example:

lnm.get_announcements()

GET /state/announcemenets documentation for more details.

get_leaderboard

Queries the 10 users with the biggest positive PL.

# No parameters

Example:

lnm.get_leaderboard()

GET /futures/leaderboard documentation for more details.

get_user

Retrieve user informations.

# No parameters

Example:

lnm.getUser()

GET /user documentation for more details.

node_state

Show informations about LN Markets lightning node.

# No parameters

Example:

lnm.node_state()

GET /state/node documentation for more details.

update_user

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: false

Example:

lnm.update_user({
    '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: true

Example:

lnm.withdraw({
    'amount': 1000,
    'invoice': 'lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz'
  })

POST /user/withdraw documentation for more details.

withdraw_history

Retrieve user withdraw history.

from:
  type: Integer
  required: false

to:
  type: Integer
  required: false

limit:
  type: Integer
  required: false

Example:

lnm.withdraw_history({
   'limit': 25
  })

GET /user/withdraw documentation for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ln-markets-1.0.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ln_markets-1.0.3-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ln-markets-1.0.3.tar.gz.

File metadata

  • Download URL: ln-markets-1.0.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for ln-markets-1.0.3.tar.gz
Algorithm Hash digest
SHA256 979b76c4db4ddefad6831881397d9671c96080b6adebdbfe761aadf754929090
MD5 c009653670ff21596c9fb706bd1dcb2f
BLAKE2b-256 abd5da76643abdea4271169548557b125df1d4c1c5b5d179101834cb18631ee4

See more details on using hashes here.

File details

Details for the file ln_markets-1.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: ln_markets-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for ln_markets-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 02004a7333b6e6266b4d721687e6cca08d54a97fa6e38e8ee829f3f1bd2b05dc
MD5 1b4cd711872ced4cd97d14c486b4bf1e
BLAKE2b-256 f6cf74fc9f6312ad6f348b0ea90ecb63c5f1e193a6e08c6caab168c8cd199a21

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page