public class CandlePeriod extends Object implements CandleSymbolAttribute<CandlePeriod>, Serializable
CandleSymbol
defines aggregation period of the candles.
Aggregation period is defined as pair of a getValue()
and type
.
MarketEventSymbols.getAttributeStringByKey
,
changeAttributeStringByKey
, and
removeAttributeStringByKey
methods.
The key to use with these methods is available via
ATTRIBUTE_KEY
constant.
The value that this key shall be set to is equal to
the corresponding CandlePeriod.toString()
Modifier and Type | Field and Description |
---|---|
static String |
ATTRIBUTE_KEY
The attribute key that is used to store the value of
CandlePeriod in
a symbol string using methods of MarketEventSymbols class. |
static CandlePeriod |
DAY
Day aggregation where each candle represents a day.
|
static CandlePeriod |
DEFAULT
Default period is
TICK . |
static CandlePeriod |
TICK
Tick aggregation where each candle represents an individual tick.
|
Modifier and Type | Method and Description |
---|---|
String |
changeAttributeForSymbol(String symbol)
Returns candle event symbol string with this aggregation period set.
|
void |
checkInAttributeImpl(CandleSymbol candleSymbol)
Internal method that initializes attribute in the candle symbol.
|
boolean |
equals(Object o)
Indicates whether this aggregation period is the same as another one.
|
static CandlePeriod |
getAttributeForSymbol(String symbol)
Returns candle period of the given candle symbol string.
|
long |
getPeriodIntervalMillis()
Returns aggregation period in milliseconds as closely as possible.
|
CandleType |
getType()
Returns aggregation period type.
|
double |
getValue()
Returns aggregation period value.
|
int |
hashCode()
Returns hash code of this aggregation period.
|
static String |
normalizeAttributeForSymbol(String symbol)
Returns candle symbol string with the normalized representation of the candle period attribute.
|
static CandlePeriod |
parse(String s)
Parses string representation of aggregation period into object.
|
protected Object |
readResolve() |
String |
toString()
Returns string representation of this aggregation period.
|
static CandlePeriod |
valueOf(double value,
CandleType type)
Returns candle period with the given value and type.
|
public static final CandlePeriod TICK
public static final CandlePeriod DAY
public static final CandlePeriod DEFAULT
TICK
.public static final String ATTRIBUTE_KEY
CandlePeriod
in
a symbol string using methods of MarketEventSymbols
class.
The value of this constant is an empty string, because this is the
main attribute that every CandleSymbol
must have.
The value that this key shall be set to is equal to
the corresponding CandlePeriod.toString()
public long getPeriodIntervalMillis()
SECOND
and
DAY
span a specific number of milliseconds.
CandleType.MONTH
, CandleType.OPTEXP
and CandleType.YEAR
are approximate. Candle period of
CandleType.TICK
, CandleType.VOLUME
, CandleType.PRICE
,
CandleType.PRICE_MOMENTUM
and CandleType.PRICE_RENKO
is not defined and this method returns 0
.
The result of this method is equal to
(long) (this.getType().getPeriodIntervalMillis() * this.getValue())
CandleType.getPeriodIntervalMillis()
public String changeAttributeForSymbol(String symbol)
changeAttributeForSymbol
in interface CandleSymbolAttribute<CandlePeriod>
symbol
- original candle event symbol.public void checkInAttributeImpl(CandleSymbol candleSymbol)
checkInAttributeImpl
in interface CandleSymbolAttribute<CandlePeriod>
candleSymbol
- candle symbol.IllegalStateException
- if used outside of internal initialization logic.public double getValue()
5
with
the candle type of MINUTE
represents 5 minute
aggregation period.public CandleType getType()
public boolean equals(Object o)
public int hashCode()
public String toString()
"5m"
.
The value of 1
is omitted in the string representation, so
DAY
(one day) is represented as "d"
.
This string representation can be converted back into object
with parse(String)
method.public static CandlePeriod parse(String s)
toString()
can be parsed.
This method is flexible in the way candle types can be specified.
See CandleType.parse(String)
for details.s
- string representation of aggregation period.IllegalArgumentException
- if string representation is invalid.public static CandlePeriod valueOf(double value, CandleType type)
value
- candle period value.type
- candle period type.public static CandlePeriod getAttributeForSymbol(String symbol)
DEFAULT
if the symbol does not have candle period attribute.symbol
- candle symbol string.IllegalArgumentException
- if string representation is invalid.public static String normalizeAttributeForSymbol(String symbol)
symbol
- candle symbol string.protected Object readResolve() throws ObjectStreamException
ObjectStreamException
Copyright © 2002–2023 Devexperts LLC. All rights reserved.