-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64d9682
commit ec34e51
Showing
14 changed files
with
305 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 20 additions & 10 deletions
30
...st-deep/src/main/java/pl/zankowski/iextrading4j/hist/deep/trading/field/IEXEventFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
package pl.zankowski.iextrading4j.hist.deep.trading.field; | ||
|
||
public enum IEXEventFlag { | ||
import pl.zankowski.iextrading4j.hist.api.IEXByteEnum; | ||
|
||
import java.util.EnumSet; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static pl.zankowski.iextrading4j.hist.api.util.IEXByteEnumLookupUtil.lookup; | ||
|
||
public enum IEXEventFlag implements IEXByteEnum { | ||
|
||
ORDER_BOOK_IS_PROCESSING_EVENT((byte) 0x0), | ||
EVENT_PROCESSING_COMPLETE((byte) 0x1), | ||
UNKNOWN((byte) 0x11); | ||
EVENT_PROCESSING_COMPLETE((byte) 0x1); | ||
|
||
private static final Map<Byte, IEXEventFlag> LOOKUP = new HashMap<>(); | ||
|
||
static { | ||
for (final IEXEventFlag value : EnumSet.allOf(IEXEventFlag.class)) | ||
LOOKUP.put(value.getCode(), value); | ||
} | ||
|
||
private final byte code; | ||
|
||
IEXEventFlag(byte code) { | ||
IEXEventFlag(final byte code) { | ||
this.code = code; | ||
} | ||
|
||
@Override | ||
public byte getCode() { | ||
return code; | ||
} | ||
|
||
public static IEXEventFlag getEventFlag(final byte code) { | ||
for (IEXEventFlag iexEventFlag : values()) { | ||
if (iexEventFlag.getCode() == code) { | ||
return iexEventFlag; | ||
} | ||
} | ||
return IEXEventFlag.UNKNOWN; | ||
return lookup(IEXEventFlag.class, LOOKUP, code); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ski/iextrading4j/hist/deep/administrative/builder/IEXSecurityEventMessageDataBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package pl.zankowski.iextrading4j.hist.deep.administrative.builder; | ||
|
||
import pl.zankowski.iextrading4j.hist.api.IEXMessageType; | ||
import pl.zankowski.iextrading4j.hist.api.message.builder.TestDataBuilder; | ||
import pl.zankowski.iextrading4j.hist.api.util.IEXByteTestUtil; | ||
import pl.zankowski.iextrading4j.hist.deep.administrative.IEXSecurityEventMessage; | ||
import pl.zankowski.iextrading4j.hist.deep.administrative.field.IEXSecurityEvent; | ||
|
||
public class IEXSecurityEventMessageDataBuilder implements TestDataBuilder { | ||
|
||
private IEXSecurityEvent securityEvent = IEXSecurityEvent.OPENING_PROCESS_COMPLETE; | ||
private long timestamp = 1494855059287436131L; | ||
private String symbol = "SNAP"; | ||
|
||
public static IEXSecurityEventMessage defaultSecurityEventMessage() { | ||
return securityEventMessage().build(); | ||
} | ||
|
||
public static IEXSecurityEventMessageDataBuilder securityEventMessage() { | ||
return new IEXSecurityEventMessageDataBuilder(); | ||
} | ||
|
||
@Override | ||
public byte[] getBytes() { | ||
return IEXByteTestUtil.prepareBytes(18, IEXMessageType.SECURITY_EVENT, securityEvent, | ||
timestamp, symbol); | ||
} | ||
|
||
public IEXSecurityEventMessage build() { | ||
return IEXSecurityEventMessage.createIEXMessage(getBytes()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...t/java/pl/zankowski/iextrading4j/hist/deep/administrative/field/IEXSecurityEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package pl.zankowski.iextrading4j.hist.deep.administrative.field; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class IEXSecurityEventTest { | ||
|
||
@Test | ||
public void shouldSuccessfullyFindEnumBasedOnCode() { | ||
final IEXSecurityEvent value = IEXSecurityEvent.CLOSING_PROCESS_COMPLETE; | ||
|
||
final IEXSecurityEvent result = IEXSecurityEvent.getSecurityEvent(value.getCode()); | ||
|
||
assertThat(result).isEqualTo(value); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void shouldThrowAnExceptionForUnknownCode() { | ||
IEXSecurityEvent.getSecurityEvent((byte) 0x11); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...nkowski/iextrading4j/hist/deep/trading/builder/IEXPriceLevelUpdateMessageDataBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package pl.zankowski.iextrading4j.hist.deep.trading.builder; | ||
|
||
import pl.zankowski.iextrading4j.hist.api.IEXMessageType; | ||
import pl.zankowski.iextrading4j.hist.api.field.IEXPrice; | ||
import pl.zankowski.iextrading4j.hist.api.message.builder.TestDataBuilder; | ||
import pl.zankowski.iextrading4j.hist.api.util.IEXByteTestUtil; | ||
import pl.zankowski.iextrading4j.hist.deep.trading.IEXPriceLevelUpdateMessage; | ||
import pl.zankowski.iextrading4j.hist.deep.trading.field.IEXEventFlag; | ||
|
||
public class IEXPriceLevelUpdateMessageDataBuilder implements TestDataBuilder { | ||
|
||
private IEXMessageType messageType = IEXMessageType.PRICE_LEVEL_UPDATE_BUY; | ||
private IEXEventFlag eventFlag = IEXEventFlag.EVENT_PROCESSING_COMPLETE; | ||
private long timestamp = 1494855059287436131L; | ||
private String symbol = "SNAP"; | ||
private int size = 12; | ||
private IEXPrice price = new IEXPrice(1234L); | ||
|
||
public static IEXPriceLevelUpdateMessage defaultPriceLevelMessage() { | ||
return priceLevelMessage().build(); | ||
} | ||
|
||
public static IEXPriceLevelUpdateMessageDataBuilder priceLevelMessage() { | ||
return new IEXPriceLevelUpdateMessageDataBuilder(); | ||
} | ||
|
||
@Override | ||
public byte[] getBytes() { | ||
return IEXByteTestUtil.prepareBytes(30, messageType, eventFlag, timestamp, symbol, | ||
size, price); | ||
} | ||
|
||
public IEXPriceLevelUpdateMessage build() { | ||
return IEXPriceLevelUpdateMessage.createIEXMessage(messageType, getBytes()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...eep/src/test/java/pl/zankowski/iextrading4j/hist/deep/trading/field/IEXEventFlagTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package pl.zankowski.iextrading4j.hist.deep.trading.field; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class IEXEventFlagTest { | ||
|
||
@Test | ||
public void shouldSuccessfullyFindEnumBasedOnCode() { | ||
final IEXEventFlag value = IEXEventFlag.ORDER_BOOK_IS_PROCESSING_EVENT; | ||
|
||
final IEXEventFlag result = IEXEventFlag.getEventFlag(value.getCode()); | ||
|
||
assertThat(result).isEqualTo(value); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void shouldThrowAnExceptionForUnknownCode() { | ||
IEXEventFlag.getEventFlag((byte) 0x11); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.