Skip to content

Commit

Permalink
Adding pause support and updating donate addrs.
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomanuel committed Jan 6, 2024
1 parent 0072cf7 commit ae6b9a1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 25 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,11 @@ If your love is strong enough, feel free to share it with me! =D
I will much appreciate any contribution and support to keep working on it.
I have several ideas for new features, so much more could come!

You can send any token through the **Binance Smart Chain** (BSC/BEP20) to the address:
`0x1d047bc3e46ce0351fd0c44fc2a2029512e87a97`

But you can also use these networks:
* **BTC:** `bc1qanxn2ycp9em50hj5p7en6wxe962zj4umqvs7q9`
* **ETH:** `0x1d047bc3e46ce0351fd0c44fc2a2029512e87a97`
You can send any token to these network addresses:
* **BTC (SegWit):** `bc1quxsufu73vy3d2ehpjddgxl9pjs2wygltmkryd0`
* **ETH (ERC20) | BNB (BSC/BEP20) | MATIC (Polygon):** `0x25307eea23642c03e3e2a522624f8181870afb18`
* **TRX (TRC20):** `THu2mwfkFXSs2jFuZDxuMBKd22Wjkp3zwv`
* **SOL (Solana):** `3c7g2DP1cgth1rxrF5iis5RjkWWZKavACaoJ1JTvZpL2`

---

Expand Down
2 changes: 1 addition & 1 deletion config.gs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const USE_PROXY = false;

