Skip to content

Commit

Permalink
Merge pull request #9 from WojciechZankowski/7-cannot-parse-iexsaleco…
Browse files Browse the repository at this point in the history
…nditionflag

[7] Cannot parse IexSaleConditionFlag
  • Loading branch information
WojciechZankowski authored Jun 29, 2018
2 parents ec34e51 + d3b3fa9 commit 7af2859
Show file tree
Hide file tree
Showing 66 changed files with 747 additions and 418 deletions.
2 changes: 1 addition & 1 deletion iextrading4j-hist-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>iextrading4j-hist</artifactId>
<groupId>pl.zankowski</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion iextrading4j-hist-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>iextrading4j-hist</artifactId>
<groupId>pl.zankowski</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package pl.zankowski.iextrading4j.hist.api.exception;

import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;

public class IEXMessageException extends RuntimeException {

public IEXMessageException(final String message) {
super(message);
}

public IEXMessageException(final Class<? extends IEXMessage> clazz, final int length) {
super("Failed to parse message. " + clazz.getSimpleName() + " requires " + length + " bytes.");
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package pl.zankowski.iextrading4j.hist.api.message;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.util.IEXByteConverter;

import java.util.Arrays;
import java.util.Objects;

public class IEXMessageHeader {

public static final int LENGTH = 40;

private final byte version;
private final short messageProtocolID;
private final int channelID;
Expand Down Expand Up @@ -39,8 +42,8 @@ private IEXMessageHeader(
}

public static IEXMessageHeader createIEXMessageHeader(final byte[] bytes) {
if (bytes.length != 40) {
throw new IllegalArgumentException("IEX TOPS Message Header has to has 40 bytes.");
if (bytes.length != LENGTH) {
throw new IEXMessageException("Failed to parse message. IEXMessageHeader requires 40 bytes.");
}

final byte version = bytes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected IEXSegment(
final IEXMessageHeader messageHeader,
final List<IEXMessage> messages) {
this.messageHeader = messageHeader;
this.messages = messages;
this.messages = new ArrayList<>(messages);
}

public IEXMessageHeader getMessageHeader() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.administrative;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXOperationalHaltStatus;
import pl.zankowski.iextrading4j.hist.api.util.IEXByteConverter;
Expand All @@ -11,6 +12,8 @@

public class IEXOperationalHaltStatusMessage extends IEXMessage {

public static final int LENGTH = 18;

private final IEXOperationalHaltStatus operationalHaltStatus;
private final long timestamp;
private final String symbol;
Expand All @@ -26,6 +29,10 @@ private IEXOperationalHaltStatusMessage(
}

public static IEXOperationalHaltStatusMessage createIEXMessage(final byte[] bytes) {
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXOperationalHaltStatusMessage.class, LENGTH);
}

final IEXOperationalHaltStatus operationalHaltStatus = IEXOperationalHaltStatus.getOperationalHaltStatus(bytes[1]);
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package pl.zankowski.iextrading4j.hist.api.message.administrative;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.field.IEXPrice;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXLULDTier;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXSecurityDirectoryFlag;
import pl.zankowski.iextrading4j.hist.api.util.IEXByteConverter;

import java.util.Arrays;
Expand All @@ -13,31 +13,41 @@

public class IEXSecurityDirectoryMessage extends IEXMessage {

private final IEXSecurityDirectoryFlag securityDirectoryFlag;
public static final int LENGTH = 31;

private final byte flag;
private final long timestamp;
private final String symbol;
private final int roundLotSize;
private final IEXPrice adjustedPOCPrice;
private final IEXLULDTier luldTier;

private IEXSecurityDirectoryMessage(
final IEXSecurityDirectoryFlag securityDirectoryFlag,
final byte flag,
final long timestamp,
final String symbol,
final int roundLotSize,
final IEXPrice adjustedPOCPrice,
final IEXLULDTier luldTier) {
super(SECURITY_DIRECTORY);
this.securityDirectoryFlag = securityDirectoryFlag;
this.flag = flag;
this.timestamp = timestamp;
this.symbol = symbol;
this.roundLotSize = roundLotSize;
this.adjustedPOCPrice = adjustedPOCPrice;
this.luldTier = luldTier;
}

public IEXSecurityDirectoryFlag getSecurityDirectoryFlag() {
return securityDirectoryFlag;
public boolean isTestSecurity() {
return (flag & 0x80) != 0;
}

public boolean isWhenIssuedSecurity() {
return (flag & 0x40) != 0;
}

public boolean isETP() {
return (flag & 0x20) != 0;
}

public long getTimestamp() {
Expand All @@ -61,7 +71,11 @@ public IEXLULDTier getLuldTier() {
}

public static IEXSecurityDirectoryMessage createIEXMessage(final byte[] bytes) {
final IEXSecurityDirectoryFlag iexSecurityDirectoryFlag = IEXSecurityDirectoryFlag.getSecurityDirectoryFlag(bytes[1]);
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXSecurityDirectoryMessage.class, LENGTH);
}

final byte iexSecurityDirectoryFlag = bytes[1];
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));
final int roundLotSize = IEXByteConverter.convertBytesToInt(Arrays.copyOfRange(bytes, 18, 22));
Expand All @@ -80,21 +94,21 @@ public boolean equals(final Object o) {
final IEXSecurityDirectoryMessage that = (IEXSecurityDirectoryMessage) o;
return timestamp == that.timestamp &&
roundLotSize == that.roundLotSize &&
securityDirectoryFlag == that.securityDirectoryFlag &&
flag == that.flag &&
Objects.equals(symbol, that.symbol) &&
Objects.equals(adjustedPOCPrice, that.adjustedPOCPrice) &&
luldTier == that.luldTier;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), securityDirectoryFlag, timestamp, symbol, roundLotSize, adjustedPOCPrice, luldTier);
return Objects.hash(super.hashCode(), flag, timestamp, symbol, roundLotSize, adjustedPOCPrice, luldTier);
}

@Override
public String toString() {
return "IEXSecurityDirectoryMessage{" +
"securityDirectoryFlag=" + securityDirectoryFlag +
"flag=" + flag +
", timestamp=" + timestamp +
", symbol='" + symbol + '\'' +
", roundLotSize=" + roundLotSize +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.administrative;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXDetail;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXShortSalePriceTestStatus;
Expand All @@ -12,6 +13,8 @@

public class IEXShortSalePriceTestStatusMessage extends IEXMessage {

public static final int LENGTH = 19;

private final IEXShortSalePriceTestStatus shortSalePriceTestStatus;
private final long timestamp;
private final String symbol;
Expand All @@ -30,6 +33,10 @@ private IEXShortSalePriceTestStatusMessage(
}

public static IEXShortSalePriceTestStatusMessage createIEXMessage(final byte[] bytes) {
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXShortSalePriceTestStatusMessage.class, LENGTH);
}

final IEXShortSalePriceTestStatus shortSalePriceTestStatus = IEXShortSalePriceTestStatus.getShortSalePriceTestStatus(bytes[1]);
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.administrative;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXSystemEvent;
import pl.zankowski.iextrading4j.hist.api.util.IEXByteConverter;
Expand All @@ -11,6 +12,8 @@

public class IEXSystemEventMessage extends IEXMessage {

public static final int LENGTH = 10;

private final IEXSystemEvent systemEvent;
private final long timestamp;

Expand All @@ -23,6 +26,10 @@ private IEXSystemEventMessage(
}

public static IEXSystemEventMessage createIEXMessage(final byte[] bytes) {
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXSystemEventMessage.class, LENGTH);
}

final IEXSystemEvent systemEvent = IEXSystemEvent.getSystemEvent(bytes[1]);
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.administrative;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXTradingStatus;
import pl.zankowski.iextrading4j.hist.api.util.IEXByteConverter;
Expand All @@ -11,6 +12,8 @@

public class IEXTradingStatusMessage extends IEXMessage {

public static final int LENGTH = 22;

private final IEXTradingStatus tradingStatus;
private final long timestamp;
private final String symbol;
Expand All @@ -29,6 +32,10 @@ private IEXTradingStatusMessage(
}

public static IEXTradingStatusMessage createIEXMessage(final byte[] bytes) {
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXTradingStatusMessage.class, LENGTH);
}

final IEXTradingStatus tradingStatus = IEXTradingStatus.getTradingStatus(bytes[1]);
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.auction;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.field.IEXPrice;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.auction.field.IEXAuctionType;
Expand All @@ -13,6 +14,8 @@

public class IEXAuctionInformationMessage extends IEXMessage {

public static final int LENGTH = 80;

private final IEXAuctionType auctionType;
private final long timestamp;
private final String symbol;
Expand Down Expand Up @@ -61,6 +64,10 @@ private IEXAuctionInformationMessage(
}

public static IEXAuctionInformationMessage createIEXMessage(final byte[] bytes) {
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXAuctionInformationMessage.class, LENGTH);
}

final IEXAuctionType auctionType = IEXAuctionType.getAuctionType(bytes[1]);
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.auction.field;

import pl.zankowski.iextrading4j.hist.api.IEXByteEnum;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXDetail;

import java.util.EnumSet;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.zankowski.iextrading4j.hist.api.message.trading;

import pl.zankowski.iextrading4j.hist.api.exception.IEXMessageException;
import pl.zankowski.iextrading4j.hist.api.field.IEXPrice;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.trading.field.IEXPriceType;
Expand All @@ -12,6 +13,8 @@

public class IEXOfficialPriceMessage extends IEXMessage {

public static final int LENGTH = 26;

private final IEXPriceType priceType;
private final long timestamp;
private final String symbol;
Expand All @@ -30,6 +33,10 @@ private IEXOfficialPriceMessage(
}

public static IEXOfficialPriceMessage createIEXMessage(final byte[] bytes) {
if (bytes.length != LENGTH) {
throw new IEXMessageException(IEXOfficialPriceMessage.class, LENGTH);
}

final IEXPriceType priceType = IEXPriceType.getPriceType(bytes[1]);
final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));
Expand Down
Loading

0 comments on commit 7af2859

Please sign in to comment.