public static Instrument buildInstrument(final InstrumentDefinition instDef) {
final TagMapSafe map = new HashTagMapSafe(FIELDS);
if (instDef.hasMarketId()) {
map.set(GUID, new InstrumentGUID(String.valueOf(instDef.getMarketId())));
map.set(MARKET_GUID, newText(String.valueOf(instDef.getMarketId())));
} else {
log.warn("Inst def had no market id, returning null instrument: \n{}", instDef.toString());
return Instrument.NULL;
}
if (instDef.hasInstrumentType()) {
map.set(SECURITY_TYPE,
secTypeMap.getKey(instDef.getInstrumentType()));
}
if (instDef.hasBookLiquidity()) {
map.set(BOOK_LIQUIDITY,
liqidityTypeMap.getKey(instDef.getBookLiquidity()));
}
if (instDef.hasBookStructure()) {
map.set(BOOK_STRUCTURE,
structTypeMap.getKey(instDef.getBookStructure()));
}
if (instDef.hasBookDepth()) {
map.set(BOOK_DEPTH, newSize(instDef.getBookDepth()));
}
if (instDef.hasVendorId()) {
map.set(VENDOR, newText(instDef.getVendorId()));
}
if (instDef.hasSymbol()) {
map.set(SYMBOL, newText(instDef.getSymbol()));
}
if (instDef.hasDescription()) {
map.set(DESCRIPTION, newText(instDef.getDescription()));
}
if (instDef.hasCfiCode()) {
map.set(CFI_CODE, newText(instDef.getCfiCode()));
}
if (instDef.hasExchangeCode()) {
map.set(EXCHANGE_CODE, newText(instDef.getExchangeCode()));
}
if (instDef.hasMinimumPriceIncrement()) {
map.set(TICK_SIZE,
priceFromDecimal(instDef.getMinimumPriceIncrement()));
}
if (instDef.hasContractPointValue()) {
map.set(POINT_VALUE,
priceFromDecimal(instDef.getContractPointValue()));
}
if (instDef.hasDisplayBase() && instDef.hasDisplayExponent()) {
map.set(DISPLAY_FRACTION,
factory.newFraction(instDef.getDisplayBase(),
instDef.getDisplayExponent()));
}
if (instDef.hasCalendar()) {
final Interval i = instDef.getCalendar().getLifeTime();
if(i.getTimeFinish() > 0) {
map.set(LIFETIME, factory.newTimeInterval(i.getTimeStart(), i.getTimeFinish()));
} else {
map.set(LIFETIME, TimeInterval.NULL);
}
final List<Interval> ints = instDef.getCalendar()
.getMarketHoursList();
final TimeInterval[] tints = new TimeInterval[ints.size()];
for (int n = 0; n < ints.size(); n++) {
tints[n] = factory.newTimeInterval(
ints.get(n).getTimeStart(), ints.get(n).getTimeFinish());
}
map.set(MARKET_HOURS, factory.newSchedule(tints));
}
if (instDef.hasTimeZoneOffset()) {
map.set(TIME_ZONE_OFFSET, newSize(instDef.getTimeZoneOffset()));
}
if (instDef.hasTimeZoneName()) {
map.set(TIME_ZONE_NAME, newText(instDef.getTimeZoneName()));
}
InstrumentImpl inst = ObjectMapFactory.build(InstrumentImpl.class, map);
final List<Long> ids = instDef.getComponentIdList();
for(final Long id : ids) {
inst.componentLegs.add(new InstrumentGUID(String.valueOf(id)));
}
return inst;
}