BitBotFactory / MikaLendingBot

Automated lending on Cryptocurrency exchanges Poloniex and Bitfinex
http://poloniexlendingbot.readthedocs.io/en/latest/index.html
MIT License
1.11k stars 344 forks source link

Bot keeps canceling order on Bitfinex #444

Closed coulterj closed 7 years ago

coulterj commented 7 years ago

It might just be some setting I am overlooking, but the bot places the order and 2 min later cancels the order and continues to loop. Eventually, Bitfinex gets unhappy and gives this error -

2017-08-09 17:56:46 Error API Error 400: <html>
<head><title>400 Request Header Or Cookie Too Large</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>Request Header Or Cookie Too Large</center>
<hr><center>cloudflare-nginx</center>
</body>
</html>
 Requesting https://api.bitfinex.com/v1/offer/new
Caught API Error 400: <html>
<head><title>400 Request Header Or Cookie Too Large</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>Request Header Or Cookie Too Large</center>
<hr><center>cloudflare-nginx</center>
</body>
</html>
 Requesting https://api.bitfinex.com/v1/offer/new reading from exchange API, ignoring.
rstormsf commented 7 years ago

change your MarketAnalysis settings (analyze a day or 2 max)

rnevet commented 7 years ago

The bot placing orders and canceling them is the expected behavior, 2min is configured in the config.

@mahiso ideas?

coulterj commented 7 years ago

What setting is the 2 min?

rnevet commented 7 years ago

[BOT]

Sleeps between active iterations, time in seconds (1-3600)

sleeptimeactive = 60

Sleeps between inactive iterations, time in seconds (1-3600)

Set to the same value as sleeptimeactive to disable

sleeptimeinactive = 300

mahiso commented 7 years ago

It looks like a Bitfinex/Cloudflare error. @coulterj Did it happen once or more?

The Bitfinex API changes not the lending process/workflow. It's identical to Poloniex.

coulterj commented 7 years ago

Yes. I left it running today while at work. Just returned and had 52 identical errors. I didn't do any lending today because of it...

coulterj commented 7 years ago

Ok, if I disable the Market Analysis, the errors seem to go away.

utdrmac commented 7 years ago

Just going to jump in here and confirm that with Bitfinex the amount of 'Canceled orders' is significantly higher than poloniex, with no change in config parameters (other than API keys). In the last 6 hours, there are 79 log entries:

2017-08-10 15:14:06 Canceling ETH order... Loan offer canceled (0.1868 @ 0.0080%).

Are these canceled because nobody has taken them and the best-rate has changed?

rnevet commented 7 years ago

@utdrmac The bot always cancels any orders not taken, on every loop, it was never optimized to keep loans offers that are still relevant.

Only change that I see is that the logging is more verbose, before the bot would only indicate it is canceling "all offers". It could be that currently there is less demand for loans (as interest rates also show) and therefore we are seeing more offers being canceled and placed again.

mahiso commented 7 years ago

@utdrmac @rnevet I changed the text only, not the process of cancelling. Its another marked and the build of lending book on exchanges are different. Therefore some need to play with config (gap values, lendingstyle)

But this has imo nothing to do with @coulterj 's issue. @coulterj Could you please provide me with your config file? Remove the api key/secret before!

coulterj commented 7 years ago

Here you go. I will get the error 95% of the time if Market Analsys is on. I had that turned off last night, and only received the error 3 tims.

Also, if you see any settings that would make it better, let me know. I have been playing around with the setting to see if it helps the errors.

[BITFINEX]
# Full list of supported currencies
all_currencies = USD,BTC,ETH,ETC,ZEC,XMR,LTC,DSH,IOT,EOS,BCH

[BOT]
#Sleeps between active iterations, time in seconds (1-3600)
sleeptimeactive = 240

#Sleeps between inactive iterations, time in seconds (1-3600)
#Set to the same value as sleeptimeactive to disable
sleeptimeinactive = 300

#Timeout in seconds, the bot shall wait for a response during each request
#timeout = 30

#Minimum daily lend rate in percent (0.0031-5)
#Setting to 0.0031 is about 1% a year, not worth it.
mindailyrate = 0.005

