From 13d6cb10a1c064d5930456497c15bee1fe89a255 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 20 Jul 2018 12:55:02 -0500 Subject: [PATCH] Increase Bitfinex API sleeps (#632) * merge upstream (#1) * Plugin Graphs: make history file configurable (#518) * make history file configurable * removed extra paren * Reduce chances of nonce collisions (#520) * Check currency is being analysed before trying to get a rate for it (#528) * Check currency is being analysed before trying to get a rate for it * Fix Capital C in "Lending.py", line 85 (#529) * Resolves Issue 526 (#533) * add dashboard link in navbar * aggregate correct column * Fix recorded data when no rate offers exist, don't print traceback unless ma_debug is on (#531) * Return a dict of all currencies even if balance is 0 (#540) * Log bot "version" on error handling (#543) * When logging an exception also log the number of commits on current branch, will allow to easily identify if reporter is on master and updated. * Move get_git_version to Data module * Change fallback version number to 3.0.0 * A safer approach for handling errors in the git call * Html response fix (#546) * prevent exception overloading when receiving an html response error * prevent unicode from throwing an exception * File log using ensure_ascii * Change min/max daily lend rate depending on exchange (and simplify xdays) (#547) * Change min/max daily lend rate depending on exchange * Lending.py Simplify code with xdays and max/min daily rate * Update Lending.py * Update Lending.py * Bitfinex sync fix (#555) * Sync Bitfinex API requests completely * Update test * Update test * ERR_RATE_LIMIT_fix (#549) * Return a dict of all currencies even if balance is 0 * Sleep and reduce requests per min if we get ERR_RATE_LIMIT * Reduce request window to 1 sec * Move the timers to millisecond resolution in the coach, MA changes times now when it catches 429 * Comments, logs, fix exception * Don't change api request times unless using bitfinex * Update polo coach to milliseconds * Catch 429 at top level and more sensible api_req_period calc * PEP-8 * Unrelated bug I found from ERR_RATE_LIMIT_fix * Sync Bitfinex API requests completely * Update test * Update test * Messed up the merge from bitfinex_sync_fix * Move timer change methods to base class and catch 429 at API level * Add poloniex timer changes * Make sure to re-raise the error, sleep in the MA module not the API. * Converted a tab to spaces * Added Blacklist Option & enforce whitelist (#570) * Added Blacklist Option for Lending * Mistake in Configuration.py * Optimized config description * Optimized description * Minimized api requests by using blacklist_currencies and all_currencies parameter * Removed BTG from all_currencies * Changed to more simple blacklist and changed documentation * Changed default config * Changed configuration description * Addition of a Slack Username parameter as a configuration option. (#576) * Addition of a Slack Username parameter as a configuration option. * Backward compatibility for configs which lack a slack_username * split multiline message into multiple irc messages (#582) the irc lib in use doesn't support sending multiline messages. this patch splits messages containing newline characters into multiple irc messgaes to resolve issue: https://github.com/BitBotFactory/poloniexlendingbot/issues/565 * Discover minimum amount in EUR (#594) I think this solves #589. * Use docker image with pandas and numpy already installed (#593) * Fixes absolute reference This way the webpage will work even if under a directory, otherwise it redirects to the root directory. * Use FRR on bitfinex as min_daily_rate (#554) * Return a dict of all currencies even if balance is 0 * Sleep and reduce requests per min if we get ERR_RATE_LIMIT * Reduce request window to 1 sec * Move the timers to millisecond resolution in the coach, MA changes times now when it catches 429 * Comments, logs, fix exception * Don't change api request times unless using bitfinex * Update polo coach to milliseconds * Catch 429 at top level and more sensible api_req_period calc * Use FRR for min_daily_rate * Missing from last commit * PEP-8 * Config and docs for frr as min * Use config for frr and use configured min if higher * Unrelated bug I found from ERR_RATE_LIMIT_fix * Unrelated bug I found from ERR_RATE_LIMIT_fix * Sync Bitfinex API requests completely * Update test * Update test * Messed up the merge from bitfinex_sync_fix * Messed up the merge from bitfinex_sync_fix * Move timer change methods to base class and catch 429 at API level * Add poloniex timer changes * Make sure to re-raise the error, sleep in the MA module not the API. * Converted a tab to spaces * Added FRR Delta for Bitfinex * Added FRR Delta for Bitfinex * PEP-8 * Log when using FRR as min daily rate * Allow config to be picked up from 'BOT' section rather than just coin_cfg * Declare variables to allow global access * This is why we should use classes! * exchangeMax needs defined * add larger sleeps to prevent API bans * only display active coins in charts --- lendingbot.py | 2 +- modules/Bitfinex.py | 2 +- modules/ExchangeApi.py | 4 ++-- modules/MarketAnalysis.py | 2 ++ plugins/Charts.py | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lendingbot.py b/lendingbot.py index 00f6be30..179b795e 100755 --- a/lendingbot.py +++ b/lendingbot.py @@ -146,7 +146,7 @@ def new_getaddrinfo(*urlargs): log.log_error('IP has been banned due to many requests. Sleeping for {} seconds'.format(sum_sleep)) if Config.has_option('MarketAnalysis', 'analyseCurrencies'): if api.req_period <= api.default_req_period * 1.5: - api.req_period += 3 + api.req_period += 1000 if Config.getboolean('MarketAnalysis', 'ma_debug_log'): print("Caught ERR_RATE_LIMIT, sleeping capture and increasing request delay. Current" " {0}ms".format(api.req_period)) diff --git a/modules/Bitfinex.py b/modules/Bitfinex.py index ebf151ba..9ec0a101 100644 --- a/modules/Bitfinex.py +++ b/modules/Bitfinex.py @@ -20,7 +20,7 @@ def __init__(self, cfg, log): self.log = log self.lock = threading.RLock() self.req_per_period = 1 - self.default_req_period = 1000 # milliseconds, 1000 = 60/min + self.default_req_period = 5000 # milliseconds, 1000 = 60/min self.req_period = self.default_req_period self.req_time_log = RingBuffer(self.req_per_period) self.url = 'https://api.bitfinex.com' diff --git a/modules/ExchangeApi.py b/modules/ExchangeApi.py index 939c8bee..ce0570cc 100644 --- a/modules/ExchangeApi.py +++ b/modules/ExchangeApi.py @@ -52,8 +52,8 @@ def limit_request_rate(self): @abc.abstractmethod def increase_request_timer(self): - if self.req_period <= self.default_req_period * 1.5: - self.req_period += 3 + if self.req_period <= self.default_req_period * 3.0: + self.req_period += 500 @abc.abstractmethod def decrease_request_timer(self): diff --git a/modules/MarketAnalysis.py b/modules/MarketAnalysis.py index 05ff8321..0fe7ed98 100644 --- a/modules/MarketAnalysis.py +++ b/modules/MarketAnalysis.py @@ -83,6 +83,7 @@ def __init__(self, config, api): except Exception as cur_ex: raise Exception("ERROR: You entered an incorrect currency: '{0}' to analyse the market of, please " "check your settings. Error message: {1}".format(currency, cur_ex)) + time.sleep(2) def run(self): """ @@ -182,6 +183,7 @@ def update_market_thread(self, cur, levels=None): market_data.append("0.1") market_data.append('0') # Percentile field not being filled yet. self.insert_into_db(db_con, market_data) + time.sleep(5) def insert_into_db(self, db_con, market_data, levels=None): if levels is None: diff --git a/plugins/Charts.py b/plugins/Charts.py index 70f0a1c7..7f9a90b3 100644 --- a/plugins/Charts.py +++ b/plugins/Charts.py @@ -31,6 +31,7 @@ def before_lending(self): def after_lending(self): if self.get_db_version() > 0 and self.last_dump + self.dump_interval < sqlite3.time.time(): + self.log.log("Dumping Charts Data") self.dump_history() self.last_dump = sqlite3.time.time()