public void test_of() { EtdContractCode test = EtdContractCode.of("test"); assertEquals(test.toString(), "test"); }
public void test_equalsHashCode() { EtdContractCode a = EtdContractCode.of("test"); EtdContractCode a2 = EtdContractCode.of("test"); EtdContractCode b = EtdContractCode.of("test2"); assertEquals(a.equals(a), true); assertEquals(a.equals(a2), true); assertEquals(a.equals(b), false); assertEquals(a.equals(null), false); assertEquals(a.equals(ANOTHER_TYPE), false); }
/** * Parses the contract specification from the row. * * @param row the CSV row to parse * @param type the ETD type * @return the contract specification * @throws IllegalArgumentException if the specification is not found */ public default EtdContractSpec parseEtdContractSpec(CsvRow row, EtdType type) { ExchangeId exchangeId = ExchangeId.of(row.getValue(EXCHANGE_FIELD)); EtdContractCode contractCode = EtdContractCode.of(row.getValue(CONTRACT_CODE_FIELD)); EtdContractSpecId specId = EtdIdUtils.contractSpecId(type, exchangeId, contractCode); return getReferenceData().findValue(specId).orElseThrow( () -> new IllegalArgumentException("ETD contract specification not found in reference data: " + specId)); }
/** * Parses an ETD option position from the CSV row without using reference data. * <p> * This returns a {@link SecurityPosition} based on a standard ETD identifier from {@link EtdIdUtils}. * * @param row the CSV row to parse * @param info the position information * @return the loaded positions, position-level errors are captured in the result * @throws IllegalArgumentException if the row cannot be parsed */ public default SecurityPosition parseEtdOptionSecurityPosition(CsvRow row, PositionInfo info) { ExchangeId exchangeId = ExchangeId.of(row.getValue(EXCHANGE_FIELD)); EtdContractCode contractCode = EtdContractCode.of(row.getValue(CONTRACT_CODE_FIELD)); Pair<YearMonth, EtdVariant> variant = CsvLoaderUtils.parseEtdVariant(row, EtdType.OPTION); int version = row.findValue(VERSION_FIELD).map(Integer::parseInt).orElse(DEFAULT_OPTION_VERSION_NUMBER); PutCall putCall = LoaderUtils.parsePutCall(row.getValue(PUT_CALL_FIELD)); double strikePrice = Double.parseDouble(row.getValue(EXERCISE_PRICE_FIELD)); YearMonth underlyingExpiry = row.findValue(UNDERLYING_EXPIRY_FIELD) .map(str -> LoaderUtils.parseYearMonth(str)) .orElse(null); SecurityId securityId = EtdIdUtils.optionId( exchangeId, contractCode, variant.getFirst(), variant.getSecond(), version, putCall, strikePrice, underlyingExpiry); DoublesPair quantity = CsvLoaderUtils.parseQuantity(row); SecurityPosition position = SecurityPosition.ofLongShort(info, securityId, quantity.getFirst(), quantity.getSecond()); return completePosition(row, position); }
/** * Parses an ETD future position from the CSV row without using reference data. * <p> * This returns a {@link SecurityPosition} based on a standard ETD identifier from {@link EtdIdUtils}. * * @param row the CSV row to parse * @param info the position information * @return the loaded positions, position-level errors are captured in the result * @throws IllegalArgumentException if the row cannot be parsed */ public default SecurityPosition parseEtdFutureSecurityPosition(CsvRow row, PositionInfo info) { ExchangeId exchangeId = ExchangeId.of(row.getValue(EXCHANGE_FIELD)); EtdContractCode contractCode = EtdContractCode.of(row.getValue(CONTRACT_CODE_FIELD)); Pair<YearMonth, EtdVariant> variant = CsvLoaderUtils.parseEtdVariant(row, EtdType.FUTURE); SecurityId securityId = EtdIdUtils.futureId(exchangeId, contractCode, variant.getFirst(), variant.getSecond()); DoublesPair quantity = CsvLoaderUtils.parseQuantity(row); SecurityPosition position = SecurityPosition.ofLongShort(info, securityId, quantity.getFirst(), quantity.getSecond()); return completePosition(row, position); }
static EtdContractSpec sut2() { return EtdContractSpec.builder() .type(EtdType.OPTION) .exchangeId(ExchangeIds.IFEN) .contractCode(EtdContractCode.of("BAR")) .description("A test option template") .priceInfo(SecurityPriceInfo.of(Currency.EUR, 10)) .addAttribute(AttributeType.NAME, "NAME") .build(); }
static EtdContractSpec sut() { return EtdContractSpec.builder() .id(EtdContractSpecId.of("test", "123")) .type(EtdType.FUTURE) .exchangeId(ExchangeIds.ECAG) .contractCode(EtdContractCode.of("FOO")) .description("A test future template") .priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)) .build(); }