A simple way to connect your Python application to LN Markets!
You can install this package with pip:
pip3 install ln-markets
## Usage
You can import rest class from ln_markets
```python
from lnmarkets import restAnd the websocket one as well!
from lnmarkets import websockets
## 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**
## Websocket API
### Configuration
Use the LNMarketsWebsocket and your key / passphrase to instanciate a new api connector:
```python
options = {'key': 'your_api_key',
'secret': 'your_api_secret',
'passphrase': 'your_api_passphrase'}
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 bid offer, index and options data.
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()futures_new_positionfutures_get_positionsfutures_update_positionfutures_add_margin_positionfutures_cancel_all_positionsfutures_cancel_positionfutures_cashin_positionfutures_close_all_positionsfutures_close_positionfutures_index_historyfutures_bid_offer_historyfutures_fixing_historyfutures_carry_fees_historydepositdeposit_historyfutures_historyget_announcementsget_leaderboardget_userapi_statenode_stateupdate_userwithdrawoptions_get_positionsoptions_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: falseExample:
lnm.futures_new_position({
'type': 'm',
'side': 's',
'margin': 10000,
'leverage': 25.5,
})POST /futures documentation for more details.
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: 100Example:
lnm.futures_get_positions({
'type': 'running'
})GET /futures documentation for more details.
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:
lnm.futures_update_position({
'pid': 'b87eef8a-52ab-2fea-1adc-c41fba870b0f',
'type': 'stoploss',
'value': 13290.5
})PUT /futures documentation for more details.
Add more margin to an existing position.
amount:
type: Integer
required: true
pid:
type: String
required: trueExample:
lnm.futures_add_margin_position({
'amount': 20000,
'pid': '249dc818-f8a5-4713-a3a3-8fe85f2e8969'
})POST /futures/add-margin documentation for more details.
Cancel all opened (not running) positions for this user.
# No parameters
Example:
lnm.futures_cancel_all_positions()DELETE /futures/all/cancel documentation for more details.
Cancel a particular position for this user.
pid:
type: String
required: trueExample:
lnm.futures_cancel_position({
'pid': 'b87eef8a-52ab-2fea-1adc-c41fba870b0f'
})POST /futures/cancel documentation for more details.
Retrieve a part of the general PL of a running position.
amount:
type: Integer
required: true
pid:
type: String
required: trueExample:
lnm.futures_cashin_position({
'amount': 1000,
'pid': "99c470e1-2e03-4486-a37f-1255e08178b1"
})POST /futures/cash-in documentation for more details.
Close all running position for this user.
# No parameters
Example:
lnm.futures_close_all_positions()DELETE /futures/all/close documentation for more details.
Close a particular running position for this user.
pid:
type: String
required: trueExample:
lnm.futures_close_position({
'pid': 'a2ca6172-1078-463d-ae3f-8733f36a9b0e'
})DELETE /futures documentation for more details.
Get index history data.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 100Example:
lnm.futures_index_history({
'limit': 20
})GET /futures/history/index documentation for more details.
Get bid and offer data over time.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit: Integer
required: false
default: 100Example:
lnm.futures_bid_offer_history({
'limit': 20
})GET /futures/history/bid-offer documentation for more details.
Get fixing data history.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 100Example:
lnm.futures_fixing_history({
'limit': 20
})GET /futures/history/fixing documentation for more details.
Get carry-fees history.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: false
default: 100Example:
lnm.futures_carry_fees_history({
'limit': 20
})GET /futures/carry-fees documentation for more details.
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.
Retrieve deposit history for this user.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: falseExample:
lnm.deposit_history({
'limit': 30
})GET /user/deposit documentation for more details.
Retrieve announcements made by LN Markets.
# No parameters
Example:
lnm.get_announcements()GET /state/announcemenets documentation for more details.
Queries the 10 users with the biggest positive PL.
# No parameters
Example:
lnm.get_leaderboard()GET /futures/leaderboard documentation for more details.
Retrieve user informations.
# No parameters
Example:
lnm.get_user()
[`GET /user`](https://docs.lnmarkets.com/api/v1/#informations) documentation for more details.
#### node_state
Show informations about LN Markets lightning node.
Example:
```python
lnm.node_state()
GET /state/node documentation for more details.
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:
lnm.update_user({
'show_username': True,
'show_leaderboard': True,
'username': 'API-Connector',
})PUT /user documentation for more details.
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:
lnm.withdraw({
'amount': 1000,
'invoice': 'lntb100u1p0jr0ykpp5ldx3un8ym6z0uwjxd083mp2rcr04d2dv0fkx729ajs62pq9pfjqqdql23jhxapdwa5hg6rywfshwttjda6hgegcqzpgxq92fjuqsp5m6q0fzynu2qr624mzjc285duurhccmkfg94mcdctc0p9s7qkrq8q9qy9qsqp862cjznpey5r76e7amhlpmhwn2c7xvke59srhv0xf75m4ksjm4hzn8y9xy0zs5ec6gxmsr8gj4q23w8ped32llscjcneyjz2afeapqpu4gamz'
})POST /user/withdraw documentation for more details.
Retrieve user withdraw history.
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: falseExample:
lnm.withdraw_history({
'limit': 25
})GET /user/withdraw documentation for more details.
Retrieve all or a part of user options positions.
status:
type: String
enum: ['running', 'closed']
default: running
required: true
from:
type: Integer
required: false
to:
type: Integer
required: false
limit:
type: Integer
required: falseExample:
lnm.options_get_positions({
limit: 25,
status: 'closed'
})GET /options/vanilla documentation for more details.
Open a new option position on the market.
side:
type: String
enum: ['b']
required: true
type:
type: String
enum: ['c', 'p']
required: true
quantity:
type: Integer
required: true
strike:
type: Integer
required: true
settlement:
type: String
enum: ['physical', 'cash']
required: trueExample:
lnm.options_new_position({
limit: 25,
status: 'closed'
})POST /options/vanilla documentation for more details.
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']
path:
type: String
required: true
params:
type: Object
required: false
credentials:
type: Boolean
required: false
default: falseExample:
lnm.requestAPI({
method: 'GET',
path: '/user',
credentials: true
})