Skip to content

Commit

Permalink
Merge pull request #4 from paritytrading/features/hotspot-itch
Browse files Browse the repository at this point in the history
Add Hotspot ITCH Protocol 1.59 support
  • Loading branch information
jvirtanen committed Apr 21, 2016
2 parents 15fac3c + bb25863 commit a7f2d74
Show file tree
Hide file tree
Showing 26 changed files with 3,002 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Features

Juncture implements connectivity to the following trading venues:

- [**Hotspot**](juncture-hotspot)
- [**NASDAQ**](juncture-nasdaq)


Expand Down
34 changes: 34 additions & 0 deletions juncture-hotspot/README.md
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.
33 changes: 33 additions & 0 deletions juncture-hotspot/pom.xml
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.paritytrading.juncture.hotspot.itch;

interface Clock {

long currentTimeMillis();

}
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);
}
}

}
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);
}

}
Loading

0 comments on commit a7f2d74

Please sign in to comment.