Skip to main content

Custom code

Many elements in AutoConfig can be calculated at the time the job executes, this allows for completely dynamic scenarios for power users. Every valid javascript expression can be used.

You can use calculated values for the following elements in AutoConfig:

  • overrides
  • variables
  • pairVariables
  • maxPairs
  • target in filter type custom

To use an expression instead of a string or number, enter your expression as string with a leading blank space:

"validExpression": " 1 + 2"

When using custom expressions, be careful with internal data that's available to you. It's common to come across undefined data, but you can handle these errors by adding a filter that checks if the data exists or for example has a value greater than 0 before using it in an expression.

Use the following references to access internal data in your expressions:

ReferenceContent
this.configThe complete Gunbot config
this.pairAll pair data the bot works with, the same as available in json state files
this.pairNameString of the pair currently processing
this.variablesAll AutoConfig variables
this.pairVariablesAll AutoConfig pair variables
this.tickersAll collected ticker snapshots, in case it's ran in a job type that works with tickers.
this.userDataUser defined contents of acUserData.json in Gunbot root folder.

Availability of pair specific data depends on the context where you're trying to access it. For example a dynamic pair override value will have access to all pair specific data (because overrides are set for each pair, during a single job run), but a global variable won't (because global variables are just set once per job run).

Examples of valid expressions

" this.pair.Bid * this.pair.quoteBalance"
// returns bag value in base currency

" (this.pair.Bid * this.pair.quoteBalance) > this.pair.whatstrat.MIN_VOLUME_TO_SELL ? true : false"
// returns true if bag is bigger than MVTS, false if not

" (function doStuff(data) {
if (data.pair.Bid > 0){
return true
}
else {
return false
}
})(this)" ---> this example needs to be minified before it would work, as all code needs to be in a single line to not break JSON formatting.

" (function doStuff(data){if(data.pair.Bid>0){return true}else{return false}})(this)"
// minified example of the above

Example of a custom filter

"position bigger Than zero": {
"type": "custom",
"target": " this.pair.quoteBalance * this.pair.Bid > parseFloat(this.pair.whatstrat.MIN_VOLUME_TO_SELL)"
},