script: implementation of error insertion on return (#986)

* exchanges/account: shift credentials to account package and segregate funds to keys

* merge: fixes

* linter: fix

* Update exchanges/account/account.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits + protection for string panic

* glorious_suggestion: add method for matching keys

* linter: fix tests

* account: add protected method for credentials minimizing access, display full account details to rpc.

* linter: spelling kweeeeeeen

* accounts/portfolio: clean/check portfolio code and quickly check balances from change. Add protected method for future matching.

* accounts: theres no point in pointerising everything

* linter: ok pointerise this then...

* exchanges: fix regression add in little notes.

* glorious: nits

* Update exchanges/account/credentials.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update exchanges/account/credentials_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update exchanges/account/credentials_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

* gloriously: fix glorious glorious test gloriously

* script: initial implementation of error insertion on return

* script: make script context aware(ish) and update error handle in examples

* script: add tests

* script: add syntax highlighting to readme

* Update gctscript/vm/vm.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/vm/vm.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/examples/exchange/account_info.gct

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/examples/exchange/cancel_order.gct

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/examples/verbose.gct

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

* rm: bros

* scripts: handle errors in examples when they are going to use the data after fetching

* linter: fix rides again

* SCOTT_SPELL_CHECK_LINTER: fix

* gctscript: fix tests

* glorious: niiiiiiiiiiiiits

* scriptmodules/gct: standardize runtime errors

* Update gctscript/modules/gct/exchange.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/exchange.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/exchange.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/exchange.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update gctscript/modules/gct/gct.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits/reverts

* go mod: tidy

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2022-08-17 14:18:53 +10:00
committed by GitHub
parent 68588560e3
commit e93ee83563
42 changed files with 1110 additions and 372 deletions

View File

@@ -0,0 +1,31 @@
global := import("global")
exch := import("exchange")
fmt := import("fmt")
load := func() {
// 'ctx' is already defined when we construct our bytecode from file.
// It contains script ID and shortname of file as save details to default
// script output directory.
// Set account func allows the setting of account details via script
// which can then be passed into auth functions to specifically target
// different subaccounts while trading or retrieving fund details.
// Basic required implementation below:
ctx = global.set_account(ctx, "api_key_str", "api_secret_str")
// Full implementation:
// ctx = global.set_account(ctx, "api_key_str", "api_secret_str", "sub_account_str", "client_Id_str", "PEM_key_str", "OTP_Str")
// Set sub account func allows the setting of just the individual sub
// account details while utilizing the configured config.json apikeys.
// ctx = global.set_sub_account(ctx, "sub_account_str")
info := exch.accountinfo(ctx, "ftx", "spot")
if is_error(info) {
// handle error
}
fmt.println(info)
}
load()

View File

@@ -1,5 +1,6 @@
exch := import("exchange")
t := import("times")
fmt := import("fmt")
// Import all the indicators you want
atr := import("indicator/atr")
sma := import("indicator/sma")
@@ -12,7 +13,12 @@ load := func() {
end := t.add_date(start, 0, 6 , 0)
// This fetches the ohlcv
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
fmt.println(ohlcvData)
return
}
// construct ta values
avgtr := atr.calculate(ohlcvData.candles, 14)
@@ -22,7 +28,14 @@ load := func() {
// 'ctx' is already defined when we construct our bytecode from file.
// It contains script ID and shortname of file as save details to default
// script output directory.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
common.writeascsv(ctx, ohlcvData, avgtr, simma, expma)
// A custom filename can also be declared when using a string instead of the
// context variable like below. This will continue to save in the output
// folder of the scripts file and will look something like this
// 'super_cool_filename-1658465844999067400.csv'.
// common.writeascsv("super_cool_filename", ohlcvData, avgtr, simma, expma)
}
load()

View File

@@ -4,8 +4,14 @@ fmt := import("fmt")
exch := import("exchange")
load := func() {
// retrieve account information from exchange and store in info variable
info := exch.accountinfo("BTC Markets", "spot")
// Retrieve account information from exchange and store in info variable
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
// for more details.
info := exch.accountinfo(ctx, "BTC Markets", "spot")
if is_error(info) {
// handle error
}
// print out info
fmt.println(info)
}

View File

@@ -2,7 +2,12 @@ fmt := import("fmt")
exch := import("exchange")
load := func() {
info := exch.ordercancel("binance","13371337", "btc-usdt", "spot")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
info := exch.ordercancel(ctx, "binance","13371337", "btc-usdt", "spot")
if is_error(info) {
// handle error
}
fmt.println(info)
}

View File

@@ -3,6 +3,9 @@ exch := import("exchange")
load := func() {
info := exch.depositaddress("BTC Markets", "BTC", "")
if is_error(info) {
// handle error
}
fmt.println(info)
}

View File

@@ -4,7 +4,12 @@ t := import("times")
load := func() {
start := t.add(t.now(), -t.hour*24)
ohlcvData := exch.ohlcv("coinbasepro", "BTC-USD", "-", "SPOT", start, t.now(), "1h")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "coinbasepro", "BTC-USD", "-", "SPOT", start, t.now(), "1h")
if is_error(ohlcvData) {
// handle error
}
fmt.println(ohlcvData)
}

View File

@@ -5,7 +5,12 @@ name := "run"
timer := "5s"
load := func() {
tx := exch.orderbook("btc markets", "btc-aud", "-", "spot")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
tx := exch.orderbook(ctx, "btc markets", "btc-aud", "-", "spot")
if is_error(tx) {
// handle error
}
fmt.println(tx)
}

View File

@@ -3,6 +3,9 @@ exch := import("exchange")
load := func() {
info := exch.pairs("BTC Markets", false, "SPOT")
if is_error(info) {
// handle error
}
fmt.println(info)
}

View File

