-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
16 changed files
with
1,612 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ ehthumbs.db | |
# Folder config file | ||
Desktop.ini | ||
|
||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
|
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,134 @@ | ||
# Lightstreamer - Market Depth Demo - Java Adapter | ||
|
||
The *Market Depth Demo* is a very simple market depth application based on Lightstreamer for its real-time communication needs.<br> | ||
|
||
This project includes the server-side part of this demo, the Metadata and Data Adapters implementation. | ||
The client-side part of this demo, a web client front-end, is covered in this project: [Lightstreamer - Market Depth Demo - HTML Client](https://github.com/Weswit/Lightstreamer-example-MarketDepth-client-javascript). | ||
|
||
## Details | ||
|
||
Market depth is an electronic list of buy and sell orders, organized by price level and updated to reflect real-time market activity.<br> | ||
Market depth data are also known as Level II, Depth Of Market (DOM), and the order book.<br> | ||
<br> | ||
Lightstreamer has semi-native support for market depth, which can be managed very easily via COMMAND mode subscriptions. Basically, the bid and ask lists for an instrument will be two items subscribed to in COMMAND mode.<br> | ||
You will be able to add, update, and remove rows, where each row is identified by a key, which is the price. Lightstreamer will take care of aggregating updates to market depth in the most optimized way, based on bandwidth and frequency constraints.<br> | ||
This way, you will be able to manage full market depths even on unreliable networks and also benefit from update resampling with conflation, if needed.<br> | ||
|
||
### Dig the Code | ||
|
||
The project is comprised of source code and a deployment example. The main elements of the code are the Data Adapter, the MetaData Adapter, and the simulator of market orders. | ||
|
||
#### The Data Adapter | ||
|
||
The Data Adpter is implemented by the *MarketDepthDataAdapter* class. The class implement two interfaces: | ||
- *SmartDataProvider* that concerns relations with <b>Lightstreamer server<b>; | ||
- *MarketMaker* that models a very simple set of possible events from the trading market. | ||
|
||
#### The Metadata Adapter | ||
|
||
The Metadata Adpter is implemented by the *MarketDepthMetadataAdapter* class. The class inherits from the reusable [LiteralBasedProvider](https://github.com/Weswit/Lightstreamer-example-ReusableMetadata-adapter-java) and just adds a simple support for order entry by implementing the NotifyUserMessage method, to handle "sendMessage" requests from the client. | ||
The communication to the Market Orders Simulator, through the Data Adapter, is handled here. | ||
|
||
It should not be used as a reference for a real case of client-originated message handling, as no guaranteed delivery and no clustering support is shown. | ||
|
||
#### The Market Orders Simulator | ||
|
||
The *com.lightstreamer.adapters.MarketDepthDemo.orders_simulator* package contains the implementation of a very simple market orders simulator.<br> | ||
Orders are randomly generated for ask or bid around a reference price that is also randomly determined. Four stocks are managed, each with a different order generation frequency. | ||
The stocks are listed below in ascending order (from slower to faster): | ||
- *Old&Slow Company ...*, Item name: "OS_C"; | ||
- *BTTQ Industries Sa* Item name: "BTTQ_I"; | ||
- *AXY COMPANY Ltd*, Item name: "AXY_COMP"; | ||
- *SuperFast Tech.*, Item name: "SF_TECH". | ||
|
||
Once a fixed number of executions has been reached, the stock simulates the "End of Day" phase, in which both the order books, for buy and sell, are cleaned up, and the reference price is recalculated (this phase lasts 15 seconds). | ||
<br> | ||
See the source code comments for further details. | ||
|
||
### The Adapter Set Configuration | ||
|
||
This Adapter Set is configured and will be referenced by the clients as `MARKETDEPTH`. | ||
|
||
The `adapters.xml` file for the Market Depth Demo, should look like: | ||
```xml | ||
<?xml version="1.0"?> | ||
<adapters_conf id="MARKETDEPTH"> | ||
|
||
<!-- | ||
Not all configuration options of an Adapter Set are exposed by this file. | ||
You can easily expand your configurations using the generic template, | ||
`DOCS-SDKs/sdk_adapter_java_inprocess/doc/adapter_conf_template/adapters.xml`, | ||
as a reference. | ||
--> | ||
|
||
<metadata_adapter_initialised_first>Y</metadata_adapter_initialised_first> | ||
|
||
<metadata_provider> | ||
<adapter_class>com.lightstreamer.adapters.MarketDepthDemo.MarketDepthMetadataAdapter</adapter_class> | ||
|
||
<!-- Optional configuration file for the Adapter's own logging. | ||
Logging is managed through log4j. --> | ||
<param name="log_config">adapters_log_conf.xml</param> | ||
<param name="log_config_refresh_seconds">10</param> | ||
|
||
<param name="RND_GENERATOR_SUPERFAST">70</param> | ||
<param name="RND_GENERATOR_FAST">700</param> | ||
<param name="RND_GENERATOR_REGULAR">7000</param> | ||
<param name="RND_GENERATOR_SLOW">35000</param> | ||
|
||
<!-- Number of executions after which the "End Of Day" starts. --> | ||
<param name="TRADING_DAY_LASTING">5000</param> | ||
|
||
</metadata_provider> | ||
|
||
<data_provider> | ||
|
||
<adapter_class>com.lightstreamer.adapters.MarketDepthDemo.MarketDepthDataAdapter</adapter_class> | ||
|
||
</data_provider> | ||
</adapters_conf> | ||
``` | ||
|
||
<i>NOTE: not all configuration options of an Adapter Set are exposed by the file suggested above. | ||
You can easily expand your configurations using the generic template, `DOCS-SDKs/sdk_adapter_java_inprocess/doc/adapter_conf_template/adapters.xml`, as a reference.</i><br> | ||
<br> | ||
Please refer [here](http://www.lightstreamer.com/docs/base/General%20Concepts.pdf) for more details about Lightstreamer Adapters. | ||
|
||
## Install | ||
|
||
If you want to install a version of this demo in your local Lightstreamer Server, follow these steps: | ||
* Download *Lightstreamer Server* (Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from [Lightstreamer Download page](http://www.lightstreamer.com/download.htm), and install it, as explained in the `GETTING_STARTED.TXT` file in the installation home directory. | ||
* Get the `deploy.zip` file of the [latest release](https://github.com/Weswit/Lightstreamer-example-MarketDepth-adapter-java/releases), unzip it, and copy the just unzipped `MarketDepth` folder into the `adapters` folder of your Lightstreamer Server installation. | ||
* Launch Lightstreamer Server. | ||
* Test the Adapter, launching one of the clients listed in [Clients Using This Adapter](https://github.com/Weswit/Lightstreamer-example-MarketDepth-adapter-java#clients-using-this-adapter). | ||
|
||
|
||
## Build | ||
|
||
To build your own version of `LS_MarketDepth_adapters.jar`, instead of using the one provided in the `deploy.zip` file from the [Install](https://github.com/Weswit/Lightstreamer-example-MarketDepth-adapter-java#install) section above, follow these steps: | ||
* Clone this project. | ||
* Get the `ls-adapter-interface.jar` file from the [latest Lightstreamer distribution](http://www.lightstreamer.com/download), and copy it into the `lib` folder. | ||
* Get the `log4j-1.2.17.jar` file from [Apache log4j](https://logging.apache.org/log4j/1.2/) and copy it into the `lib` folder. | ||
* Create the jar `LS_MarketDepth_adapters.jar` with something like these commands: | ||
```sh | ||
>javac -source 1.7 -target 1.7 -nowarn -g -classpath compile_libs/log4j-1.2.17.jar;compile_libs/ls-adapter-interface/ls-adapter-interface.jar -sourcepath src -d tmp_classes src/com/lightstreamer/adapters/MarketDepthDemo/MarketDepthMetadataAdapter.java | ||
|
||
>jar cvf LS_MarketDepth_adapters.jar -C tmp_classes com | ||
``` | ||
* Stop Lightstreamer Server; copy the just compiled `LS_MarketDepth_adapters.jar` in the `/adapters/MarketDepth/lib` folder of your Lightstreamer Server installation; restart Lightstreamer Server. | ||
|
||
## See Also | ||
|
||
### Clients Using This Adapter | ||
|
||
* [Lightstreamer - Basic Market Depth Demo - JavaScript Client](https://github.com/Weswit/Lightstreamer-example-MarketDepth-client-javascript) | ||
|
||
### Related Projects | ||
|
||
* [Lightstreamer - Reusable Metadata Adapters - Java Adapter](https://github.com/Weswit/Lightstreamer-example-ReusableMetadata-adapter-java) | ||
* [Lightstreamer - Stock-List Demos - HTML Clients](https://github.com/Weswit/Lightstreamer-example-StockList-client-javascript) | ||
* [Lightstreamer - Portfolio Demos - HTML Clients](https://github.com/Weswit/Lightstreamer-example-Portfolio-client-javascript) | ||
|
||
## Lightstreamer Compatibility Notes | ||
|
||
* Compatible with Lightstreamer SDK for Java In-Process Adapters since 6.0 |
61 changes: 61 additions & 0 deletions
61
src/com/lightstreamer/adapters/MarketDepthDemo/Constants.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,61 @@ | ||
/* | ||
Copyright 2015 Weswit Srl | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.lightstreamer.adapters.MarketDepthDemo; | ||
|
||
import java.util.Map; | ||
|
||
public class Constants { | ||
public static final String LOGGER_CAT = "LS_demos_Logger.MarketDepthDemo.adapters"; | ||
|
||
public static final long MAX_QTY = 100000; | ||
|
||
public static final String BUY_SUFFIX = "_BUYSIDE"; | ||
|
||
public static final String SELL_SUFFIX = "_SELLSIDE"; | ||
|
||
public static long TRADING_DAY_LASTING = 750; | ||
|
||
public static long RND_GENERATOR_1 = 70; | ||
|
||
public static long RND_GENERATOR_2 = 700; | ||
|
||
public static long RND_GENERATOR_3 = 7000; | ||
|
||
public static long RND_GENERATOR_4 = 25000; | ||
|
||
public static void init(Map params) { | ||
|
||
if (params.containsKey("TRADING_DAY_LASTING")) { | ||
TRADING_DAY_LASTING = new Long((String)params.get("TRADING_DAY_LASTING")).longValue(); | ||
} | ||
if (params.containsKey("RND_GENERATOR_SUPERFAST")) { | ||
RND_GENERATOR_1 = new Long((String)params.get("RND_GENERATOR_SUPERFAST")).longValue(); | ||
} | ||
if (params.containsKey("RND_GENERATOR_FAST")) { | ||
RND_GENERATOR_2 = new Long((String)params.get("RND_GENERATOR_FAST")).longValue(); | ||
} | ||
if (params.containsKey("RND_GENERATOR_REGULAR")) { | ||
RND_GENERATOR_3 = new Long((String)params.get("RND_GENERATOR_REGULAR")).longValue(); | ||
} | ||
if (params.containsKey("RND_GENERATOR_SLOW")) { | ||
RND_GENERATOR_3 = new Long((String)params.get("RND_GENERATOR_SLOW")).longValue(); | ||
} | ||
|
||
return ; | ||
} | ||
|
||
} |
Oops, something went wrong.