-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from paritytrading/features/hotspot-itch
Add Hotspot ITCH Protocol 1.59 support
- Loading branch information
Showing
26 changed files
with
3,002 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Juncture Hotspot | ||
================ | ||
|
||
Juncture Hotspot implements connectivity to Hotspot on the JVM. | ||
|
||
|
||
Features | ||
-------- | ||
|
||
Juncture Hotspot implements the following protocols: | ||
|
||
- **Hotspot ITCH Protocol 1.59** | ||
|
||
See the [Wiki][] for links to the protocol specifications. | ||
|
||
[Wiki]: https://github.com/paritytrading/juncture/wiki/ | ||
|
||
|
||
Download | ||
-------- | ||
|
||
Add a Maven dependency to Juncture Hotspot: | ||
|
||
<dependency> | ||
<groupId>com.paritytrading.juncture</groupId> | ||
<artifactId>juncture-hotspot</artifactId> | ||
<version><!-- latest version --></version> | ||
</dependency> | ||
|
||
|
||
License | ||
------- | ||
|
||
Juncture Hotspot is released under the Apache License, Version 2.0. |
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,33 @@ | ||
<?xml version="1.0"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.paritytrading.juncture</groupId> | ||
<artifactId>juncture-parent</artifactId> | ||
<version>0.2.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>juncture-hotspot</artifactId> | ||
|
||
<name>Juncture Hotspot</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.paritytrading.foundation</groupId> | ||
<artifactId>foundation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jvirtanen.value</groupId> | ||
<artifactId>value</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
7 changes: 7 additions & 0 deletions
7
juncture-hotspot/src/main/java/com/paritytrading/juncture/hotspot/itch/Clock.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,7 @@ | ||
package com.paritytrading.juncture.hotspot.itch; | ||
|
||
interface Clock { | ||
|
||
long currentTimeMillis(); | ||
|
||
} |
234 changes: 234 additions & 0 deletions
234
juncture-hotspot/src/main/java/com/paritytrading/juncture/hotspot/itch/HotspotBook.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,234 @@ | ||
package com.paritytrading.juncture.hotspot.itch; | ||
|
||
import java.nio.BufferOverflowException; | ||
import java.nio.BufferUnderflowException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ReadOnlyBufferException; | ||
|
||
/** | ||
* Common definitions for Hotspot Book Protocol. | ||
*/ | ||
public class HotspotBook { | ||
|
||
private HotspotBook() { | ||
} | ||
|
||
public static final byte BUY = 'B'; | ||
public static final byte SELL = 'S'; | ||
|
||
public static final byte MESSAGE_TYPE_NEW_ORDER = 'N'; | ||
public static final byte MESSAGE_TYPE_MODIFY_ORDER = 'M'; | ||
public static final byte MESSAGE_TYPE_CANCEL_ORDER = 'X'; | ||
public static final byte MESSAGE_TYPE_MARKET_SNAPSHOT = 'S'; | ||
public static final byte MESSAGE_TYPE_TICKER = 'T'; | ||
|
||
/** | ||
* A message. | ||
*/ | ||
public interface Message { | ||
|
||
/** | ||
* Read this message from the buffer. | ||
* | ||
* @param buffer a buffer | ||
* @throws BufferUnderflowException if there are fewer bytes remaining | ||
* in the buffer than what this message consists of | ||
*/ | ||
void get(ByteBuffer buffer); | ||
|
||
/** | ||
* Write this message to the buffer. | ||
* | ||
* @param buffer a buffer | ||
* @throws BufferUnderflowException if there are fewer bytes remaining | ||
* in the buffer than what this message consists of | ||
* @throws ReadOnlyBufferException if the buffer is read-only | ||
*/ | ||
void put(ByteBuffer buffer); | ||
|
||
} | ||
|
||
/** | ||
* A New Order message (2.2.1). | ||
*/ | ||
public static class NewOrder implements Message { | ||
public byte buyOrSellIndicator; | ||
public byte[] currencyPair; | ||
public byte[] orderId; | ||
public byte[] price; | ||
public byte[] amount; | ||
public byte[] minqty; | ||
public byte[] lotsize; | ||
|
||
/** | ||
* Construct an instance. | ||
*/ | ||
public NewOrder() { | ||
currencyPair = new byte[7]; | ||
orderId = new byte[15]; | ||
price = new byte[10]; | ||
amount = new byte[16]; | ||
minqty = new byte[16]; | ||
lotsize = new byte[16]; | ||
} | ||
|
||
@Override | ||
public void get(ByteBuffer buffer) { | ||
buyOrSellIndicator = buffer.get(); | ||
buffer.get(currencyPair); | ||
buffer.get(orderId); | ||
buffer.get(price); | ||
buffer.get(amount); | ||
buffer.get(minqty); | ||
buffer.get(lotsize); | ||
} | ||
|
||
@Override | ||
public void put(ByteBuffer buffer) { | ||
buffer.put(MESSAGE_TYPE_NEW_ORDER); | ||
buffer.put(buyOrSellIndicator); | ||
buffer.put(currencyPair); | ||
buffer.put(orderId); | ||
buffer.put(price); | ||
buffer.put(amount); | ||
buffer.put(minqty); | ||
buffer.put(lotsize); | ||
} | ||
} | ||
|
||
/** | ||
* A Modify Order message (2.2.2). | ||
*/ | ||
public static class ModifyOrder implements Message { | ||
public byte[] currencyPair; | ||
public byte[] orderId; | ||
public byte[] amount; | ||
public byte[] minqty; | ||
public byte[] lotsize; | ||
|
||
/** | ||
* Construct an instance. | ||
*/ | ||
public ModifyOrder() { | ||
currencyPair = new byte[7]; | ||
orderId = new byte[15]; | ||
amount = new byte[16]; | ||
minqty = new byte[16]; | ||
lotsize = new byte[16]; | ||
} | ||
|
||
@Override | ||
public void get(ByteBuffer buffer) { | ||
buffer.get(currencyPair); | ||
buffer.get(orderId); | ||
buffer.get(amount); | ||
buffer.get(minqty); | ||
buffer.get(lotsize); | ||
} | ||
|
||
@Override | ||
public void put(ByteBuffer buffer) { | ||
buffer.put(MESSAGE_TYPE_MODIFY_ORDER); | ||
buffer.put(currencyPair); | ||
buffer.put(orderId); | ||
buffer.put(amount); | ||
buffer.put(minqty); | ||
buffer.put(lotsize); | ||
} | ||
} | ||
|
||
/** | ||
* A Cancel Order message (2.2.3). | ||
*/ | ||
public static class CancelOrder implements Message { | ||
public byte[] currencyPair; | ||
public byte[] orderId; | ||
|
||
/** | ||
* Construct an instance. | ||
*/ | ||
public CancelOrder() { | ||
currencyPair = new byte[7]; | ||
orderId = new byte[15]; | ||
} | ||
|
||
@Override | ||
public void get(ByteBuffer buffer) { | ||
buffer.get(currencyPair); | ||
buffer.get(orderId); | ||
} | ||
|
||
@Override | ||
public void put(ByteBuffer buffer) { | ||
buffer.put(MESSAGE_TYPE_CANCEL_ORDER); | ||
buffer.put(currencyPair); | ||
buffer.put(orderId); | ||
} | ||
} | ||
|
||
/** | ||
* An entry in a Market Snapshot message (2.2.4). | ||
*/ | ||
public static class MarketSnapshotEntry { | ||
public byte[] currencyPair; | ||
public byte buyOrSellIndicator; | ||
public byte[] price; | ||
public byte[] amount; | ||
public byte[] minqty; | ||
public byte[] lotsize; | ||
public byte[] orderId; | ||
|
||
/** | ||
* Construct an instance. | ||
*/ | ||
public MarketSnapshotEntry() { | ||
currencyPair = new byte[7]; | ||
price = new byte[10]; | ||
amount = new byte[16]; | ||
minqty = new byte[16]; | ||
lotsize = new byte[16]; | ||
orderId = new byte[15]; | ||
} | ||
} | ||
|
||
/** | ||
* A Ticker message (2.2.5). | ||
*/ | ||
public static class Ticker implements Message { | ||
public byte aggressorBuyOrSellIndicator; | ||
public byte[] currencyPair; | ||
public byte[] price; | ||
public byte[] transactionDate; | ||
public byte[] transactionTime; | ||
|
||
/** | ||
* Construct an instance. | ||
*/ | ||
public Ticker() { | ||
currencyPair = new byte[7]; | ||
price = new byte[10]; | ||
transactionDate = new byte[8]; | ||
transactionTime = new byte[6]; | ||
} | ||
|
||
@Override | ||
public void get(ByteBuffer buffer) { | ||
aggressorBuyOrSellIndicator = buffer.get(); | ||
buffer.get(currencyPair); | ||
buffer.get(price); | ||
buffer.get(transactionDate); | ||
buffer.get(transactionTime); | ||
} | ||
|
||
@Override | ||
public void put(ByteBuffer buffer) { | ||
buffer.put(MESSAGE_TYPE_TICKER); | ||
buffer.put(aggressorBuyOrSellIndicator); | ||
buffer.put(currencyPair); | ||
buffer.put(price); | ||
buffer.put(transactionDate); | ||
buffer.put(transactionTime); | ||
} | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...e-hotspot/src/main/java/com/paritytrading/juncture/hotspot/itch/HotspotBookException.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,19 @@ | ||
package com.paritytrading.juncture.hotspot.itch; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Indicates a protocol error while handling Hotspot Book Protocol. | ||
*/ | ||
public class HotspotBookException extends IOException { | ||
|
||
/** | ||
* Create an instance with the specified detail message. | ||
* | ||
* @param message the detail message | ||
*/ | ||
public HotspotBookException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
Oops, something went wrong.