@@ -2,7 +2,12 @@ fmt := import("fmt")
exch := import("exchange")
load := func() {
info := exch.orderquery("binance", "4491600698", "BTC-USDT", "spot")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
info := exch.orderquery(ctx, "binance", "4491600698", "BTC-USDT", "spot")
if is_error(info) {
// handle error
}
fmt.println(info)
}

View File

@@ -2,7 +2,12 @@ fmt := import("fmt")
exch := import("exchange")
load := func() {
info := exch.ordersubmit("BTC Markets","BTC-AUD","-","LIMIT","SELL",1000000, 1,"", "spot")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
info := exch.ordersubmit(ctx, "BTC Markets","BTC-AUD","-","LIMIT","SELL",1000000, 1,"", "spot")
if is_error(info) {
// handle error
}
fmt.println(info)
}

View File

@@ -5,7 +5,12 @@ name := "run"
timer := "5s"
load := func() {
tx := exch.ticker("btc markets", "btc-aud", "-", "spot")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
tx := exch.ticker(ctx, "btc markets", "btc-aud", "-", "spot")
if is_error(tx) {
// handle error
}
fmt.println(tx)
}

View File

@@ -13,10 +13,14 @@ load := func() {
// 4: address tag
// 5: amount
// 6: fee amount
// 7: trade password
// 8: OTP
// 7: description
info := exch.withdrawcrypto("BTC Markets","BTC", "1234562362", "1231", 1.0, 0.0, "","" )
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
info := exch.withdrawcrypto(ctx, "BTC Markets", "BTC", "1234562362", "1231", 1.0, 0.0, "")
if is_error(info) {
// handle error
}
// print out info
fmt.println(info)
}

View File

@@ -16,8 +16,13 @@ load := func() {
// 7: trade password
// 8: OTP
// submit request to withdraw funds
info := exch.withdrawfiat("BTC Markets", "AUD", "hello", 1, "-")
// Submit request to withdraw funds
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
info := exch.withdrawfiat(ctx, "BTC Markets", "AUD", "hello", 1, "-")
if is_error(info) {
// handle error
}
// print out info
fmt.println(info)
}

View File

@@ -1,14 +1,16 @@
fmt := import("fmt")
// 'timer' is a GCT key word that is captured at compilation and used to execute
// this script task every defined duration.
timer := "5s"
exit := func() {
timer = 0
timer = "0s" // This will reset the timer to zero and shutdown the script.
}
load := func() {
for x := 0 ; x < 20; x++ {
fmt.printf("Hello %v", x)
fmt.printf("Hello %v\n", x)
}
exit()
}

View File

@@ -6,7 +6,14 @@ atr := import("indicator/atr")
load := func() {
start := t.date(2017, 8 , 17, 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := atr.calculate(ohlcvData.candles, 14)
fmt.println(ret)

View File

@@ -6,7 +6,14 @@ bbands := import("indicator/bbands")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := bbands.calculate("close", ohlcvData.candles, 20, 2.0, 2.0, "sma")
fmt.println(ret)

View File

@@ -6,8 +6,20 @@ cc := import("indicator/correlationcoefficient")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvDataBTC := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
ohlcvDataETH := exch.ohlcv("binance", "ETH-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvDataBTC := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvDataBTC) {
// handle error
fmt.println(ohlcvDataBTC)
return
}
ohlcvDataETH := exch.ohlcv(ctx, "binance", "ETH-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvDataETH) {
// handle error
fmt.println(ohlcvDataETH)
return
}
ret := cc.calculate(ohlcvDataBTC.candles, ohlcvDataETH.candles, 20)
fmt.println(ret)
}

View File

@@ -7,8 +7,14 @@ ema := import("indicator/ema")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := ema.calculate(ohlcvData.candles, 9)
fmt.println(ret)

View File

@@ -6,8 +6,14 @@ macd := import("indicator/macd")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := macd.calculate(ohlcvData.candles, 12, 26, 9)
fmt.println(ret)
}

View File

@@ -6,7 +6,14 @@ mfi := import("indicator/mfi")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := mfi.calculate(ohlcvData.candles, 14)
fmt.println(ret)

View File

@@ -6,7 +6,14 @@ obv := import("indicator/obv")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := obv.calculate(ohlcvData.candles)
fmt.println(ret)

View File

@@ -6,7 +6,14 @@ rsi := import("indicator/rsi")
load := func() {
start := t.date(2017, 8 , 17 , 0 , 0 , 0, 0)
end := t.add_date(start, 0, 6 , 0)
ohlcvData := exch.ohlcv("binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
// 'ctx' is already defined when we construct our bytecode from file.
// To add debugging information to the request, see verbose.gct. To add account credentials, see account.gct
ohlcvData := exch.ohlcv(ctx, "binance", "BTC-USDT", "-", "SPOT", start, end, "1d")
if is_error(ohlcvData) {
// handle error
fmt.println(ohlcvData)
return
}
ret := rsi.calculate(ohlcvData.candles, 14)
fmt.println(ret)

View File

@@ -0,0 +1,27 @@
global := import("global")
exch := import("exchange")
fmt := import("fmt")
load := func() {
// 'ctx' is already defined when we construct our bytecode from file.
// It contains script ID and shortname of file as save details to default
// script output directory.
// Set verbosity func allows the setting of rest request verbosity to
// specifically log out this scripts interaction with any http outbound
// request for debugging purposes.
ctx = global.set_verbose(ctx)
// Any verbose logs will be output according to logger settings defined in the config
// NOTE: Get account info is cached and updated by another worker thread
// therefore calling this script multiple times, if data has already been
// fetched request verbosity will be limited.
info := exch.accountinfo(ctx, "ftx", "spot")
if is_error(info) {
// handle error
}
fmt.println(info)
}
load()