#Maximum lending rate. 2% is good choice because it's default at margin trader interface.
#5% is the maximum rate accepted by the exchange (0.003-5)
maxdailyrate = 5

#The number of offers to split the available balance across the [gaptop, gapbottom] range. (1-20)
spreadlend = 3

#The depth of lendbook 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 to skip dust offers.
# Gap modes: Raw, RawBTC, Relative
gapMode = Relative
gapbottom = 40
gaptop = 150

#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 (0.003-5)
# Poloniex max lending period: 60 days
# Bitfinex max lending period: 30 days
xdaythreshold = 0.2
xdays = 30

#Auto-transfer of funds from exchange to lending balance.
#Enter ALL to transfer all coins, enter ACTIVE to transfer any coins you have in your lending account when the bot starts, these can be mixed.
#The currencies you enter below (comment it out to disable entirely, just leaving empty will result in an error) will be automatically transferred from your exchange balance to your lending balance whenever you deposit them.
#transferableCurrencies = STR,BTC,BTS,CLAM,DOGE,DASH,LTC,MAID,XMR,XRP,ETH,FCT
#transferableCurrencies = USD,BTC,ETH,ETC,ZEC,XMR,LTC,DSH,IOT,EOS

#Minimum loan size, the minimum size of offers to make, bigger values prevent the bot from loaning small available amounts but reduce loan fragmentation.
minloansize = 0.01

#Keep Stuck Orders - Sometimes an order gets partially filled. When this happens it may leave the remainder of your coin under the set minloansize.
#If this happens, KeepStuckOrders will keep your order where it is so maybe it can be filled. Otherwise it will be canceled and held until orders expire.
keepstuckorders = True

#Hide coins - Instead of keeping your coins lent out at minlendrate when it is not met, the bot will hold them and wait for the rate to surpass it.
hideCoins = False

#End date for lending, bot will try to make sure all your loans are done by this date so you can withdraw or do whatever you need.
#Uncomment to enable.
#Format: YEAR,MONTH,DAY
#endDate = 2016,12,25

#Raw maximum amount to lend if under maxtolendrate.
#If set to 0 or commented: the bot will check for maxpercenttolend.(0+)
#maxtolend = 0

#Maximum percent to lend if under maxtolendrate.
#If set to 0 or commented: the bot will lend 100% of your balance regardless of rate. (0-100)
#maxpercenttolend = 0

#Max to lend conditional rate.
#If set to more than 0: the maxtolend or maxpercenttolend will be used when the rate is less than or equal to the maxtolendrate.
#If set to 0 or commented: the bot will use the maxtolend or maxpercenttolend all the time. (0.0031-5)
#maxtolendrate = 0

# Local Market Analysis: Choose which coins to record the market of in order to analyse them and compute a recommended lending rate.
# Enter ALL to analyse all coins, enter ACTIVE to analyse the markets of any coins you have in your lending account when the bot starts, these can be mixed.
#analyseCurrencies = BCH,BTC
# Choose how long to keep market data. (In days) (1-365)
#analyseMaxAge = 1
# Choose how often to record a market's rate. (In seconds.) (10-3600)
#analyseUpdateInterval = 60
# Choose how aggressive to lend at based on a market's performance. (As a percentile of the market's rate.) (1-99)
# Recommendations: Conservative = 50, Moderate = 75, Aggressive = 90, Very Aggressive = 99
#lendingStyle = 75

#Syntax: ["COIN:mindailyrate:maxactiveamount:maxtolend:maxpercenttolend:maxtolendrate",...]
#If maxactive amount is 0: stop lending this coin. in the future you'll be able to limit amount to be lent.
#If maxtolend is 0: check for maxpercenttolend.
#If maxpercenttolend is 0: 100% is going to be lent.
#If maxtolendrate is set to more than 0: the maxtolend or maxpercenttolend will be used when then rate is less or equal to the maxtolendrate. if set to 0 the bot will use the maxtolend or maxpercenttolend all the time.
# Please configure via the coinconfig line below OR individual coins in the [BTC], [CLAM], etc section. NOT both.
# coinconfig takes precedence
#coinconfig = ["BTC:0.18:1:0:0:0","CLAM:0.6:1:0:0:0"]

