This library was created to convert a customized json payload into org.ta4j.core.Rule
object from Ta4j project.
Example of payload
{
"operator": "AND",
"rules": [
{
"type": "RULE",
"class": "UnderIndicatorRule",
"parameters": [
{
"type": "INDICATOR",
"class": "CCIIndicator",
"parameters": [
{
"type": "BAR_SERIES"
},
{
"type": "INTEGER",
"value": 20
}
]
},
{
"type": "NUMBER",
"value": -100
}
]
},
{
"type": "RULE",
"class": "TimeRangeRule",
"parameters": [...]
},
{
"type": "RULE",
"class": "TimeRangeRule",
"parameters": [...]
},
... and so on
]
}
First Rule converted to a org.ta4j.core.Rule
object (the other rules in the payload above were added only to exemplify)
Root level
Example of payload:
{
"operator": "AND",
"rules": [
...
]
}
Field | Available Values |
---|---|
operator | AND, OR |
rules | Array of Rules object |
Rule object level
Example of payload:
{
"type": "RULE",
"class": "UnderIndicatorRule",
"parameters": [
{
"type": "RULE",
"class": "UnderIndicatorRule",
"parameters": [...]
}
// OR
{
"type": "INDICATOR",
"class": "CCIIndicator",
"parameters": [...]
}
// OR
{
"type": "NUMBER",
"value": -100
}
// OR
{
"type": "INTEGER",
"value": 100
}
// and so on
]
}
Field | Available Values |
---|---|
type | RULE |
class | Full path of Ta4j Rule classes. E.g: org.ta4j.core.rules.UnderIndicatorRule |
parameters | Array with the required parameters in the constructors (at the same defined order) from Rule's classes |
Real example:
- Take a look the
UnderIndicatorRule
class from Ta4j and its respective constructor: UnderIndicatorRule.java#L54
public UnderIndicatorRule(Indicator<Num> indicator, Number threshold) {
...
}
To create an instance of this class, you should send a Rule object in this way:
{
"type": "RULE",
"class": "UnderIndicatorRule",
"parameters": [
{
"type": "INDICATOR",
"class": "CCIIndicator",
"parameters": [
{
"type": "BAR_SERIES"
},
{
"type": "INTEGER",
"value": 20
}
]
},
{
"type": "NUMBER",
"value": -100
}
]
}
Indicator object level
Example of payload:
{
"type": "INDICATOR",
"class": "CCIIndicator",
"parameters": [
{
"type": "BAR_SERIES"
},
// OR
{
"type": "INDICATOR",
"class": "CCIIndicator",
"parameters": [...]
}
// OR
{
"type": "NUMBER",
"value": -100
}
// OR
{
"type": "INTEGER",
"value": 100
}
// and so on
]
}
Field | Available Values |
---|---|
type | INDICATOR |
class | Full path of Ta4j Indicator classes. E.g: org.ta4j.core.indicators.MACDIndicator |
parameters | Array with the required parameters in the constructors (at the same defined order) from Indicator's classes |
Real example:
- Take a look the
CCIIndicator
class from Ta4j and its respective constructor: CCIIndicator.java#L52
public CCIIndicator(BarSeries series, int barCount) {
...
}
To create an instance of this class, you should send an Indicator object in this way:
{
"type": "INDICATOR",
"class": "CCIIndicator",
"parameters": [
{
"type": "BAR_SERIES"
},
{
"type": "INTEGER",
"value": 20
}
]
}
Available Values references
Field | Class |
---|---|
type | JsonElementType.java |
operator | JsonOperatorType.java |
This library can be used as a dependency in your project. So, you will be able to access all classes parsing your json payload in Ta4j classes as demonstrated previously.
This is the class responsible for: RuleParser.java
You should initialize that class and call the parse method as demonstrated below:
String payload = "{\"operator\":\"AND\",\"rules\":[{\"type\":\"RULE\",\"class\":\"UnderIndicatorRule\",\"parameters\":[{\"type\":\"INDICATOR\",\"class\":\"CCIIndicator\",\"parameters\":[{\"type\":\"TIME_SERIES\"},{\"type\":\"INTEGER\",\"value\":20}]},{\"type\":\"NUMBER\",\"value\":-100}]}]}";
// 1. Initialize the class setting the BarSeries filled accordingly
RuleParser parser = new RuleParser(new BaseBarSeries());
// 2. call the parse method to convert the payload into an org.ta4j.core.Rule class
Rule rule = parser.parse(payload);
This library provides you to create many Rule's possibilities in a simple way, using JSON structure and with easy integration to your project.
Depending on your implementation, you can store this JSON payload in a database for example, and every time you receive a new ticket, a new call to the RuleParser sending the JSON to convert it into an org.ta4j.core.Rule
to run your strategy.