├── icon384.png ├── config.gs ├── GetAccount.gs ├── KeepStaking.gs ├── README.md └── KeepLending.gs /icon384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/M-Igashi/FTX-GAS-Tools/HEAD/icon384.png -------------------------------------------------------------------------------- /config.gs: -------------------------------------------------------------------------------- 1 | /* 2 | First execute this function once with your apikey and apisecret to set them as script property. You can delete the value after it. 3 | 最初にapiキーとシークレットを入れてこの関数を一度実行。実行したあとは値は削除していい。 4 | */ 5 | 6 | 7 | function myFunction() { 8 | var keys = {apikey: 'xxxxxxxxxxxx', apisecret: 'yyyyyyyyyyy'}; 9 | PropertiesService.getScriptProperties().setProperties(keys); 10 | } 11 | 12 | 13 | var uri = 'https://ftx.com' 14 | var basepath = '/api' 15 | var keys = PropertiesService.getScriptProperties().getProperties(); 16 | -------------------------------------------------------------------------------- /GetAccount.gs: -------------------------------------------------------------------------------- 1 | function GetAccount(){ 2 | var ts = String(Date.now()); 3 | var method = 'GET'; 4 | var command = basepath + "/account"; 5 | var sign = toHexString(Utilities.computeHmacSha256Signature(ts + method + command, keys.apisecret)); 6 | function toHexString(byteArray) { 7 | return Array.from(byteArray, function(byte) { 8 | return ('0' + (byte & 0xFF).toString(16)).slice(-2); 9 | }).join('') 10 | } 11 | var header = { 12 | 'FTX-KEY' : keys.apikey, 13 | 'FTX-TS' : ts, 14 | 'FTX-SIGN' : sign 15 | }; 16 | var options = { 17 | 'method' : method, 18 | 'headers' : header 19 | }; 20 | var account = UrlFetchApp.fetch(uri + command, options); 21 | 22 | console.log(JSON.parse(account)); 23 | } 24 | -------------------------------------------------------------------------------- /KeepStaking.gs: -------------------------------------------------------------------------------- 1 | function KeepStaking(){ 2 | 3 | // suggest coin name/ticker ステーキングし続けるコインのティッカーを指定 4 | var coin = "SRM_LOCKED"; 5 | 6 | var target = GetBalance().find((v) => v.coin === coin) 7 | 8 | var size = Math.floor(target.free*10000000)/10000000; 9 | 10 | var data = {"coin": coin, "size": size}; 11 | var payload =JSON.stringify(data); 12 | 13 | var ts = String(Date.now()); 14 | var method = "POST"; 15 | var command = basepath + "/srm_stakes/stakes"; 16 | var sign = toHexString(Utilities.computeHmacSha256Signature(ts + method + command + payload, keys.apisecret)); 17 | function toHexString(byteArray) { 18 | return Array.from(byteArray, function(byte) { 19 | return ('0' + (byte & 0xFF).toString(16)).slice(-2); 20 | }).join('') 21 | } 22 | var header = { 23 | 'FTX-KEY' : keys.apikey, 24 | 'FTX-TS' : ts, 25 | 'FTX-SIGN' : sign 26 | }; 27 | var options = { 28 | 'method' : method, 29 | 'headers' : header, 30 | 'contentType': 'application/json', 31 | 'payload' : payload 32 | }; 33 | 34 | var result = UrlFetchApp.fetch(uri + command, options); 35 | 36 | Logger.log(result); 37 | } 38 | 39 | 40 | 41 | function GetBalance(){ 42 | var ts = String(Date.now()); 43 | var method = 'GET'; 44 | var command = basepath + "/wallet/balances"; 45 | var sign = toHexString(Utilities.computeHmacSha256Signature(ts + method + command, keys.apisecret)); 46 | function toHexString(byteArray) { 47 | return Array.from(byteArray, function(byte) { 48 | return ('0' + (byte & 0xFF).toString(16)).slice(-2); 49 | }).join('') 50 | } 51 | var header = { 52 | 'FTX-KEY' : keys.apikey, 53 | 'FTX-TS' : ts, 54 | 'FTX-SIGN' : sign 55 | }; 56 | var options = { 57 | 'method' : method, 58 | 'headers' : header 59 | }; 60 | ; 61 | 62 | return JSON.parse(UrlFetchApp.fetch(uri + command, options)).result 63 | 64 | } 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FTX tools in Google Apps Script 2 | Google Apps Scripts that keep staking and lending max available funds in FTX. 3 | ## Motivation 4 | Compound yield is important to increase your money, but FTX staking and lending should be flexible according to your asset management and strategy. By using GAS triger, you can easily start/stop compound earning from console. The code is pure stand alone GAS, so that you do not need to import any 3rd party libraries or wrappers. 5 | # How to start 6 | - Go to https://script.google.com/home and create a new project. 7 | - Copy all .gs files in this repository and Paste them to the new project. (delete unnecessary function code before pasting) 8 | - Give your FTX API key and secret in config.gs, and run the function. Once running it, you can delete the key and secret in the script for security. Those works from GAS hidden property. 9 | - During executing GAS function, you may be asked to authorize execution by Google. Simply press authorize. 10 | ## KeepLending 11 | In the file, there are two functions. KeepLending is the main function of this file. Make sure KeepLending is selected. 12 | - Input the ticker you would like to keep lending in `var coin = "BTC"`. ie. BTC for Bitcoin, USD for USD. 13 | - Run the function for testing. 14 | - You can copy KeepLending for multiple coin. Rename `function KeepLending(){` to `function KeepLending_USD(){` for example and paste just under the main function. 15 | - Go to Triger in the menu left hand side, and set 1h or 30min time driven triger for KeepLending functions you wish. 16 | - You can suspend the trigers in any time, so that execution is canceled and you can use accumulated asset within next hour timing. 17 | ## KeepStaking 18 | WIP. Due to georestriction of FTX API, I do not have workaround so far. 19 | # Donation 20 | SOL or SPL tonkens are welcome. Please send your pocket pennies to `FS1dcQnnfSnT2qY6FgxxafVCnhXhALeNzEkrwdTJVEXc` . 21 | -------------------------------------------------------------------------------- /KeepLending.gs: -------------------------------------------------------------------------------- 1 | function KeepLending(){ 2 | 3 | // suggest coin name/ticker レンディングし続けるコインのティッカーを指定 4 | var coin = "BTC"; 5 | 6 | var target = GetBalance().find((v) => v.coin === coin) 7 | 8 | var size = Math.floor(target.total*1000000)/1000000; 9 | var rate = 1e-6; 10 | var data = {"coin": coin, "size": size, "rate": rate}; 11 | var payload =JSON.stringify(data); 12 | 13 | var ts = String(Date.now()); 14 | var method = "POST"; 15 | var command = basepath + "/spot_margin/offers"; 16 | var sign = toHexString(Utilities.computeHmacSha256Signature(ts + method + command + payload, keys.apisecret)); 17 | function toHexString(byteArray) { 18 | return Array.from(byteArray, function(byte) { 19 | return ('0' + (byte & 0xFF).toString(16)).slice(-2); 20 | }).join('') 21 | } 22 | var header = { 23 | 'FTX-KEY' : keys.apikey, 24 | 'FTX-TS' : ts, 25 | 'FTX-SIGN' : sign 26 | }; 27 | var options = { 28 | 'method' : method, 29 | 'headers' : header, 30 | 'contentType': 'application/json', 31 | 'payload' : payload 32 | }; 33 | 34 | 35 | var result = UrlFetchApp.fetch(uri + command, options); 36 | 37 | Logger.log(result); 38 | } 39 | 40 | 41 | function GetBalance(){ 42 | var ts = String(Date.now()); 43 | var method = 'GET'; 44 | var command = basepath + "/wallet/balances"; 45 | var sign = toHexString(Utilities.computeHmacSha256Signature(ts + method + command, keys.apisecret)); 46 | function toHexString(byteArray) { 47 | return Array.from(byteArray, function(byte) { 48 | return ('0' + (byte & 0xFF).toString(16)).slice(-2); 49 | }).join('') 50 | } 51 | var header = { 52 | 'FTX-KEY' : keys.apikey, 53 | 'FTX-TS' : ts, 54 | 'FTX-SIGN' : sign 55 | }; 56 | var options = { 57 | 'method' : method, 58 | 'headers' : header 59 | }; 60 | ; 61 | 62 | return JSON.parse(UrlFetchApp.fetch(uri + command, options)).result 63 | 64 | } 65 | 66 | --------------------------------------------------------------------------------