forked from diegomanuel/binance-to-google-sheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gs
68 lines (62 loc) · 2.27 KB
/
main.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Binance to Google Sheets!
* Diego Manuel - [email protected]
* https://github.com/diegomanuel/binance-to-google-sheets
*/
/**
* Main formula wrapper to call supported operations.
*
* @param operation The operation tag to call.
* @param range_or_cell A range of cells or a single cell or a literal/string value.
* @param opts Additional options like the symbol/ticker to match against or an option list like "ticker: USDT, headers: false" (depending the called operation).
* @param force_refresh_cell Cells are automatically refreshed, but you can force it by passing any changing value here.
* @return Depends on the operation given.
* @customfunction
*/
function BINANCE(operation, range_or_cell, opts, force_refresh_cell) {
const options = BinUtils().parseOptions(opts);
if (DEBUG) {
Logger.log("OP: "+operation);
Logger.log("RANGE: "+JSON.stringify(range_or_cell));
Logger.log("OPTS: "+JSON.stringify(opts));
Logger.log("OPTIONS: "+JSON.stringify(options));
}
if (operation == "version") {
return VERSION;
}
if (BinDoLastUpdate().is(operation)) {
return BinDoLastUpdate().run();
}
if (BinDoCurrentPrices().is(operation)) {
return BinDoCurrentPrices().run(range_or_cell, options);
}
if (BinDoHistoricalData().is(operation)) {
return BinDoHistoricalData().run(range_or_cell, options);
}
if (BinDo24hStats().is(operation)) {
return BinDo24hStats().run(range_or_cell, options);
}
if (BinDoAccountInfo().is(operation)) {
return BinDoAccountInfo().run(range_or_cell, options);
}
if (BinDoOrdersOpen().is(operation)) {
return BinDoOrdersOpen().run(range_or_cell, options);
}
if (BinDoOrdersDone().is(operation)) {
return BinDoOrdersDone().run(range_or_cell, options);
}
if (BinDoOrdersTable().is(operation)) {
return BinDoOrdersTable().run(range_or_cell, options);
}
throw new Error("Unsupported operation given: '"+operation+"'");
}
/**
* This is just a dummy function, use `BINANCE` instead!
* It only serves to help to [R]efresh (the "R" from there) spreadsheet formulas
* by switching between `BINANCE` and `BINANCER`.
*
* @customfunction
*/
function BINANCER(operation, range_or_cell, opts, force_refresh_cell) {
return BINANCE(operation, range_or_cell, opts, force_refresh_cell);
}