#This option creates a json log file instead of console output which includes the most recent status.
#Uncomment both jsonfile and jsonlogsize to enable.
#Keep this in the default location if you want to use the webserver.
jsonfile = www/botlog.json

#Limits the amount of log lines to save.
jsonlogsize = 200

#Enables a webserver for the www folder, in order to easily use the lendingbot.html with the .json log.
startWebServer = true

#Customize the IP and port that the webserver is hosted on. Defaults respectively to 0.0.0.0 and 8000
#0.0.0.0 will point to your default IP (Local IP on LAN as well as localhost), set to 127.0.0.1 if you want it to be only accessible by host computer.
#Do not set to a reserved port
#Advanced users only.
#customWebServerAddress = 0.0.0.0
#customWebServerPort = 8000

#Customize or select the desired template for the webserver. Default to 'www'.
#customWebServerTemplate = www

#The currency that the HTML Overview will present the earnings summary in.
#Options are BTC, USDT (USD on Bitfinex), ETH or anything as long as it has a direct BTC market. The default is BTC.
outputCurrency = USD

#Plugins allow extending Bot functionality with extra features.
plugins = AccountStats

# Currencies can be configured here, or in the coinconfig. Coinconfig takes precedence.
#[BTC]
#minloansize = 0.01
#mindailyrate = 0.18
#maxactiveamount = 1
#maxtolend = 0
#maxpercenttolend = 0
#maxtolendrate = 0

#[CLAM]
#minloansize = 1
#mindailyrate = 0.6
#maxactiveamount = 1
#maxtolend = 0
#maxpercenttolend = 0
#maxtolendrate = 0

[notifications]
notify_new_loans = False
notify_tx_coins = False
notify_xday_threshold = False
notify_summary_minutes = 0
notify_caught_exception = False

email = False
email_login_address = me@gmail.com
email_login_password = secretPassword
email_smtp_server = smtp.gmail.com
email_smtp_port = 465
email_smtp_starttls = False
email_to_addresses = me@gmail.com,you@gmail.com

slack = False
slack_token = 1234567890abcdef
slack_channels = #cryptocurrency,@someUser

telegram = False
telegram_bot_id = 1234567890abcdef
telegram_chat_ids = @polopolo,@cryptocurrency

pushbullet = False
pushbullet_token = 1234567890abcdef
pushbullet_deviceid = 1234567890abcdef

irc = False
irc_host = irc.freenode.net
irc_port = 6667
irc_nick = LendingBot
irc_ident = ledningbot
irc_realname = Poloniex lending bot
irc_target = #bitbotfactory
utdrmac commented 7 years ago

@coulterj oh man. code fence that next time. my eyes! :)

rnevet commented 7 years ago

@utdrmac fenced so your eyes aren't offended. :)

bgits commented 7 years ago

Any idea why market analysis would be causing this error? I have received it as well.

coulterj commented 7 years ago

I played with the settings yesterday. My errors went away when I removed the ticker BCH.

nielash commented 7 years ago

Hey guys--total n00b programmer here, but I think I may have figured this out, or at least found a clue.

In modules/Bitfinex.py on line 224, I tried changing

"rate": str(lending_rate * 36500),

to:

"rate": str(round(float(lending_rate),10) * 36500),

And that seems to have solved it. I think it's because (as the error message seems to indicate) the payload for 'offer/new' was too long, and rounding the rate to 10 decimal places prevents that.

I'm not sure if this is the root of the problem or if I simply treated a symptom, but I wanted to mention it here in case it's helpful.

Orteko commented 7 years ago

I think @nielash has found the culprit - I can confirm that rounding to 10 decimal places has made this issue go away for me.

rnevet commented 7 years ago

Please make a PR. :)

mike4001 commented 7 years ago

Thanks @nielash

This seems to have solved it :-)

laxdog commented 7 years ago

Fixed in #510

Merged to master