com.dxfeed.event.candle
Class CandlePeriod

java.lang.Object
  extended by com.dxfeed.event.candle.CandlePeriod
All Implemented Interfaces:
CandleSymbolAttribute<CandlePeriod>

public class CandlePeriod
extends Object
implements CandleSymbolAttribute<CandlePeriod>

Period attribute of CandleSymbol defines aggregation period of the candles. Aggregation period is defined as pair of a getValue() and type.

Implementation details

This attribute is encoded in a symbol string with 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()


Field Summary
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.
 
Method Summary
 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.
 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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TICK

public static final CandlePeriod TICK
Tick aggregation where each candle represents an individual tick.


DAY

public static final CandlePeriod DAY
Day aggregation where each candle represents a day.


DEFAULT

public static final CandlePeriod DEFAULT
Default period is TICK.


ATTRIBUTE_KEY

public static final String ATTRIBUTE_KEY
The attribute key that is used to store the value of 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()

See Also:
Constant Field Values
Method Detail

getPeriodIntervalMillis

public long getPeriodIntervalMillis()
Returns aggregation period in milliseconds as closely as possible. Certain aggregation types like 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, and CandleType.PRICE is not defined and this method returns 0. The result of this method is equal to (long)(this.getType().getPeriodIntervalMillis() * this.getValue())

Returns:
aggregation period in milliseconds.
See Also:
CandleType.getPeriodIntervalMillis()

changeAttributeForSymbol

public String changeAttributeForSymbol(String symbol)
Returns candle event symbol string with this aggregation period set.

Specified by:
changeAttributeForSymbol in interface CandleSymbolAttribute<CandlePeriod>
Parameters:
symbol - original candle event symbol.
Returns:
candle event symbol string with this aggregation period set.

checkInAttributeImpl

public void checkInAttributeImpl(CandleSymbol candleSymbol)
Internal method that initializes attribute in the candle symbol.

Specified by:
checkInAttributeImpl in interface CandleSymbolAttribute<CandlePeriod>
Parameters:
candleSymbol - candle symbol.
Throws:
IllegalStateException - if used outside of internal initialization logic.

getValue

public double getValue()
Returns aggregation period value. For example, the value of 5 with the candle type of MINUTE represents 5 minute aggregation period.

Returns:
aggregation period value.

getType

public CandleType getType()
Returns aggregation period type.

Returns:
aggregation period type.

equals

public boolean equals(Object o)
Indicates whether this aggregation period is the same as another one. The same aggregation period has the same value and type.

Overrides:
equals in class Object
Returns:
true if this aggregation period is the same as another one.

hashCode

public int hashCode()
Returns hash code of this aggregation period.

Overrides:
hashCode in class Object
Returns:
hash code of this aggregation period.

toString

public String toString()
Returns string representation of this aggregation period. The string representation is composed of value and type string. For example, 5 minute aggregation is represented as "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.

Overrides:
toString in class Object
Returns:
string representation of this aggregation period.

parse

public static CandlePeriod parse(String s)
Parses string representation of aggregation period into object. Any string that was returned by toString() can be parsed. This method is flexible in the way candle types can be specified. See CandleType.parse(String) for details.

Parameters:
s - string representation of aggregation period.
Returns:
aggregation period object.
Throws:
IllegalArgumentException - if string representation is invalid.

valueOf

public static CandlePeriod valueOf(double value,
                                   CandleType type)
Returns candle period with the given value and type.

Parameters:
value - candle period value.
type - candle period type.
Returns:
candle period with the given value and type.

getAttributeForSymbol

public static CandlePeriod getAttributeForSymbol(String symbol)
Returns candle period of the given candle symbol string. The result is DEFAULT if the symbol does not have candle period attribute.

Parameters:
symbol - candle symbol string.
Returns:
candle period of the given candle symbol string.
Throws:
IllegalArgumentException - if string representation is invalid.

normalizeAttributeForSymbol

public static String normalizeAttributeForSymbol(String symbol)
Returns candle symbol string with the normalized representation of the candle period attribute.

Parameters:
symbol - candle symbol string.
Returns:
candle symbol string with the normalized representation of the the candle period attribute.


Copyright © 2013 Devexperts. All Rights Reserved.