-
Notifications
You must be signed in to change notification settings - Fork 15
/
lnm_client.py
67 lines (57 loc) · 2.16 KB
/
lnm_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from lnmarkets import rest
import datetime
from time import time
import logging
import json
logging.basicConfig(level=logging.INFO)
class lnm_client():
# Connection to LN Markets API
def __init__(self, options):
self.options = options
self.lnm = rest.LNMarketsRest(**self.options)
if len(json.loads(self.lnm.get_user())['uid']) != 36:
logging.warning('There is probably an error with your LN Markets credentials')
else:
logging.info('Connection to LN Markets ok!')
def get_user(self):
print(self.lnm.get_user())
def market_long(self, quantity, leverage, takeprofit, stoploss):
params = {
'type': 'm',
'side': 'b',
'quantity': quantity,
'leverage': leverage,
'takeprofit': takeprofit,
'stoploss': stoploss
}
logging.info(datetime.datetime.fromtimestamp(time()))
logging.info(
f'New Market Buy Running for Quantity = {quantity}, leverage = {leverage}, take profit = {takeprofit}, stop loss = {stoploss}')
return self.lnm.futures_new_trade(params)
def market_short(self, quantity, leverage, takeprofit, stoploss):
params = {
'type': 'm',
'side': 's',
'quantity': quantity,
'leverage': leverage,
'takeprofit': takeprofit,
'stoploss': stoploss
}
logging.info(datetime.datetime.fromtimestamp(time()))
logging.info(
f'New Market Sell Running for Quantity = {quantity}, leverage = {leverage}, take profit = {takeprofit}, stop loss = {stoploss}')
return self.lnm.futures_new_trade(params)
def close_position(self, operation_id):
params = {
'id': operation_id,
}
logging.info(datetime.datetime.fromtimestamp(time()))
logging.info(f'Close position id = {operation_id}')
return self.lnm.futures_close(params)
def get_last(self):
return self.lnm.futures_get_ticker()
def get_trades(self, type_trade):
params = {
'type': type_trade,
}
return self.lnm.futures_get_trades(params)