// Other settings
let DEBUG = false; // If enabled, will output more logs to the AppScript console
const VERSION = "v0.5.4";
const VERSION = "v0.5.5";
const REPO_URL = "https://github.com/diegomanuel/binance-to-google-sheets";
const SPOT_API_URL = "https://api.binance.com";
const FUTURES_API_URL = "https://fapi.binance.com";
Expand Down
72 changes: 66 additions & 6 deletions misc/scheduler.gs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function BinScheduler(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";
const PAUSED_PROP_NAME = "BIN_SCHEDULER_PAUSED";

return {
init,
Expand All @@ -15,11 +16,14 @@ function BinScheduler(OPTIONS) {
run15m,
run30m,
run60m,
runOrdersTable,
getSchedule,
setSchedule,
cleanSchedules,
rescheduleFailed,
clearFailed,
isPaused,
setPaused,
isStalled
};

Expand All @@ -36,47 +40,84 @@ function BinScheduler(OPTIONS) {
function run1m() {
_updateLastRun();
BinDoOrdersTable().init(); // Initialize orders table sheets (if any)
BinUtils().forceRefreshSheetFormulas("1m");
if (isPaused()) {
Logger.log("Scheduler is paused, skipping '1m' call..");
} else {
BinUtils().forceRefreshSheetFormulas("1m");
}
}

/**
* Runs the scheduled functions for 5m
*/
function run5m() {
_updateLastRun();
BinUtils().forceRefreshSheetFormulas("5m");
if (isPaused()) {
Logger.log("Scheduler is paused, skipping '5m' call..");
} else {
BinUtils().forceRefreshSheetFormulas("5m");
}
}

/**
* Runs the scheduled functions for 10m
*/
function run10m() {
_updateLastRun();
BinUtils().forceRefreshSheetFormulas("10m");
if (isPaused()) {
Logger.log("Scheduler is paused, skipping '10m' call..");
} else {
BinUtils().forceRefreshSheetFormulas("10m");
}
}

/**
* Runs the scheduled functions for 15m
*/
function run15m() {
_updateLastRun();
BinUtils().forceRefreshSheetFormulas("15m");
if (isPaused()) {
Logger.log("Scheduler is paused, skipping '15m' call..");
} else {
BinUtils().forceRefreshSheetFormulas("15m");
}
}

/**
* Runs the scheduled functions for 30m
*/
function run30m() {
_updateLastRun();
BinUtils().forceRefreshSheetFormulas("30m");
if (isPaused()) {
Logger.log("Scheduler is paused, skipping '30m' call..");
} else {
BinUtils().forceRefreshSheetFormulas("30m");
}
}

/**
* Runs the scheduled functions for 60m
*/
function run60m() {
_updateLastRun();
BinUtils().forceRefreshSheetFormulas("1h");
if (isPaused()) {
Logger.log("Scheduler is paused, skipping '1h' call..");
} else {
BinUtils().forceRefreshSheetFormulas("1h");
}
}

/**
* Runs the scheduled functions for OrdersTable
*/
function runOrdersTable() {
_updateLastRun();
if (isPaused()) {
Logger.log("Scheduler is paused, skipping 'orders table poll' call..");
}
else if (BinSetup().areAPIKeysConfigured()) {
BinDoOrdersTable().execute();
}
}

/**
Expand Down Expand Up @@ -137,6 +178,25 @@ function BinScheduler(OPTIONS) {
return false;
}

/**
* Returns true if the scheduler is paused
*/
function isPaused() {
return _getDocPropService().getProperty(PAUSED_PROP_NAME) == "true";
}

/**
* Sets the paused status
*/
function setPaused(paused) {
const doc = _getDocPropService();
doc.setProperty(PAUSED_PROP_NAME, paused ? "true" : "false");
// Also clean the re-schedules (no matter the pause status)
doc.setProperty(RESCHEDULES_PROP_NAME, JSON.stringify({}));
Logger.log("Scheduler paused status set to: "+isPaused());
return paused;
}

/**
* Returns true if the scheduler didn't run in the last 5 minutes
*/
Expand Down
24 changes: 19 additions & 5 deletions ui/menu.gs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ function BinMenu(ui) {
*/
function addMenuItems(menu) {
const is_ready = BinSetup().isReady();
const is_paused = BinScheduler().isPaused();

if (!is_ready) { // Add-on is not ready (unauthorized or BinScheduler is stalled or never run)
menu.addItem("Authorize add-on!", "authorizeMe");
} else {
menu.addItem("Refresh", "forceRefreshFormulas");
menu.addItem((is_paused?"Resume":"Pause")+" auto-refresh", "togglePaused");
}
menu.addSeparator()
.addItem("Show API Last Update", "showAPILastUpdate")
Expand Down Expand Up @@ -108,6 +110,18 @@ function forceRefreshFormulas() {
utils.forceRefreshSheetFormulas(); // Refresh'em all!
}

/**
* Toggles the pause state
*/
function togglePaused() {
const utils = BinUtils();
const scheduler = BinScheduler();
const is_paused = scheduler.isPaused();
scheduler.setPaused(!is_paused);
utils.toast("Auto-refresh was "+(is_paused?"resumed":"paused")+"!", "", 5);
utils.refreshMenu(); // Refresh main menu items
}

/**
* Triggers the modal to enable/authorize the add-on.
* If this function gets executed, it means that the user has authorized the add-on!
Expand Down Expand Up @@ -258,12 +272,12 @@ function showDonate() {
"I have several ideas for new features, so much more could come!\n"+
"\n"+
"\n"+
"You can send any token through the Binance Smart Chain (BSC/BEP20) to:\n"+
"0x1d047bc3e46ce0351fd0c44fc2a2029512e87a97\n"+
"You can send any token to these network addresses:\n"+
"\n"+
"But you can also use these networks:\n"+
"BTC: bc1qanxn2ycp9em50hj5p7en6wxe962zj4umqvs7q9\n"+
"ETH: 0x1d047bc3e46ce0351fd0c44fc2a2029512e87a97\n"+
"BTC (SegWit): bc1quxsufu73vy3d2ehpjddgxl9pjs2wygltmkryd0\n"+
"ETH (ERC20) | BNB (BSC/BEP20) | MATIC (Polygon): 0x25307eea23642c03e3e2a522624f8181870afb18\n"+
"TRX (TRC20): THu2mwfkFXSs2jFuZDxuMBKd22Wjkp3zwv\n"+
"SOL (Solana): 3c7g2DP1cgth1rxrF5iis5RjkWWZKavACaoJ1JTvZpL2\n"+
"\n"+
"------------------------------------------------\n"+
"Don't you have a Binance account yet?\n"+
Expand Down
8 changes: 1 addition & 7 deletions ui/setup.gs
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,8 @@ function doRefresh30m(event) {
function doRefresh1h(event) {
_callScheduler(event, "60m");
}

function doTablesPoll(event) {
if (DEBUG) {
Logger.log("EVENT: "+JSON.stringify(event));
}
if (BinSetup().areAPIKeysConfigured()) {
BinDoOrdersTable().execute();
}
_callScheduler(event, "OrdersTable")
}

function _callScheduler(event, every) {
Expand Down

0 comments on commit ae6b9a1

Please sign in to comment.