forked from dwy6626/ftx-lending-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (41 loc) · 1.39 KB
/
main.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
import os
import argparse
from dotenv import load_dotenv
import ccxt
load_dotenv()
API_KEY = os.getenv('FTX_API')
APY_SECRET = os.getenv('FTX_API_SECRET')
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--account', help='set subaccount, by default it use main account', default=None)
parser.add_argument('-c', '--coin', help='set coin to lend, default is USDT', default='USDT')
parser.add_argument('-r', '--rate', help='set lowest lending hour rate', default=1e-5) # ~ 8.76 % / year
if __name__ == '__main__':
args = parser.parse_args()
config = {
'apiKey': API_KEY,
'secret': APY_SECRET,
}
subaccount = args.account
if subaccount is not None:
config['headers'] = { 'FTX-SUBACCOUNT': subaccount }
client = ccxt.ftx(config)
# get balance
balances = client.fetch_balance()
coin = args.coin
for item in balances['info']['result']:
if item['coin'] == coin:
balance = item['total']
break
else:
print(balances)
raise Exception(f'result not found for {coin}')
# renew lending
body = {
"coin": coin,
"size": int(float(balance)), # take only integer part to avoid "Size too large" errors
"rate": args.rate
}
res = client.private_post_spot_margin_offers(body)
if not res['success']:
print(res.json())
raise Exception('lending fail')