diff --git a/README.md b/README.md index 8d624bb..52cfeeb 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ Therefore, you will agree upon your own fully responsibility at the very moment No personal data collect and/or usage is done in any way, that's why this `add-on` doesn't require any _"controversial"_ permission from your side. The only _sensitive scopes_ according to **Google** are: * `script.external_request` :: Needed to **fetch data from Binance API** into the spreadsheet (GET requests only). -* `script.scriptapp` :: Needed to **install and run 3 triggers** to keep data updated in the spreadsheet (every 1, 5 and 10 minutes). +* `script.scriptapp` :: Needed to **install and run triggers** to keep data updated in the spreadsheet. **NOTE:** This is an _open-source_ project, so you will always be available to keep and eye to the code and audit it. If you have any concerns, please feel free to open a ticket in the [issues](https://github.com/diegomanuel/binance-to-google-sheets/issues) section or email me. @@ -203,13 +203,12 @@ No other service acts as an intermediary between your Google spreadsheet and Bin **NOTE:** If you have any concerns, please feel free to open a ticket in the [issues](https://github.com/diegomanuel/binance-to-google-sheets/issues) section or email me. -## Binance Account - Get 5% discount on fees! +## Binance Account - Get 10% discount on fees! Don't you have a **Binance** account yet? -Register using the **referal link** below and get a **5% discount on fees** for **all** your trades! +Register using the **referal link** below and get a **10% discount on fees** for **all** your trades! -[**https://www.binance.com/en/register?ref=NJE1D9CS**](https://www.binance.com/en/register?ref=NJE1D9CS) -Join to Binance! +[**https://www.binance.com/en/register?ref=SM93PRAV**](https://www.binance.com/en/register?ref=SM93PRAV) ## Enjoy - Donate - Buy me a beer! =] diff --git a/img/binance-join.png b/img/binance-join.png deleted file mode 100644 index 8709e24..0000000 Binary files a/img/binance-join.png and /dev/null differ diff --git a/misc/config.gs b/misc/config.gs index 41190ce..b4d615e 100644 --- a/misc/config.gs +++ b/misc/config.gs @@ -3,7 +3,7 @@ */ const DEBUG = false; -const VERSION = "v0.3.1"; +const VERSION = "v0.3.2"; const REPO_URL = "https://github.com/diegomanuel/binance-to-google-sheets"; const API_KEY_NAME = "BIN_API_KEY"; const API_SECRET_NAME = "BIN_API_SECRET"; diff --git a/misc/scheduler.gs b/misc/scheduler.gs index 8198e7e..94809d0 100644 --- a/misc/scheduler.gs +++ b/misc/scheduler.gs @@ -4,6 +4,7 @@ function BinScheduler(OPTIONS) { OPTIONS = OPTIONS || {}; // Init options const SCHEDULES_PROP_NAME = "BIN_SCHEDULER_ENTRIES"; + const RESCHEDULES_PROP_NAME = "BIN_SCHEDULER_ENTRIES_RETRY"; const LAST_RUN_PROP_NAME = "BIN_SCHEDULER_LAST_RUN"; return { @@ -18,6 +19,7 @@ function BinScheduler(OPTIONS) { setSchedule, cleanSchedules, rescheduleFailed, + clearFailed, isStalled }; @@ -81,6 +83,10 @@ function BinScheduler(OPTIONS) { * Returns the scheduled interval for given operation (or all schedules if no operation given) */ function getSchedule(operation) { + const rescheduled = _getRescheduled(); + if (operation && rescheduled[operation]) { // This operation failed before and was re-sheduled! + return rescheduled[operation]; + } const props = _getDocPropService().getProperty(SCHEDULES_PROP_NAME); const schedules = props ? JSON.parse(props) : {}; return operation ? schedules[operation] : schedules; @@ -106,10 +112,29 @@ function BinScheduler(OPTIONS) { } /** - * Re-schedule failed executions so they can be retried ASAP (at 1 minute trigger) + * Re-schedule failed execution for given operation so it can be retried ASAP (at 1m trigger) */ function rescheduleFailed(operation) { - // @TODO WIP! + const reschedules = _getRescheduled(); // Get all current re-scheduled operations + reschedules[operation] = "1m"; // Retry this operation at 1m trigger! + Logger.log("Setting new retry schedule for: "+operation); + Logger.log("Updated re-schedules: "+JSON.stringify(reschedules)); + return _getDocPropService().setProperty(RESCHEDULES_PROP_NAME, JSON.stringify(reschedules)); + } + + /** + * Clears failed execution schedule for given operation (if any) + * NOTE: This function could cause problems on parallel executions! + */ + function clearFailed(operation) { + const reschedules = _getRescheduled(); // Get all current re-scheduled operations + if (reschedules[operation]) { + delete reschedules[operation]; // Clear this operation! + Logger.log("Clearing retry schedule for: "+operation); + Logger.log("Updated re-schedules: "+JSON.stringify(reschedules)); + return _getDocPropService().setProperty(RESCHEDULES_PROP_NAME, JSON.stringify(reschedules)); + } + return false; } /** @@ -120,6 +145,11 @@ function BinScheduler(OPTIONS) { return !lastRun || lastRun < (new Date()).getTime() - 1000*60*5; // 5 minutes in milliseconds } + function _getRescheduled() { + const reprops = _getDocPropService().getProperty(RESCHEDULES_PROP_NAME); + return reprops ? JSON.parse(reprops) : {}; + } + /** * Updates the last run timestamp */ diff --git a/tasks/do-24h-stats.gs b/tasks/do-24h-stats.gs index 5326cab..83e7d03 100644 --- a/tasks/do-24h-stats.gs +++ b/tasks/do-24h-stats.gs @@ -15,7 +15,7 @@ function BinDo24hStats() { * Returns this function period (the one that's used by the refresh triggers) */ function period() { - return BinScheduler().getSchedule(tag()) || "5m"; + return BinScheduler().getSchedule(tag()) || "30m"; } /** @@ -26,6 +26,17 @@ function BinDo24hStats() { * @return The list of 24hs stats for given symbols */ function run(range_or_cell, options) { + const bs = BinScheduler(); + try { + bs.clearFailed(tag()); + return execute(range_or_cell, options); + } catch(err) { // Re-schedule this failed run! + bs.rescheduleFailed(tag()); + throw err; + } + } + + function execute(range_or_cell, options) { const ticker_against = options["ticker"]; Logger.log("[BinDo24hStats] Running.."); if (!range_or_cell) { // @TODO This limitation could be removed if cache is changed by other storage @@ -33,7 +44,7 @@ function BinDo24hStats() { } const lock = BinUtils().getUserLock(lock_retries--); if (!lock) { // Could not acquire lock! => Retry - return run(range_or_cell, options); + return execute(range_or_cell, options); } const opts = { diff --git a/tasks/do-account-info.gs b/tasks/do-account-info.gs index 9d97e77..1dfab0f 100644 --- a/tasks/do-account-info.gs +++ b/tasks/do-account-info.gs @@ -15,7 +15,7 @@ function BinDoAccountInfo() { * Returns this function period (the one that's used by the refresh triggers) */ function period() { - return BinScheduler().getSchedule(tag()) || "5m"; + return BinScheduler().getSchedule(tag()) || "15m"; } /** @@ -25,10 +25,21 @@ function BinDoAccountInfo() { * @return A list with account information */ function run(options) { + const bs = BinScheduler(); + try { + bs.clearFailed(tag()); + return execute(options); + } catch(err) { // Re-schedule this failed run! + bs.rescheduleFailed(tag()); + throw err; + } + } + + function execute(options) { Logger.log("[BinDoAccountInfo] Running.."); const lock = BinUtils().getUserLock(lock_retries--); if (!lock) { // Could not acquire lock! => Retry - return run(options); + return execute(options); } const opts = {CACHE_TTL: 55}; diff --git a/tasks/do-current-prices.gs b/tasks/do-current-prices.gs index 7ea2057..871f5c9 100644 --- a/tasks/do-current-prices.gs +++ b/tasks/do-current-prices.gs @@ -26,10 +26,21 @@ function BinDoCurrentPrices() { * @return The list of current prices for all or given symbols/tickers. */ function run(symbol_or_range, options) { + const bs = BinScheduler(); + try { + bs.clearFailed(tag()); + return execute(symbol_or_range, options); + } catch(err) { // Re-schedule this failed run! + bs.rescheduleFailed(tag()); + throw err; + } + } + + function execute(symbol_or_range, options) { Logger.log("[BinDoCurrentPrices] Running.."); const lock = BinUtils().getUserLock(lock_retries--); if (!lock) { // Could not acquire lock! => Retry - return run(symbol_or_range, options); + return execute(symbol_or_range, options); } const opts = {CACHE_TTL: 55, "public": true}; diff --git a/tasks/do-orders-done.gs b/tasks/do-orders-done.gs index 1b7fc05..a7b626d 100644 --- a/tasks/do-orders-done.gs +++ b/tasks/do-orders-done.gs @@ -28,6 +28,17 @@ function BinDoOrdersDone() { * @return The list of all current done orders for all or given symbols/tickers. */ function run(range_or_cell, options) { + const bs = BinScheduler(); + try { + bs.clearFailed(tag()); + return execute(range_or_cell, options); + } catch(err) { // Re-schedule this failed run! + bs.rescheduleFailed(tag()); + throw err; + } + } + + function execute(range_or_cell, options) { const ticker_against = options["ticker"]; const limit = _getMaxItems(options); // Get max items limit Logger.log("[BinDoOrdersDone] Running.."); @@ -36,7 +47,7 @@ function BinDoOrdersDone() { } const lock = BinUtils().getUserLock(lock_retries--); if (!lock) { // Could not acquire lock! => Retry - return run(range_or_cell, options); + return execute(range_or_cell, options); } const range = BinUtils().getRangeOrCell(range_or_cell) || []; diff --git a/tasks/do-orders-open.gs b/tasks/do-orders-open.gs index 2217187..4fc121b 100644 --- a/tasks/do-orders-open.gs +++ b/tasks/do-orders-open.gs @@ -26,10 +26,21 @@ function BinDoOrdersOpen() { * @return The list of all current open orders for all or given symbol/ticker. */ function run(symbol, options) { + const bs = BinScheduler(); + try { + bs.clearFailed(tag()); + return execute(symbol, options); + } catch(err) { // Re-schedule this failed run! + bs.rescheduleFailed(tag()); + throw err; + } + } + + function execute(symbol, options) { Logger.log("[BinDoOrdersOpen] Running.."); const lock = BinUtils().getUserLock(lock_retries--); if (!lock) { // Could not acquire lock! => Retry - return run(symbol, options); + return execute(symbol, options); } const opts = {CACHE_TTL: 55}; diff --git a/ui/menu.gs b/ui/menu.gs index 01beb87..3b63cf3 100644 --- a/ui/menu.gs +++ b/ui/menu.gs @@ -233,8 +233,8 @@ function showDonate() { "\n"+ "------------------------------------------------\n"+ "Don't you have a Binance account yet?\n"+ - "Register using the referal link below and get a 5% discount on fees for all your trades!\n"+ - "https://www.binance.com/en/register?ref=NJE1D9CS\n"+ + "Register using the referal link below and get a 10% discount on fees for all your trades!\n"+ + "https://www.binance.com/en/register?ref=SM93PRAV\n"+ "------------------------------------------------\n"+ "\n"+ "This software was published and released under the GPL-3.0 License.\n"+