Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,35 @@ When you first run the script a default.cnf will be generated. Edit it with your

```
[API]

apikey = YourAPIKey
secret = YourSecret

[BOT]

#sleep between iterations, time in seconds
sleeptime = 60

#minimum daily lend rate in percent
mindailyrate = 0.04
mindailyrate = 0.01

#max rate. 2% is good choice because it's default at margin trader interface.
#5% is max to be accepted by the exchange
#max rate. 2% is good choice because it's default at margin trader interface. 5% is max to be accepted by the exchange
maxdailyrate = 2

#The number of offers to split the available balance across the [gaptop, gapbottom] range.
#The number of offers to split the available balance uniformly across the [gaptop, gapbottom] range.
spreadlend = 3

#The depth of lendbook (in percent of lendable balance) to move through
#before placing the first (gapbottom) and last (gaptop) offer.
#If gapbottom is set to 0, the first offer will be at the lowest possible rate.
#However some low value is recommended (say 10%) to skip dust offers.
gapbottom = 10
gaptop = 200
#The depth of lendbook (in percent of lendable balance) to move through before placing the first (gapbottom) and last (gaptop) offer.
#if gapbottom is set to 0, the first offer will be at the lowest possible rate. However some low value is recommended (say 10%) to skip dust offers
gapbottom = 1
gaptop = 100

#Daily lend rate threshold after which we offer lends for 60 days as opposed to 2.
#If set to 0 all offers will be placed for a 2 day period
sixtydaythreshold = 0.2
#Daily lend rate threshold after which we offer lends for X days as opposed to 2. If set to 0 all offers will be placed for a 2 day period
xdaythreshold = 0.1
xdays = 15

#custom config per coin, useful when closing positions etc.
#syntax: ["COIN:mindailyrate:maxactiveamount",...]
#syntax: [COIN:mindailyrate:maxactiveamount, ... COIN:mindailyrate:maxactiveamount]
#if maxactive amount is 0 - stop lending this coin. in the future you'll be able to limit amount to be lent.
#coinconfig = ["BTC:0.18:1","CLAM:0.6:1"]
```
Expand Down
30 changes: 20 additions & 10 deletions lendingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
[API]
apikey = YourAPIKey
secret = YourSecret

[BOT]
#sleep between iterations, time in seconds
sleeptime = 60
Expand All @@ -28,8 +27,9 @@
#if gapbottom is set to 0, the first offer will be at the lowest possible rate. However some low value is recommended (say 10%) to skip dust offers
gapbottom = 1
gaptop = 100
#Daily lend rate threshold after which we offer lends for 60 days as opposed to 2. If set to 0 all offers will be placed for a 2 day period
sixtydaythreshold = 0.2
#Daily lend rate threshold after which we offer lends for X days as opposed to 2. If set to 0 all offers will be placed for a 2 day period
xdaythreshold = 0.1
xdays = 15
#custom config per coin, useful when closing positions etc.
#syntax: [COIN:mindailyrate:maxactiveamount, ... COIN:mindailyrate:maxactiveamount]
#if maxactive amount is 0 - stop lending this coin. in the future you'll be able to limit amount to be lent.
Expand All @@ -52,7 +52,9 @@
spreadLend = int(config.get("BOT","spreadlend"))
gapBottom = Decimal(config.get("BOT","gapbottom"))
gapTop = Decimal(config.get("BOT","gaptop"))
sixtyDayThreshold = float(config.get("BOT","sixtydaythreshold"))/100
#sixtyDayThreshold = float(config.get("BOT","sixtydaythreshold"))/100
xDayThreshold = float(config.get("BOT","xdaythreshold"))/100
xDays = str(config.get("BOT","xdays"))

try:
coincfg = {} #parsed
Expand Down Expand Up @@ -125,9 +127,9 @@ def createLoanOffer(cur,amt,rate):
if float(amt) > 0.001:
rate = float(rate) - 0.000001 #lend offer just bellow the competing one
amt = "%.8f" % Decimal(amt)
if rate > sixtyDayThreshold:
days = '60'
if sixtyDayThreshold == 0:
if rate > xDayThreshold:
days = xDays
if xDayThreshold == 0:
days = '2'
if dryRun == False:
msg = bot.createLoanOffer(cur,amt,days,0,rate)
Expand All @@ -138,9 +140,17 @@ def cancelAndLoanAll():
if type(loanOffers) is list: #silly api wrapper, empty dict returns a list, which brakes the code later.
loanOffers = {}
if loanOffers.get('error'):
print loanOffers.get('error')
print 'You might want to edit config file (default.cnf) and put correct apisecret and key values'
exit(1)
print loanOffers.get('error')
print 'Error, cant get loan offers, you might have invalid api keys'
print 'Gonna try agian in 60 secs'
time.sleep(60)
loanOffers = bot.returnOpenLoanOffers('BTC')
if type(loanOffers) is list:
loanOffers = {}
if loanOffers.get('error'):
print loanOffers.get('error')
print 'You might want to edit config file (default.cnf) and put and put correct apisecret and key values'
exit(1)

onOrderBalances = {}
for cur in loanOffers:
Expand Down