Persistently save data, the function implements a global dictionary function that can be saved. The data structure is a KV table that is permanently saved in the docker’s local database file.
Persistent saved key-value data in k-v
key-value pairs.
string, number, bool, object, array, null value
_G() _G(k) _G(k, v)
The parameter k
is the name of the key in the saved key-value pair, and is not case-sensitive.
k
false
string, null value
The parameter v
is the key value in the saved key-value pair, which can be any data that can be JSON
serialized.
v
false
string, number, bool, object, array, null value
function main(){
// Set a global variable num with a value of 1
_G("num", 1)
// Change a global variable num to the value of the string ok
_G("num", "ok")
// Delete the global variable num
_G("num", null)
// Returns the value of the global variable num
Log(_G("num"))
// Delete all global variables
_G(null)
// Return to live trading ID
var robotId = _G()
}
def main():
_G("num", 1)
_G("num", "ok")
_G("num", None)
Log(_G("num"))
_G(None)
robotId = _G()
void main() {
_G("num", 1);
_G("num", "ok");
_G("num", NULL);
Log(_G("num"));
_G(NULL);
// Not support auto robotId = _G();
}
A separate database for each live trading, the data saved by the _G()
function will always be there if the strategy is restarted or the docker stops running. If the backtesting is finished, the data saved in the backtesting system by the _G()
function will be cleared. When using the _G()
function to persist the saved data, it should be used reasonably according to the memory and hard disk space of the hardware device, and should not be abused.
When calling the _G()
function in a live trading and no parameters are passed, the _G()
function returns the Id
of the current live trading. When calling the _G()
function, the parameter v
is passed as null to indicate the deletion of the k-v
key-value pair. When calling the _G()
function, only the parameter k
is passed in the string, and the _G()
function returns the key value corresponding to the saved parameter k
. When calling the _G()
function, only the parameter k
is passed in a null value, indicating that all records of the k-v
key-value pair is deleted. When the k-v
key-value pairs have been saved persistently, the _G()
function is called again, passing in the name of the key that has been saved persistently as parameter k
. Passing in the new key value as parameter v
will update that k-v
key-value pair.
{@fun/Global/DBExec DBExec}
__Serve _D