Converted to maven
This commit is contained in:
parent
2efa1d3d63
commit
bd7638c05a
21
pom.xml
Normal file
21
pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mycompany</groupId>
|
||||
<artifactId>MavenJava</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jfree</groupId>
|
||||
<artifactId>jfreechart</artifactId>
|
||||
<version>1.0.19</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<name>SeSim</name>
|
||||
</project>
|
56
src/main/java/gui/AskBook.java
Normal file
56
src/main/java/gui/AskBook.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Order.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class AskBook extends OrderBook {
|
||||
|
||||
@Override
|
||||
ArrayList getOrderBook() {
|
||||
return MainWin.se.getOrderBook(OrderType.ask,40);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean getDesc(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public AskBook(){
|
||||
if (MainWin.se == null) {
|
||||
return;
|
||||
}
|
||||
MainWin.se.addBookReceiver(OrderType.ask, this);
|
||||
|
||||
}
|
||||
|
||||
}
|
48
src/main/java/gui/BidBook.java
Normal file
48
src/main/java/gui/BidBook.java
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Order.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class BidBook extends OrderBook {
|
||||
|
||||
@Override
|
||||
ArrayList getOrderBook() {
|
||||
return MainWin.se.getOrderBook(OrderType.bid, 40);
|
||||
}
|
||||
|
||||
public BidBook() {
|
||||
if (MainWin.se == null) {
|
||||
return;
|
||||
}
|
||||
MainWin.se.addBookReceiver(OrderType.bid, this);
|
||||
}
|
||||
}
|
99
src/main/java/gui/CandlestickDemo.java
Normal file
99
src/main/java/gui/CandlestickDemo.java
Normal file
@ -0,0 +1,99 @@
|
||||
package gui;
|
||||
|
||||
import org.jfree.chart.*;
|
||||
import org.jfree.chart.axis.*;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.chart.renderer.xy.CandlestickRenderer;
|
||||
import org.jfree.data.xy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class CandlestickDemo extends JFrame {
|
||||
public CandlestickDemo(String stockSymbol) {
|
||||
super("CandlestickDemo");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
DateAxis domainAxis = new DateAxis("Date");
|
||||
NumberAxis rangeAxis = new NumberAxis("Price");
|
||||
CandlestickRenderer renderer = new CandlestickRenderer();
|
||||
XYDataset dataset = getDataSet(stockSymbol);
|
||||
|
||||
XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
|
||||
|
||||
//Do some setting up, see the API Doc
|
||||
renderer.setSeriesPaint(0, Color.BLACK);
|
||||
renderer.setDrawVolume(false);
|
||||
rangeAxis.setAutoRangeIncludesZero(false);
|
||||
domainAxis.setTimeline( SegmentedTimeline.newMondayThroughFridayTimeline() );
|
||||
|
||||
//Now create the chart and chart panel
|
||||
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
chartPanel.setPreferredSize(new Dimension(600, 300));
|
||||
|
||||
this.add(chartPanel);
|
||||
this.pack();
|
||||
}
|
||||
protected AbstractXYDataset getDataSet(String stockSymbol) {
|
||||
//This is the dataset we are going to create
|
||||
DefaultOHLCDataset result = null;
|
||||
//This is the data needed for the dataset
|
||||
OHLCDataItem[] data;
|
||||
|
||||
//This is where we go get the data, replace with your own data source
|
||||
data = getData(stockSymbol);
|
||||
|
||||
//Create a dataset, an Open, High, Low, Close dataset
|
||||
result = new DefaultOHLCDataset(stockSymbol, data);
|
||||
|
||||
return result;
|
||||
}
|
||||
//This method uses yahoo finance to get the OHLC data
|
||||
protected OHLCDataItem[] getData(String stockSymbol) {
|
||||
List<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>();
|
||||
try {
|
||||
String strUrl= "http://ichart.finance.yahoo.com/table.csv?s="+stockSymbol+"&a=0&b=1&c=2008&d=3&e=30&f=2008&ignore=.csv";
|
||||
URL url = new URL(strUrl);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
DateFormat df = new SimpleDateFormat("y-M-d");
|
||||
|
||||
String inputLine;
|
||||
in.readLine();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
StringTokenizer st = new StringTokenizer(inputLine, ",");
|
||||
|
||||
Date date = df.parse( st.nextToken() );
|
||||
double open = Double.parseDouble( st.nextToken() );
|
||||
double high = Double.parseDouble( st.nextToken() );
|
||||
double low = Double.parseDouble( st.nextToken() );
|
||||
double close = Double.parseDouble( st.nextToken() );
|
||||
double volume = Double.parseDouble( st.nextToken() );
|
||||
double adjClose = Double.parseDouble( st.nextToken() );
|
||||
|
||||
OHLCDataItem item = new OHLCDataItem(date, open, high, low, close, volume);
|
||||
dataItems.add(item);
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Data from Yahoo is from newest to oldest. Reverse so it is oldest to newest
|
||||
Collections.reverse(dataItems);
|
||||
|
||||
//Convert the list into an array
|
||||
OHLCDataItem[] data = dataItems.toArray(new OHLCDataItem[dataItems.size()]);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new CandlestickDemo("MSFT").setVisible(true);
|
||||
}
|
||||
}
|
30
src/main/java/gui/Chart.form
Normal file
30
src/main/java/gui/Chart.form
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JToggleButton" name="jToggleButton2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jToggleButton2"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
268
src/main/java/gui/Chart.java
Normal file
268
src/main/java/gui/Chart.java
Normal file
@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Exchange;
|
||||
import sesim.Exchange.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.axis.DateAxis;
|
||||
import org.jfree.chart.axis.NumberAxis;
|
||||
import org.jfree.chart.axis.SegmentedTimeline;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.chart.renderer.xy.CandlestickRenderer;
|
||||
import org.jfree.data.xy.AbstractXYDataset;
|
||||
import org.jfree.data.xy.DefaultOHLCDataset;
|
||||
import org.jfree.data.xy.OHLCDataItem;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
|
||||
import sesim.Quote;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class Chart extends javax.swing.JPanel implements QuoteReceiver {
|
||||
|
||||
/**
|
||||
* Creates new form Chart
|
||||
*/
|
||||
public Chart() {
|
||||
initComponents();
|
||||
|
||||
String stockSymbol = "Schliemanz Koch AG";
|
||||
//String stockSymbol = "MSFT";
|
||||
|
||||
DateAxis domainAxis = new DateAxis("Date");
|
||||
NumberAxis rangeAxis = new NumberAxis("Price");
|
||||
CandlestickRenderer renderer = new CandlestickRenderer();
|
||||
XYDataset dataset = getDataSet(stockSymbol);
|
||||
|
||||
XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
|
||||
|
||||
//Do some setting up, see the API Doc
|
||||
renderer.setSeriesPaint(0, Color.BLACK);
|
||||
renderer.setDrawVolume(false);
|
||||
rangeAxis.setAutoRangeIncludesZero(false);
|
||||
domainAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
|
||||
|
||||
//Now create the chart and chart panel
|
||||
JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false);
|
||||
ChartPanel chartPanel = new ChartPanel(chart);
|
||||
|
||||
chartPanel.setPreferredSize(new Dimension(500, 270));
|
||||
|
||||
add(chartPanel);
|
||||
System.out.print("Hallo Welt\n");
|
||||
|
||||
if (MainWin.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MainWin.se.addQuoteReceiver(this);
|
||||
|
||||
}
|
||||
|
||||
protected AbstractXYDataset getDataSet(String stockSymbol) {
|
||||
//This is the dataset we are going to create
|
||||
DefaultOHLCDataset result = null;
|
||||
//This is the data needed for the dataset
|
||||
OHLCDataItem[] data;
|
||||
|
||||
//This is where we go get the data, replace with your own data source
|
||||
data = getData();
|
||||
|
||||
//Create a dataset, an Open, High, Low, Close dataset
|
||||
result = new DefaultOHLCDataset(stockSymbol, data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected OHLCDataItem getOhlcData(long first, long last, SortedSet<Quote> quotes) {
|
||||
|
||||
Quote s = new Quote();
|
||||
|
||||
s.time = first;
|
||||
|
||||
SortedSet<Quote> l = quotes.tailSet(s);
|
||||
|
||||
double open = 0;
|
||||
double high = 0;
|
||||
double low = 0;
|
||||
double close = 0;
|
||||
double volume=0;
|
||||
|
||||
Iterator<Quote> it = l.iterator();
|
||||
|
||||
Quote q;
|
||||
|
||||
|
||||
if (it.hasNext()) {
|
||||
q = it.next();
|
||||
open = q.price;
|
||||
high = q.price;
|
||||
low = q.price;
|
||||
volume = q.volume;
|
||||
}
|
||||
else {
|
||||
q = new Quote();
|
||||
}
|
||||
|
||||
|
||||
while (it.hasNext() && q.time < last) {
|
||||
q = it.next();
|
||||
|
||||
if (q.price > high) {
|
||||
high = q.price;
|
||||
}
|
||||
if (q.price < low) {
|
||||
low = q.price;
|
||||
}
|
||||
|
||||
volume += q.volume;
|
||||
|
||||
}
|
||||
close = q.price;
|
||||
|
||||
Date date = new Date(first);
|
||||
return new OHLCDataItem(
|
||||
date, open, high, low, close, volume
|
||||
);
|
||||
}
|
||||
|
||||
protected OHLCDataItem[] getData() {
|
||||
|
||||
List<OHLCDataItem> data = new ArrayList<>();
|
||||
|
||||
long ct;
|
||||
ct = Exchange.getCurrentTimeSeconds(10);
|
||||
|
||||
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 60);
|
||||
|
||||
for (long i = (ct - 60)*1000; i < (ct + 10)*1000; i += 10*1000) {
|
||||
OHLCDataItem d = getOhlcData(i, i + 10*1000, h);
|
||||
data.add(d);
|
||||
}
|
||||
|
||||
System.out.print(data.size() + "\n");
|
||||
// System.exit(0);
|
||||
|
||||
return data.toArray(new OHLCDataItem[data.size()]);
|
||||
|
||||
}
|
||||
|
||||
//This method uses yahoo finance to get the OHLC data
|
||||
protected OHLCDataItem[] getData_old() {
|
||||
String stockSymbol = "MSFT";
|
||||
List<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>();
|
||||
try {
|
||||
String strUrl = "http://ichart.finance.yahoo.com/table.csv?s=" + stockSymbol + "&a=0&b=1&c=2008&d=3&e=30&f=2008&ignore=.csv";
|
||||
URL url = new URL(strUrl);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
DateFormat df = new SimpleDateFormat("y-M-d");
|
||||
|
||||
String inputLine;
|
||||
in.readLine();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
StringTokenizer st = new StringTokenizer(inputLine, ",");
|
||||
|
||||
Date date = df.parse(st.nextToken());
|
||||
double open = Double.parseDouble(st.nextToken());
|
||||
double high = Double.parseDouble(st.nextToken());
|
||||
double low = Double.parseDouble(st.nextToken());
|
||||
double close = Double.parseDouble(st.nextToken());
|
||||
double volume = Double.parseDouble(st.nextToken());
|
||||
double adjClose = Double.parseDouble(st.nextToken());
|
||||
|
||||
OHLCDataItem item = new OHLCDataItem(date, open, high, low, close, volume);
|
||||
dataItems.add(item);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Data from Yahoo is from newest to oldest. Reverse so it is oldest to newest
|
||||
Collections.reverse(dataItems);
|
||||
|
||||
//Convert the list into an array
|
||||
OHLCDataItem[] data = dataItems.toArray(new OHLCDataItem[dataItems.size()]);
|
||||
|
||||
System.out.print("Return oghls old data items\n");
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jToggleButton2 = new javax.swing.JToggleButton();
|
||||
|
||||
setLayout(new java.awt.BorderLayout());
|
||||
|
||||
jToggleButton2.setText("jToggleButton2");
|
||||
add(jToggleButton2, java.awt.BorderLayout.CENTER);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JToggleButton jToggleButton2;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
@Override
|
||||
public void UpdateQuote(Quote q) {
|
||||
return;
|
||||
//q.print();
|
||||
/* SortedSet h = MainWin.se.getQuoteHistory(60);
|
||||
System.out.print(
|
||||
"SortedSet size:"
|
||||
+ h.size()
|
||||
+ "\n"
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
76
src/main/java/gui/ControlPanel.form
Normal file
76
src/main/java/gui/ControlPanel.form
Normal file
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
<Property name="columns" type="int" value="0"/>
|
||||
<Property name="rows" type="int" value="3"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="SellButton">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="c" green="0" red="b5" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
|
||||
<FontInfo relative="true">
|
||||
<Font bold="true" component="SellButton" property="font" relativeSize="true" size="12"/>
|
||||
</FontInfo>
|
||||
</Property>
|
||||
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="fe" green="fe" red="fe" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Sell"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="SellButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextArea" name="jTextArea1">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
<Property name="rows" type="int" value="5"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JButton" name="BuyButton">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="1" green="5e" red="5" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
|
||||
<FontInfo relative="true">
|
||||
<Font bold="true" component="BuyButton" property="font" relativeSize="true" size="12"/>
|
||||
</FontInfo>
|
||||
</Property>
|
||||
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="fe" green="fe" red="fe" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Buy"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="BuyButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
101
src/main/java/gui/ControlPanel.java
Normal file
101
src/main/java/gui/ControlPanel.java
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ControlPanel extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form ControlPanel
|
||||
*/
|
||||
public ControlPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
SellButton = new javax.swing.JButton();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
jTextArea1 = new javax.swing.JTextArea();
|
||||
BuyButton = new javax.swing.JButton();
|
||||
|
||||
setLayout(new java.awt.GridLayout(3, 0));
|
||||
|
||||
SellButton.setBackground(new java.awt.Color(181, 0, 12));
|
||||
SellButton.setFont(SellButton.getFont().deriveFont(SellButton.getFont().getStyle() | java.awt.Font.BOLD, SellButton.getFont().getSize()+12));
|
||||
SellButton.setForeground(new java.awt.Color(254, 254, 254));
|
||||
SellButton.setText("Sell");
|
||||
SellButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
SellButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
add(SellButton);
|
||||
|
||||
jTextArea1.setColumns(20);
|
||||
jTextArea1.setRows(5);
|
||||
jScrollPane1.setViewportView(jTextArea1);
|
||||
|
||||
add(jScrollPane1);
|
||||
|
||||
BuyButton.setBackground(new java.awt.Color(5, 94, 1));
|
||||
BuyButton.setFont(BuyButton.getFont().deriveFont(BuyButton.getFont().getStyle() | java.awt.Font.BOLD, BuyButton.getFont().getSize()+12));
|
||||
BuyButton.setForeground(new java.awt.Color(254, 254, 254));
|
||||
BuyButton.setText("Buy");
|
||||
BuyButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
BuyButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
add(BuyButton);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void SellButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SellButtonActionPerformed
|
||||
MainWin.myAccount.sell(81, 55.0);
|
||||
}//GEN-LAST:event_SellButtonActionPerformed
|
||||
|
||||
private void BuyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BuyButtonActionPerformed
|
||||
MainWin.myAccount.buy(44, 66.0);
|
||||
}//GEN-LAST:event_BuyButtonActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton BuyButton;
|
||||
private javax.swing.JButton SellButton;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JTextArea jTextArea1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
105
src/main/java/gui/MainWin.form
Normal file
105
src/main/java/gui/MainWin.form
Normal file
@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jButton1"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JMenuItem" name="jMenuItem1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jMenuItem1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Menu class="javax.swing.JMenuBar" name="MainMenu">
|
||||
<SubComponents>
|
||||
<Menu class="javax.swing.JMenu" name="FileMenu">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="1" green="cb" red="fe" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="File"/>
|
||||
</Properties>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="FileNew">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="New"/>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="null"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="FileNewActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="FileRun">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Run"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="FileRunActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
<Menu class="javax.swing.JMenu" name="jMenu2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Edit"/>
|
||||
</Properties>
|
||||
</Menu>
|
||||
</SubComponents>
|
||||
</Menu>
|
||||
</NonVisualComponents>
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[640, 480]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="MainMenu"/>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,93,0,0,2,-69"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="gui.ControlPanel" name="controlPanel2">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="After"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="gui.OrderBookPanel" name="orderBookPanel1">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Before"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="gui.Chart" name="zZChart1">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
224
src/main/java/gui/MainWin.java
Normal file
224
src/main/java/gui/MainWin.java
Normal file
@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import traders.RandomTraderConfig;
|
||||
import traders.SwitchingTraderConfig;
|
||||
import sesim.Account;
|
||||
import sesim.AutoTraderLIst;
|
||||
import sesim.Exchange;
|
||||
import sesim.BuyOrder;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class MainWin extends javax.swing.JFrame {
|
||||
|
||||
static sesim.Exchange se;
|
||||
static sesim.Account myAccount;
|
||||
static traders.ManTrader myTrader;
|
||||
|
||||
/**
|
||||
* Creates new form MainWin
|
||||
*/
|
||||
public MainWin() {
|
||||
|
||||
initComponents();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jMenuItem1 = new javax.swing.JMenuItem();
|
||||
controlPanel2 = new gui.ControlPanel();
|
||||
orderBookPanel1 = new gui.OrderBookPanel();
|
||||
zZChart1 = new gui.Chart();
|
||||
MainMenu = new javax.swing.JMenuBar();
|
||||
FileMenu = new javax.swing.JMenu();
|
||||
FileNew = new javax.swing.JMenuItem();
|
||||
FileRun = new javax.swing.JMenuItem();
|
||||
jMenu2 = new javax.swing.JMenu();
|
||||
|
||||
jButton1.setText("jButton1");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jMenuItem1.setText("jMenuItem1");
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setMinimumSize(new java.awt.Dimension(640, 480));
|
||||
getContentPane().add(controlPanel2, java.awt.BorderLayout.LINE_END);
|
||||
getContentPane().add(orderBookPanel1, java.awt.BorderLayout.LINE_START);
|
||||
getContentPane().add(zZChart1, java.awt.BorderLayout.CENTER);
|
||||
|
||||
FileMenu.setBackground(new java.awt.Color(254, 203, 1));
|
||||
FileMenu.setText("File");
|
||||
|
||||
FileNew.setText("New");
|
||||
FileNew.setBorder(null);
|
||||
FileNew.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
FileNewActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
FileMenu.add(FileNew);
|
||||
|
||||
FileRun.setText("Run");
|
||||
FileRun.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
FileRunActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
FileMenu.add(FileRun);
|
||||
|
||||
MainMenu.add(FileMenu);
|
||||
|
||||
jMenu2.setText("Edit");
|
||||
MainMenu.add(jMenu2);
|
||||
|
||||
setJMenuBar(MainMenu);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void FileNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileNewActionPerformed
|
||||
|
||||
|
||||
}//GEN-LAST:event_FileNewActionPerformed
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
private void FileRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileRunActionPerformed
|
||||
se.start();
|
||||
}//GEN-LAST:event_FileRunActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
|
||||
se = new Exchange();
|
||||
myAccount = new Account(se,1000,100000000.0);
|
||||
myTrader = new traders.ManTrader(myAccount,null);
|
||||
|
||||
/* Account otherAccount = new Account(se,1000,1000);
|
||||
Traders.ManTrader otherTrader = new Traders.ManTrader(otherAccount);
|
||||
otherTrader.sell(80, 22.70);
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Account traccount = new Account(se,5500,1000000.0);
|
||||
RandomTrader rt = new RandomTrader(traccount,null);
|
||||
TraderRunner tr = new TraderRunner(rt);
|
||||
tr.start();
|
||||
*/
|
||||
|
||||
AutoTraderLIst at = new AutoTraderLIst();
|
||||
// RandomTraderConfig rcfg = new RandomTraderConfig();
|
||||
SwitchingTraderConfig rcfg = new SwitchingTraderConfig();
|
||||
at.add(1000, rcfg, se, 100, 0);
|
||||
at.add(1000, rcfg, se, 0, 10000);
|
||||
|
||||
|
||||
SwitchingTraderConfig scfg = new SwitchingTraderConfig();
|
||||
at.add(1, scfg, se, 1000000, 0);
|
||||
|
||||
|
||||
// at.add(10, rcfg, se, 1000000, 0);
|
||||
|
||||
|
||||
try {
|
||||
// Set cross-platform Java L&F (also called "Metal")
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
||||
} catch (UnsupportedLookAndFeelException | ClassNotFoundException |
|
||||
InstantiationException | IllegalAccessException e) {
|
||||
}
|
||||
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
/* try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Motif".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(MainWin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
*/
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new MainWin().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JMenu FileMenu;
|
||||
private javax.swing.JMenuItem FileNew;
|
||||
private javax.swing.JMenuItem FileRun;
|
||||
private javax.swing.JMenuBar MainMenu;
|
||||
private gui.ControlPanel controlPanel2;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JMenu jMenu2;
|
||||
private javax.swing.JMenuItem jMenuItem1;
|
||||
private gui.OrderBookPanel orderBookPanel1;
|
||||
private gui.Chart zZChart1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
18
src/main/java/gui/NewPanel.form
Normal file
18
src/main/java/gui/NewPanel.form
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.2" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
</Form>
|
128
src/main/java/gui/NewPanel.java
Normal file
128
src/main/java/gui/NewPanel.java
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
//import static Gui.SimpleJFreeDemo.createDemoPanel;
|
||||
import javax.swing.JPanel;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.jfree.chart.JFreeChart;
|
||||
import org.jfree.chart.plot.PlotOrientation;
|
||||
import org.jfree.chart.plot.XYPlot;
|
||||
import org.jfree.data.function.Function2D;
|
||||
import org.jfree.data.general.DatasetUtilities;
|
||||
import org.jfree.data.xy.XYDataset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class NewPanel extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form NewPanel
|
||||
*/
|
||||
public NewPanel() {
|
||||
initComponents();
|
||||
|
||||
initComponents();
|
||||
JPanel chartPanel = createDemoPanel();
|
||||
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
|
||||
add(chartPanel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static JFreeChart createChart(XYDataset dataset) {
|
||||
// create the chart...
|
||||
JFreeChart chart = ChartFactory.createXYLineChart(
|
||||
"Function2DDemo1 ", // chart title
|
||||
"X", // x axis label
|
||||
"Y", // y axis label
|
||||
dataset, // data
|
||||
PlotOrientation.VERTICAL,
|
||||
true, // include legend
|
||||
true, // tooltips
|
||||
false // urls
|
||||
);
|
||||
|
||||
XYPlot plot = (XYPlot) chart.getPlot();
|
||||
plot.getDomainAxis().setLowerMargin(0.0);
|
||||
plot.getDomainAxis().setUpperMargin(0.0);
|
||||
return chart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sample dataset.
|
||||
*
|
||||
* @return A sample dataset.
|
||||
*/
|
||||
public static XYDataset createDataset() {
|
||||
XYDataset result = DatasetUtilities.sampleFunction2D(new X2(),
|
||||
-4.0, 4.0, 40, "f(x)");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a panel for the demo (used by SuperDemo.java).
|
||||
*
|
||||
* @return A panel.
|
||||
*/
|
||||
public static JPanel createDemoPanel() {
|
||||
JFreeChart chart = createChart(createDataset());
|
||||
return new ChartPanel(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple function.
|
||||
*/
|
||||
static class X2 implements Function2D {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.jfree.data.function.Function2D#getValue(double)
|
||||
*/
|
||||
public double getValue(double x) {
|
||||
return x * x + 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
setLayout(new java.awt.BorderLayout());
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
83
src/main/java/gui/OrderBook.form
Normal file
83
src/main/java/gui/OrderBook.form
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="orderBookScroller" alignment="1" pref="162" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="orderBookScroller" alignment="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JScrollPane" name="orderBookScroller">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="orderBookList">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
|
||||
<Table columnCount="3" rowCount="30">
|
||||
<Column editable="false" title="id" type="java.lang.Object">
|
||||
<Data value="1"/>
|
||||
<Data value="2"/>
|
||||
<Data value="3"/>
|
||||
<Data value="4"/>
|
||||
<Data value="5"/>
|
||||
<Data value="7"/>
|
||||
<Data value="4"/>
|
||||
<Data value="null"/>
|
||||
<Data value="3"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
<Data value="null"/>
|
||||
</Column>
|
||||
<Column editable="false" title="Title 2pri" type="java.lang.Object"/>
|
||||
<Column editable="false" title="Title 3" type="java.lang.Object"/>
|
||||
</Table>
|
||||
</Property>
|
||||
<Property name="doubleBuffered" type="boolean" value="true"/>
|
||||
<Property name="focusable" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
276
src/main/java/gui/OrderBook.java
Normal file
276
src/main/java/gui/OrderBook.java
Normal file
@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Exchange;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Formatter;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
/**
|
||||
* OderBook Class
|
||||
*/
|
||||
public abstract class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiver {
|
||||
|
||||
|
||||
OrderBookListModel model;
|
||||
|
||||
abstract ArrayList getOrderBook();
|
||||
|
||||
private Color hdr_color = Color.LIGHT_GRAY;
|
||||
|
||||
private class OrderBookCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table,
|
||||
Object value, boolean isSelected, boolean hasFocus,
|
||||
int row, int column) {
|
||||
DefaultTableCellRenderer renderer
|
||||
= (DefaultTableCellRenderer) super.getTableCellRendererComponent(
|
||||
table, value, isSelected, hasFocus, row, column);
|
||||
renderer.setBackground(hdr_color);
|
||||
return renderer;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void UpdateOrderBook() {
|
||||
|
||||
class Updater implements Runnable{
|
||||
OrderBookListModel model;
|
||||
ArrayList newlist;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
model.update(this.newlist);
|
||||
}
|
||||
|
||||
Updater(OrderBookListModel model, ArrayList newlist){
|
||||
this.model = model;
|
||||
this.newlist = newlist;
|
||||
}
|
||||
|
||||
}
|
||||
ArrayList newlist = getOrderBook();
|
||||
SwingUtilities.invokeLater(new Updater(this.model,newlist));
|
||||
|
||||
}
|
||||
|
||||
boolean getDesc() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// protected OrderBookListModel model;
|
||||
|
||||
protected class OrderBookListModel extends AbstractTableModel {
|
||||
|
||||
private ArrayList list;
|
||||
private boolean desc = false;
|
||||
|
||||
public OrderBookListModel() {
|
||||
// System.out.print("CREATING A NEW MODEL\n");
|
||||
// update();
|
||||
list = getOrderBook();
|
||||
}
|
||||
|
||||
int update_calls = 0;
|
||||
int colcount_calls = 0;
|
||||
|
||||
public void update(ArrayList newlist) {
|
||||
list = newlist; //getOrderBook();
|
||||
this.fireTableDataChanged();
|
||||
|
||||
this.update_calls++;
|
||||
int hc = this.hashCode();
|
||||
//System.out.print("Update/ColCalls = " + update_calls + "/" + colcount_calls + " HC: " + hc + "\n");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getColumnName(int c) {
|
||||
switch (c) {
|
||||
case 0:
|
||||
return "ID";
|
||||
case 1:
|
||||
return "Price";
|
||||
case 2:
|
||||
return "Vol.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
colcount_calls++;
|
||||
// System.out.print("Update/ColCalls = " + update_calls + "/" + colcount_calls + "\n");
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int r, int c) {
|
||||
sesim.Order o;
|
||||
|
||||
int s = list.size();
|
||||
//System.out.print("Looking for Value at" + r + ":" + c + " w size:" + s + "\n");
|
||||
|
||||
if (!getDesc()) {
|
||||
o = (sesim.Order) list.get(r);
|
||||
} else {
|
||||
o = (sesim.Order) list.get(list.size() - r - 1);
|
||||
}
|
||||
Formatter f = new Formatter();
|
||||
switch (c) {
|
||||
case 0:
|
||||
return f.format("#%06x", o.id);
|
||||
|
||||
case 1:
|
||||
return o.limit;
|
||||
case 2:
|
||||
return o.volume;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form OrderBook
|
||||
*/
|
||||
public OrderBook() {
|
||||
//System.out.print("init Orderbook]\n");
|
||||
initComponents();
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder());
|
||||
this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
|
||||
|
||||
if (MainWin.se == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.model = new OrderBookListModel();
|
||||
this.orderBookList.setModel(model);
|
||||
|
||||
orderBookList.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
JTableHeader h = this.orderBookList.getTableHeader();
|
||||
h.setBackground(hdr_color);
|
||||
h.setForeground(Color.green);
|
||||
h.setDefaultRenderer(new OrderBookCellRenderer());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
orderBookScroller = new javax.swing.JScrollPane();
|
||||
orderBookList = new javax.swing.JTable();
|
||||
|
||||
orderBookList.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
{"1", null, null},
|
||||
{"2", null, null},
|
||||
{"3", null, null},
|
||||
{"4", null, null},
|
||||
{"5", null, null},
|
||||
{"7", null, null},
|
||||
{"4", null, null},
|
||||
{null, null, null},
|
||||
{"3", null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null},
|
||||
{null, null, null}
|
||||
},
|
||||
new String [] {
|
||||
"id", "Title 2pri", "Title 3"
|
||||
}
|
||||
) {
|
||||
boolean[] canEdit = new boolean [] {
|
||||
false, false, false
|
||||
};
|
||||
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return canEdit [columnIndex];
|
||||
}
|
||||
});
|
||||
orderBookList.setDoubleBuffered(true);
|
||||
orderBookList.setFocusable(false);
|
||||
orderBookScroller.setViewportView(orderBookList);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(orderBookScroller, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(orderBookScroller, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JTable orderBookList;
|
||||
private javax.swing.JScrollPane orderBookScroller;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
459
src/main/java/gui/OrderBookPanel.form
Normal file
459
src/main/java/gui/OrderBookPanel.form
Normal file
@ -0,0 +1,459 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<Properties>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[220, 262]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,41,0,0,2,75"/>
|
||||
</AuxValues>
|
||||
<SubComponents>
|
||||
<Component class="gui.AskBook" name="askBook1">
|
||||
<Properties>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[200, 200]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="gui.BidBook" name="bidBook1">
|
||||
<Properties>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[200, 200]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="0" gridY="4" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Container class="gui.QuotePanel" name="quotePanel2">
|
||||
<Properties>
|
||||
<Property name="opaque" type="boolean" value="false"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[587, 200]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.5" weightY="0.5"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
<LayoutCode>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="1_quotePanel2Layout">
|
||||
<CodeVariable name="quotePanel2Layout" type="4096" declaredType="java.awt.GridBagLayout"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagLayout" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="1_quotePanel2Layout"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="1_quotePanel2Layout"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="columnWidths" class="java.awt.GridBagLayout"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="2">
|
||||
<ExpressionOrigin>
|
||||
<Value type="[I" editor="org.netbeans.modules.form.layoutsupport.delegates.GridBagLayoutSupport$IntArrayPropertyEditor">
|
||||
<PropertyValue value="[0, 5, 0, 5, 0]"/>
|
||||
</Value>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="1_quotePanel2Layout"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="rowHeights" class="java.awt.GridBagLayout"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="3">
|
||||
<ExpressionOrigin>
|
||||
<Value type="[I" editor="org.netbeans.modules.form.layoutsupport.delegates.GridBagLayoutSupport$IntArrayPropertyEditor">
|
||||
<PropertyValue value="[0]"/>
|
||||
</Value>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="4_quotePanel2">
|
||||
<CodeVariable name="quotePanel2" type="8194" declaredType="gui.QuotePanel"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="quotePanel2"/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="setLayout" class="java.awt.Container" parameterTypes="java.awt.LayoutManager"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="1_quotePanel2Layout"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
</LayoutCode>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
<LayoutCode>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="5_layout">
|
||||
<CodeVariable name="layout" type="4096" declaredType="java.awt.GridBagLayout"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagLayout" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="5_layout"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="5_layout"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="columnWidths" class="java.awt.GridBagLayout"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="6">
|
||||
<ExpressionOrigin>
|
||||
<Value type="[I" editor="org.netbeans.modules.form.layoutsupport.delegates.GridBagLayoutSupport$IntArrayPropertyEditor">
|
||||
<PropertyValue value="[0]"/>
|
||||
</Value>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="5_layout"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="rowHeights" class="java.awt.GridBagLayout"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="7">
|
||||
<ExpressionOrigin>
|
||||
<Value type="[I" editor="org.netbeans.modules.form.layoutsupport.delegates.GridBagLayoutSupport$IntArrayPropertyEditor">
|
||||
<PropertyValue value="[0, 5, 0, 5, 0]"/>
|
||||
</Value>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="8">
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="."/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="setLayout" class="java.awt.Container" parameterTypes="java.awt.LayoutManager"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="5_layout"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints">
|
||||
<CodeVariable name="gridBagConstraints" type="20480" declaredType="java.awt.GridBagConstraints"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagConstraints" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="10">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridy" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="11">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="fill" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="12">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="1"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weightx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="13">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="1.0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weighty" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="14">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="1.0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="8"/>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="15_askBook1">
|
||||
<CodeVariable name="askBook1" type="8194" declaredType="gui.AskBook"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="askBook1"/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints">
|
||||
<CodeVariable name="gridBagConstraints"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagConstraints" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="17">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridy" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="18">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="4"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="fill" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="19">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="1"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weightx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="20">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="1.0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weighty" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="21">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="1.0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="8"/>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="22_bidBook1">
|
||||
<CodeVariable name="bidBook1" type="8194" declaredType="gui.BidBook"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="bidBook1"/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="23_gridBagConstraints">
|
||||
<CodeVariable name="gridBagConstraints"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagConstraints" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="24">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridy" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="25">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="2"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="fill" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="26">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="1"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weightx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="27">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="0.5"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weighty" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="28">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="0.5"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="8"/>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="4_quotePanel2"/>
|
||||
<CodeExpression id="23_gridBagConstraints"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
</LayoutCode>
|
||||
</Form>
|
111
src/main/java/gui/OrderBookPanel.java
Normal file
111
src/main/java/gui/OrderBookPanel.java
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
//import SeSim.*;
|
||||
import static java.lang.Thread.sleep;
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Formatter;
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class OrderBookPanel extends javax.swing.JPanel {
|
||||
|
||||
sesim.Exchange se;
|
||||
|
||||
public OrderBookPanel() {
|
||||
this.se = MainWin.se;
|
||||
|
||||
initComponents();
|
||||
|
||||
if (this.se == null) {
|
||||
return;
|
||||
}
|
||||
// System.out.print("Order boo init\n");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
java.awt.GridBagConstraints gridBagConstraints;
|
||||
|
||||
askBook1 = new gui.AskBook();
|
||||
bidBook1 = new gui.BidBook();
|
||||
quotePanel2 = new gui.QuotePanel();
|
||||
|
||||
setPreferredSize(new java.awt.Dimension(220, 262));
|
||||
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
|
||||
layout.columnWidths = new int[] {0};
|
||||
layout.rowHeights = new int[] {0, 5, 0, 5, 0};
|
||||
setLayout(layout);
|
||||
|
||||
askBook1.setPreferredSize(new java.awt.Dimension(200, 200));
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 1.0;
|
||||
gridBagConstraints.weighty = 1.0;
|
||||
add(askBook1, gridBagConstraints);
|
||||
|
||||
bidBook1.setPreferredSize(new java.awt.Dimension(200, 200));
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 4;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 1.0;
|
||||
gridBagConstraints.weighty = 1.0;
|
||||
add(bidBook1, gridBagConstraints);
|
||||
|
||||
quotePanel2.setOpaque(false);
|
||||
quotePanel2.setPreferredSize(new java.awt.Dimension(587, 200));
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 2;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 0.5;
|
||||
gridBagConstraints.weighty = 0.5;
|
||||
add(quotePanel2, gridBagConstraints);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private gui.AskBook askBook1;
|
||||
private gui.BidBook bidBook1;
|
||||
private gui.QuotePanel quotePanel2;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
326
src/main/java/gui/QuotePanel.form
Normal file
326
src/main/java/gui/QuotePanel.form
Normal file
@ -0,0 +1,326 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.8" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="null"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,66,0,0,1,99"/>
|
||||
</AuxValues>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel2">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="lastPrice">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
|
||||
<FontInfo relative="true">
|
||||
<Font bold="true" component="lastPrice" property="font" relativeSize="true" size="4"/>
|
||||
</FontInfo>
|
||||
</Property>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="0.00"/>
|
||||
<Property name="opaque" type="boolean" value="true"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="2" gridY="0" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.9" weightY="0.9"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel3">
|
||||
<Properties>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 18]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
|
||||
<GridBagConstraints gridX="4" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
<LayoutCode>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="1_layout">
|
||||
<CodeVariable name="layout" type="4096" declaredType="java.awt.GridBagLayout"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagLayout" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="1_layout"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="1_layout"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="columnWidths" class="java.awt.GridBagLayout"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="2">
|
||||
<ExpressionOrigin>
|
||||
<Value type="[I" editor="org.netbeans.modules.form.layoutsupport.delegates.GridBagLayoutSupport$IntArrayPropertyEditor">
|
||||
<PropertyValue value="[0, 5, 0, 5, 0]"/>
|
||||
</Value>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="1_layout"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="rowHeights" class="java.awt.GridBagLayout"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="3">
|
||||
<ExpressionOrigin>
|
||||
<Value type="[I" editor="org.netbeans.modules.form.layoutsupport.delegates.GridBagLayoutSupport$IntArrayPropertyEditor">
|
||||
<PropertyValue value="[0]"/>
|
||||
</Value>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="4">
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="."/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="setLayout" class="java.awt.Container" parameterTypes="java.awt.LayoutManager"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="1_layout"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="5_gridBagConstraints">
|
||||
<CodeVariable name="gridBagConstraints" type="20480" declaredType="java.awt.GridBagConstraints"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagConstraints" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="5_gridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="5_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="6">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="5_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridy" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="7">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="4"/>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="8_jLabel2">
|
||||
<CodeVariable name="jLabel2" type="8194" declaredType="javax.swing.JLabel"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="jLabel2"/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<CodeExpression id="5_gridBagConstraints"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints">
|
||||
<CodeVariable name="gridBagConstraints"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagConstraints" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="10">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="2"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridy" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="11">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="fill" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="12">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="1"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weightx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="13">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="0.9"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="weighty" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="14">
|
||||
<ExpressionOrigin>
|
||||
<Value type="double" value="0.9"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="4"/>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="15_lastPrice">
|
||||
<CodeVariable name="lastPrice" type="8194" declaredType="javax.swing.JLabel"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="lastPrice"/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<CodeExpression id="9_gridBagConstraints"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints">
|
||||
<CodeVariable name="gridBagConstraints"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="CodeConstructor">
|
||||
<CodeConstructor class="java.awt.GridBagConstraints" parameterTypes=""/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<StatementProvider type="CodeExpression">
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridx" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="17">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="4"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
<StatementProvider type="CodeField">
|
||||
<CodeField name="gridy" class="java.awt.GridBagConstraints"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="18">
|
||||
<ExpressionOrigin>
|
||||
<Value type="int" value="0"/>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
<CodeStatement>
|
||||
<CodeExpression id="4"/>
|
||||
<StatementProvider type="CodeMethod">
|
||||
<CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
|
||||
</StatementProvider>
|
||||
<Parameters>
|
||||
<CodeExpression id="19_jLabel3">
|
||||
<CodeVariable name="jLabel3" type="8194" declaredType="javax.swing.JLabel"/>
|
||||
<ExpressionOrigin>
|
||||
<ExpressionProvider type="ComponentRef">
|
||||
<ComponentRef name="jLabel3"/>
|
||||
</ExpressionProvider>
|
||||
</ExpressionOrigin>
|
||||
</CodeExpression>
|
||||
<CodeExpression id="16_gridBagConstraints"/>
|
||||
</Parameters>
|
||||
</CodeStatement>
|
||||
</LayoutCode>
|
||||
</Form>
|
142
src/main/java/gui/QuotePanel.java
Normal file
142
src/main/java/gui/QuotePanel.java
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import sesim.Quote;
|
||||
import java.awt.Color;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class QuotePanel extends javax.swing.JPanel implements sesim.Exchange.QuoteReceiver{
|
||||
|
||||
/**
|
||||
* Creates new form QuotePanel
|
||||
*/
|
||||
public QuotePanel() {
|
||||
initComponents();
|
||||
if (MainWin.se==null)
|
||||
return;
|
||||
MainWin.se.addQuoteReceiver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
java.awt.GridBagConstraints gridBagConstraints;
|
||||
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
lastPrice = new javax.swing.JLabel();
|
||||
jLabel3 = new javax.swing.JLabel();
|
||||
|
||||
setBorder(null);
|
||||
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
|
||||
layout.columnWidths = new int[] {0, 5, 0, 5, 0};
|
||||
layout.rowHeights = new int[] {0};
|
||||
setLayout(layout);
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 0;
|
||||
gridBagConstraints.gridy = 0;
|
||||
add(jLabel2, gridBagConstraints);
|
||||
|
||||
lastPrice.setFont(lastPrice.getFont().deriveFont(lastPrice.getFont().getStyle() | java.awt.Font.BOLD, lastPrice.getFont().getSize()+4));
|
||||
lastPrice.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||
lastPrice.setText("0.00");
|
||||
lastPrice.setOpaque(true);
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 2;
|
||||
gridBagConstraints.gridy = 0;
|
||||
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
|
||||
gridBagConstraints.weightx = 0.9;
|
||||
gridBagConstraints.weighty = 0.9;
|
||||
add(lastPrice, gridBagConstraints);
|
||||
|
||||
jLabel3.setPreferredSize(new java.awt.Dimension(30, 18));
|
||||
gridBagConstraints = new java.awt.GridBagConstraints();
|
||||
gridBagConstraints.gridx = 4;
|
||||
gridBagConstraints.gridy = 0;
|
||||
add(jLabel3, gridBagConstraints);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel3;
|
||||
private javax.swing.JLabel lastPrice;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
@Override
|
||||
public void UpdateQuote(Quote q) {
|
||||
class Updater implements Runnable {
|
||||
QuotePanel qp;
|
||||
String text="";
|
||||
Color color = Color.BLUE;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
qp.lastPrice.setText(text);
|
||||
qp.lastPrice.setForeground(color);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Updater u= new Updater();
|
||||
u.qp=this;
|
||||
|
||||
if (q.price==q.bid){
|
||||
u.color=new Color(172,0,0);
|
||||
}
|
||||
if (q.price==q.ask){
|
||||
u.color=new Color(0,120,0); //.; //new Color(30,0,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
u.text = String.format("%.2f\n(%d)", q.price,q.volume);
|
||||
|
||||
SwingUtilities.invokeLater(u);
|
||||
|
||||
// SortedSet s = MainWin.se.getQuoteHistory(5);
|
||||
|
||||
// System.out.print(
|
||||
// "SortedSet size:"
|
||||
// +s.size()
|
||||
// +"\n"
|
||||
// );
|
||||
|
||||
//this.lastPrice.setText(lp);
|
||||
}
|
||||
}
|
115
src/main/java/gui/test.java
Normal file
115
src/main/java/gui/test.java
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (c) 2017, tobias
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tobias
|
||||
*/
|
||||
public class test {
|
||||
|
||||
static class Problem {
|
||||
|
||||
class Elem implements Comparable {
|
||||
|
||||
public int id;
|
||||
|
||||
public Elem(int id) {
|
||||
this.id = id;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
Elem e = (Elem) o;
|
||||
return id - e.id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
SortedSet<Elem> s = new TreeSet<>();
|
||||
s.add(new Elem(1));
|
||||
s.add(new Elem(7));
|
||||
s.add(new Elem(12));
|
||||
Elem e = new Elem(5);
|
||||
|
||||
SortedSet<Elem> ts = exclusiveTailSet(s, e);
|
||||
|
||||
Elem e2 = new Elem(0);
|
||||
|
||||
// SortedSet<Elem> ts2 = exclusiveTailSet(ts,e);
|
||||
SortedSet<Elem> ts2 = ts.tailSet(e2);
|
||||
|
||||
e.id = 99;
|
||||
|
||||
System.out.print(String.format("First: %s\n", ts.first().id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class NoProblem {
|
||||
public void run(){
|
||||
SortedSet<Integer> s=new TreeSet<>();
|
||||
|
||||
s.add(10);
|
||||
s.add(20);
|
||||
s.add(30);
|
||||
s.add(40);
|
||||
s.add(50);
|
||||
s.add(60);
|
||||
|
||||
int e1 = 15;
|
||||
SortedSet l1 = s.tailSet(e1);
|
||||
|
||||
int e2 = -1;
|
||||
|
||||
SortedSet l2 = l1.tailSet(e2);
|
||||
|
||||
System.out.print("First:"+l2.first()+"\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static <Ta> SortedSet<Ta> exclusiveTailSet(SortedSet<Ta> ts, Ta elem) {
|
||||
Iterator<Ta> iter = ts.tailSet(elem).iterator();
|
||||
|
||||
return ts.tailSet(iter.next());
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
NoProblem p = new NoProblem();
|
||||
p.run();
|
||||
|
||||
|
||||
}
|
||||
}
|
100
src/main/java/sesim/Account.java
Normal file
100
src/main/java/sesim/Account.java
Normal file
@ -0,0 +1,100 @@
|
||||
package sesim;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
final public class Account {
|
||||
|
||||
/**
|
||||
* Exchange this account belongs to
|
||||
*/
|
||||
public Exchange se;
|
||||
|
||||
/**
|
||||
* Number of shares in this account
|
||||
*/
|
||||
public long shares = 0;
|
||||
|
||||
/**
|
||||
* Ammount of money in this account
|
||||
*/
|
||||
public double money = 0;
|
||||
|
||||
/**
|
||||
* Name of this account
|
||||
*/
|
||||
public String name = "";
|
||||
|
||||
|
||||
public ArrayList <Order> pending;
|
||||
|
||||
public boolean orderpending = false;
|
||||
|
||||
|
||||
public Account(Exchange se, long shares, double money ) {
|
||||
this.shares=shares;
|
||||
this.money=money;
|
||||
this.se=se;
|
||||
pending = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Account(){
|
||||
//this(,0.0);
|
||||
}
|
||||
|
||||
// private double bound_money;
|
||||
|
||||
|
||||
|
||||
public void print_current() {
|
||||
System.out.printf("%s shares: %d credit: %.2f\n",
|
||||
name, shares, money
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public boolean isRuined(){
|
||||
|
||||
|
||||
/* System.out.print(
|
||||
"Account: "
|
||||
+money
|
||||
+" / "
|
||||
+shares
|
||||
+"\n"
|
||||
);
|
||||
*/
|
||||
return this.money<=se.lastprice && this.shares<=0;
|
||||
}
|
||||
|
||||
public Order sell(long volume, double limit) {
|
||||
SellOrder o = new SellOrder();
|
||||
o.account = this;
|
||||
o.limit = limit;
|
||||
o.volume = volume;
|
||||
orderpending = true;
|
||||
return se.SendOrder(o);
|
||||
}
|
||||
|
||||
public Order buy(long volume, double limit) {
|
||||
if (volume * limit > money) {
|
||||
return null;
|
||||
}
|
||||
BuyOrder o = new BuyOrder();
|
||||
o.limit = limit;
|
||||
o.volume = volume;
|
||||
o.account = this;
|
||||
orderpending = true;
|
||||
return se.SendOrder(o);
|
||||
}
|
||||
|
||||
/*
|
||||
public void Buy(Account a, long size, double price) {
|
||||
shares += size;
|
||||
money -= price * size;
|
||||
a.shares -= size;
|
||||
a.money += price * size;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
63
src/main/java/sesim/AutoTrader.java
Normal file
63
src/main/java/sesim/AutoTrader.java
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public abstract class AutoTrader extends Trader implements Runnable {
|
||||
|
||||
public AutoTrader(Account account, TraderConfig config) {
|
||||
super(account, config);
|
||||
}
|
||||
|
||||
protected void doSleep(int seconds) {
|
||||
try {
|
||||
sleep(seconds*1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void start(){
|
||||
System.out.print("Starting AutoTrader\n");
|
||||
class Runner extends Thread{
|
||||
AutoTrader trader;
|
||||
@Override
|
||||
public void run(){
|
||||
trader.run();
|
||||
}
|
||||
}
|
||||
Runner r = new Runner();
|
||||
r.trader=this;
|
||||
r.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
44
src/main/java/sesim/AutoTraderLIst.java
Normal file
44
src/main/java/sesim/AutoTraderLIst.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class AutoTraderLIst {
|
||||
|
||||
public void add(int n, TraderConfig config, Exchange se, long shares, double money) {
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
AutoTrader trader = config.createTrader(se, shares, money);
|
||||
// TraderRunner tr = new TraderRunner(trader);
|
||||
|
||||
trader.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
9
src/main/java/sesim/BuyOrder.java
Normal file
9
src/main/java/sesim/BuyOrder.java
Normal file
@ -0,0 +1,9 @@
|
||||
package sesim;
|
||||
|
||||
public class BuyOrder extends Order implements Comparable<Order> {
|
||||
|
||||
public BuyOrder(){
|
||||
type=OrderType.bid;
|
||||
}
|
||||
|
||||
}
|
457
src/main/java/sesim/Exchange.java
Normal file
457
src/main/java/sesim/Exchange.java
Normal file
@ -0,0 +1,457 @@
|
||||
package sesim;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import sesim.Order.OrderStatus;
|
||||
import sesim.Order.OrderType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tube
|
||||
*/
|
||||
public class Exchange extends Thread {
|
||||
|
||||
/**
|
||||
* Histrory of quotes
|
||||
*/
|
||||
public TreeSet<Quote> quoteHistory = new TreeSet<>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Exchange() {
|
||||
this.ask = new TreeSet<>();
|
||||
this.bid = new TreeSet<>();
|
||||
this.qrlist = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
||||
public static long getCurrentTimeSeconds(long div) {
|
||||
long ct = System.currentTimeMillis() / 1000*div;
|
||||
return ct * div;
|
||||
}
|
||||
|
||||
public static long getCurrentTimeSeconds(){
|
||||
return getCurrentTimeSeconds(1);
|
||||
}
|
||||
|
||||
public SortedSet<Quote> getQuoteHistory(long start) {
|
||||
|
||||
Quote s = new Quote();
|
||||
s.time = start;
|
||||
s.time = 2;
|
||||
s.id = 2;
|
||||
|
||||
TreeSet<Quote> result = new TreeSet<>();
|
||||
result.addAll(this.quoteHistory.tailSet(s));
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/* public SortedSet<Quote> getQuoteHistory(int seconds) {
|
||||
Quote last = quoteHistory.last();
|
||||
return this.getQuoteHistory(seconds, last.time);
|
||||
}
|
||||
*/
|
||||
|
||||
// Class to describe an executed order
|
||||
// QuoteReceiver has to be implemented by objects that wants
|
||||
// to receive quote updates
|
||||
public interface QuoteReceiver {
|
||||
|
||||
void UpdateQuote(Quote q);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bookreceiver Interface
|
||||
*/
|
||||
public interface BookReceiver {
|
||||
|
||||
void UpdateOrderBook();
|
||||
}
|
||||
|
||||
private ArrayList<BookReceiver> ask_bookreceivers = new ArrayList<>();
|
||||
private ArrayList<BookReceiver> bid_bookreceivers = new ArrayList<>();
|
||||
|
||||
private ArrayList<BookReceiver> selectBookReceiver(OrderType t) {
|
||||
switch (t) {
|
||||
case ask:
|
||||
return ask_bookreceivers;
|
||||
case bid:
|
||||
return bid_bookreceivers;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addBookReceiver(OrderType t, BookReceiver br) {
|
||||
ArrayList<BookReceiver> bookreceivers;
|
||||
bookreceivers = selectBookReceiver(t);
|
||||
bookreceivers.add(br);
|
||||
}
|
||||
|
||||
void updateBookReceivers(OrderType t) {
|
||||
ArrayList<BookReceiver> bookreceivers;
|
||||
bookreceivers = selectBookReceiver(t);
|
||||
|
||||
Iterator<BookReceiver> i = bookreceivers.iterator();
|
||||
while (i.hasNext()) {
|
||||
i.next().UpdateOrderBook();
|
||||
}
|
||||
try {
|
||||
sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("I was Interrupted");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Here we store the list of quote receivers
|
||||
private final ArrayList<QuoteReceiver> qrlist;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param qr
|
||||
*/
|
||||
public void addQuoteReceiver(QuoteReceiver qr) {
|
||||
qrlist.add(qr);
|
||||
}
|
||||
|
||||
// send updated quotes to all quote receivers
|
||||
private void updateQuoteReceivers(Quote q) {
|
||||
Iterator<QuoteReceiver> i = qrlist.iterator();
|
||||
while (i.hasNext()) {
|
||||
i.next().UpdateQuote(q);
|
||||
}
|
||||
}
|
||||
|
||||
// long time = 0;
|
||||
double theprice = 12.9;
|
||||
long orderid = 1;
|
||||
|
||||
double lastprice = 100.0;
|
||||
long lastsvolume;
|
||||
|
||||
public TreeSet<Order> bid;
|
||||
public TreeSet<Order> ask;
|
||||
|
||||
private Locker tradelock = new Locker();
|
||||
|
||||
/*
|
||||
private final Semaphore available = new Semaphore(1, true);
|
||||
|
||||
private void Lock() {
|
||||
try {
|
||||
available.acquire();
|
||||
} catch (InterruptedException s) {
|
||||
System.out.println("Interrupted\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Unlock() {
|
||||
available.release();
|
||||
}
|
||||
*/
|
||||
private TreeSet<Order> selectOrderBook(OrderType t) {
|
||||
|
||||
switch (t) {
|
||||
case bid:
|
||||
return this.bid;
|
||||
case ask:
|
||||
return this.ask;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Order> getOrderBook(OrderType t, int depth) {
|
||||
|
||||
TreeSet<Order> book = selectOrderBook(t);
|
||||
if (book == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<Order> ret = new ArrayList<>();
|
||||
Iterator<Order> it = book.iterator();
|
||||
for (int i = 0; i < depth && it.hasNext(); i++) {
|
||||
Order o;
|
||||
o = it.next();
|
||||
ret.add(o);
|
||||
//System.out.print("Order" + o.limit);
|
||||
//System.out.println();
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
public void print_current() {
|
||||
|
||||
Order b;
|
||||
Order a;
|
||||
|
||||
//String bid;
|
||||
if (bid.isEmpty()) {
|
||||
b = new BuyOrder();
|
||||
b.limit = -1;
|
||||
b.volume = 0;
|
||||
} else {
|
||||
b = bid.first();
|
||||
}
|
||||
|
||||
if (ask.isEmpty()) {
|
||||
a = new SellOrder();
|
||||
a.limit = -1;
|
||||
a.volume = 0;
|
||||
|
||||
} else {
|
||||
a = ask.first();
|
||||
}
|
||||
|
||||
Logger.info(String.format("BID: %s(%s) LAST: %.2f(%d) ASK: %s(%s)\n",
|
||||
b.format_limit(), b.format_volume(),
|
||||
lastprice, lastsvolume,
|
||||
a.format_limit(), a.format_volume())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void transferMoney(Account src, Account dst, double money) {
|
||||
src.money -= money;
|
||||
dst.money += money;
|
||||
|
||||
}
|
||||
|
||||
public void cancelOrder(Order o) {
|
||||
tradelock.lock();
|
||||
TreeSet<Order> book = this.selectOrderBook(o.type);
|
||||
book.remove(o);
|
||||
this.updateBookReceivers(o.type);
|
||||
o.account.pending.remove(o);
|
||||
o.status = OrderStatus.canceled;
|
||||
tradelock.unlock();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer shares from one account to another account
|
||||
*
|
||||
* @param src source account
|
||||
* @param dst destination account
|
||||
* @param volumen number of shares
|
||||
* @param price price
|
||||
*/
|
||||
protected void transferShares(Account src, Account dst, long volume, double price) {
|
||||
dst.shares += volume;
|
||||
src.shares -= volume;
|
||||
dst.money -= price * volume;
|
||||
src.money += price * volume;
|
||||
}
|
||||
|
||||
long nextQuoteId = 0;
|
||||
|
||||
public void OrderMatching() {
|
||||
|
||||
while (true) {
|
||||
|
||||
if (bid.isEmpty() || ask.isEmpty()) {
|
||||
// nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
Order b = bid.first();
|
||||
Order a = ask.first();
|
||||
|
||||
if (a.volume == 0) {
|
||||
// This order is fully executed, remove
|
||||
a.account.orderpending = false;
|
||||
a.status = OrderStatus.executed;
|
||||
|
||||
a.account.pending.remove(a);
|
||||
|
||||
ask.pollFirst();
|
||||
this.updateBookReceivers(OrderType.ask);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (b.volume == 0) {
|
||||
// This order is fully executed, remove
|
||||
b.account.orderpending = false;
|
||||
b.status = OrderStatus.executed;
|
||||
b.account.pending.remove(b);
|
||||
bid.pollFirst();
|
||||
this.updateBookReceivers(OrderType.bid);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (b.limit < a.limit) {
|
||||
// no match, nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
if (b.limit >= a.limit) {
|
||||
double price;
|
||||
|
||||
if (b.id < a.id) {
|
||||
price = b.limit;
|
||||
} else {
|
||||
price = a.limit;
|
||||
}
|
||||
|
||||
long volume;
|
||||
|
||||
if (b.volume >= a.volume) {
|
||||
volume = a.volume;
|
||||
} else {
|
||||
volume = b.volume;
|
||||
}
|
||||
|
||||
transferShares(a.account, b.account, volume, price);
|
||||
|
||||
// b.account.Buy(a.account, volume, price);
|
||||
b.volume -= volume;
|
||||
a.volume -= volume;
|
||||
|
||||
lastprice = price;
|
||||
lastsvolume = volume;
|
||||
|
||||
Quote q = new Quote();
|
||||
|
||||
q.volume = volume;
|
||||
q.price = price;
|
||||
q.time = System.currentTimeMillis();
|
||||
|
||||
q.ask = a.limit;
|
||||
q.bid = b.limit;
|
||||
q.id = nextQuoteId++;
|
||||
|
||||
this.updateQuoteReceivers(q);
|
||||
this.updateBookReceivers(OrderType.bid);
|
||||
this.updateBookReceivers(OrderType.ask);
|
||||
|
||||
/* System.out.print(
|
||||
"Executed: "
|
||||
+ q.price
|
||||
+ " / "
|
||||
+ q.volume
|
||||
+ "\n"
|
||||
);
|
||||
*/
|
||||
quoteHistory.add(q);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void ExecuteOrder(BuyOrder o) {
|
||||
// SellOrder op = ask.peek();
|
||||
|
||||
}
|
||||
|
||||
private boolean InitOrder(Order o) {
|
||||
double moneyNeeded = o.volume * o.limit;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add an order to the orderbook
|
||||
private boolean addOrder(Order o) {
|
||||
boolean ret = false;
|
||||
switch (o.type) {
|
||||
case bid:
|
||||
|
||||
// System.out.print("Exchange adding bid order \n");
|
||||
ret = bid.add(o);
|
||||
break;
|
||||
|
||||
case ask:
|
||||
// System.out.print("Exchange adding ask order \n");
|
||||
ret = ask.add(o);
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
this.updateBookReceivers(o.type);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Order SendOrder(Order o) {
|
||||
|
||||
boolean rc = InitOrder(o);
|
||||
if (!rc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
tradelock.lock();
|
||||
o.timestamp = System.currentTimeMillis();
|
||||
o.id = orderid++;
|
||||
addOrder(o);
|
||||
o.account.pending.add(o);
|
||||
OrderMatching();
|
||||
tradelock.unlock();
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/*
|
||||
public void SendOrder(BuyOrder o) {
|
||||
//System.out.println("EX Buyorder");
|
||||
Lock();
|
||||
o.timestamp = System.currentTimeMillis();
|
||||
o.id = orderid++;
|
||||
bid.add(o);
|
||||
|
||||
Unlock();
|
||||
Lock();
|
||||
// OrderMatching();
|
||||
Unlock();
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
* public void SendOrder(Order o){
|
||||
*
|
||||
*
|
||||
* if ( o.getClass() == BuyOrder.class){ bid.add((BuyOrder)o); }
|
||||
*
|
||||
* if ( o.getClass() == SellOrder.class){ ask.add((SellOrder)o); }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
public double getlastprice() {
|
||||
/*
|
||||
* SellOrder so = new SellOrder(); so.limit=1000.0; so.volume=500;
|
||||
* SendOrder(so);
|
||||
*
|
||||
* BuyOrder bo = new BuyOrder(); bo.limit=1001.0; bo.volume=300;
|
||||
* SendOrder(bo);
|
||||
*/
|
||||
|
||||
return lastprice;
|
||||
}
|
||||
|
||||
/* public double sendOrder(Account o) {
|
||||
return 0.7;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("I was Interrupted");
|
||||
}
|
||||
print_current();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
51
src/main/java/sesim/Locker.java
Normal file
51
src/main/java/sesim/Locker.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class Locker {
|
||||
|
||||
private final Semaphore avail = new Semaphore(1, true);
|
||||
|
||||
public boolean lock() {
|
||||
try {
|
||||
avail.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
avail.release();
|
||||
}
|
||||
|
||||
}
|
23
src/main/java/sesim/Logger.java
Normal file
23
src/main/java/sesim/Logger.java
Normal file
@ -0,0 +1,23 @@
|
||||
package sesim;
|
||||
|
||||
public class Logger {
|
||||
|
||||
static boolean dbg = true;
|
||||
static boolean info = true;
|
||||
|
||||
static void dbg(String s) {
|
||||
if (!dbg) {
|
||||
return;
|
||||
}
|
||||
System.out.print("DBG: ");
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
static void info(String s) {
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
System.out.print("INFO: ");
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
110
src/main/java/sesim/Order.java
Normal file
110
src/main/java/sesim/Order.java
Normal file
@ -0,0 +1,110 @@
|
||||
package sesim;
|
||||
|
||||
public abstract class Order implements Comparable<Order> {
|
||||
|
||||
/**
|
||||
* When the order was created
|
||||
*/
|
||||
public long timestamp = 0;
|
||||
|
||||
/**
|
||||
* Number of shares
|
||||
*/
|
||||
public long volume;
|
||||
|
||||
/**
|
||||
* Limit price
|
||||
*/
|
||||
public double limit;
|
||||
|
||||
/**
|
||||
* Order ID
|
||||
*/
|
||||
public long id = 0;
|
||||
|
||||
/**
|
||||
* Type of order
|
||||
*/
|
||||
public OrderType type;
|
||||
|
||||
public Account account = null;
|
||||
|
||||
|
||||
protected int compareLimit(Order o){
|
||||
int r=0;
|
||||
if (o.limit < limit) {
|
||||
r=-1;
|
||||
}
|
||||
if (o.limit > limit) {
|
||||
r=1;
|
||||
}
|
||||
|
||||
if (type==OrderType.ask)
|
||||
return -r;
|
||||
|
||||
return r;
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public int compareTo(Order o) {
|
||||
|
||||
if (o.type!=type){
|
||||
System.out.print("OrderType Missmatch\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int r = compareLimit(o);
|
||||
if (r!=0)
|
||||
return r;
|
||||
|
||||
/* if (o.timestamp> timestamp)
|
||||
return -1;
|
||||
|
||||
if (o.timestamp<timestamp)
|
||||
return 1;
|
||||
*/
|
||||
|
||||
if (o.id>id)
|
||||
return -1;
|
||||
|
||||
if (o.id<id)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum OrderStatus {
|
||||
open, executed, canceled
|
||||
}
|
||||
|
||||
public enum OrderType {
|
||||
bid,ask
|
||||
}
|
||||
|
||||
OrderStatus status = OrderStatus.open;
|
||||
|
||||
public long getAge() {
|
||||
if (timestamp == 0) {
|
||||
return 0;
|
||||
}
|
||||
return System.currentTimeMillis() - timestamp;
|
||||
}
|
||||
|
||||
String format_limit() {
|
||||
if (limit < 0.0) {
|
||||
return "n.a.";
|
||||
}
|
||||
return String.format("%.2f", limit);
|
||||
}
|
||||
|
||||
String format_volume() {
|
||||
return String.format("%d", volume);
|
||||
}
|
||||
|
||||
Order() {
|
||||
|
||||
}
|
||||
}
|
76
src/main/java/sesim/Quote.java
Normal file
76
src/main/java/sesim/Quote.java
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class Quote implements Comparable {
|
||||
|
||||
public double bid;
|
||||
public double bid_volume;
|
||||
public double ask;
|
||||
public double ask_volume;
|
||||
|
||||
public double price;
|
||||
public long volume;
|
||||
public long time;
|
||||
|
||||
Locker lock = new Locker();
|
||||
|
||||
public void print() {
|
||||
System.out.print("Quote ("
|
||||
+ time
|
||||
+ ") :"
|
||||
+ price
|
||||
+ " / "
|
||||
+ volume
|
||||
+ "\n"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public long id;
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
int ret;
|
||||
Quote q = (Quote)o;
|
||||
|
||||
ret = (int)(this.time-q.time);
|
||||
if (ret !=0)
|
||||
return ret;
|
||||
|
||||
return (int)(this.id-q.id);
|
||||
}
|
||||
|
||||
/* Quote (){
|
||||
lock.lock();
|
||||
id=nextid++;
|
||||
lock.unlock();
|
||||
}*/
|
||||
}
|
8
src/main/java/sesim/SellOrder.java
Normal file
8
src/main/java/sesim/SellOrder.java
Normal file
@ -0,0 +1,8 @@
|
||||
package sesim;
|
||||
|
||||
public class SellOrder extends Order {
|
||||
|
||||
public SellOrder(){
|
||||
type=OrderType.ask;
|
||||
}
|
||||
}
|
69
src/main/java/sesim/Trader.java
Normal file
69
src/main/java/sesim/Trader.java
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
public abstract class Trader {
|
||||
|
||||
public String name = null;
|
||||
|
||||
|
||||
public Account account;
|
||||
public TraderConfig config;
|
||||
|
||||
public void sell(long shares, double limit){
|
||||
account.sell(shares, limit);
|
||||
}
|
||||
|
||||
public void buy(long shares, double limit){
|
||||
account.buy(shares, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Trader object
|
||||
* @param account Account for this trader
|
||||
* @param config Configration for this trader
|
||||
*/
|
||||
public Trader(Account account, TraderConfig config){
|
||||
this.account=account;
|
||||
this.config=config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Trader object w/o config
|
||||
* The Trader object shoul initialize a default config
|
||||
* @param account
|
||||
*/
|
||||
public Trader(Account account){
|
||||
this(account,null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
36
src/main/java/sesim/TraderConfig.java
Normal file
36
src/main/java/sesim/TraderConfig.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package sesim;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public abstract class TraderConfig{
|
||||
String name;
|
||||
|
||||
public abstract AutoTrader createTrader(Exchange se, long shares, double money);
|
||||
}
|
55
src/main/java/traders/ManTrader.java
Normal file
55
src/main/java/traders/ManTrader.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package traders;
|
||||
|
||||
import sesim.Account;
|
||||
import sesim.Trader;
|
||||
import sesim.TraderConfig;
|
||||
import sesim.BuyOrder;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ManTrader extends Trader{
|
||||
|
||||
public ManTrader(Account account,TraderConfig config) {
|
||||
super(account,config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void trade(){
|
||||
|
||||
BuyOrder o = new BuyOrder();
|
||||
|
||||
}
|
||||
|
||||
}
|
251
src/main/java/traders/RandomTrader.java
Normal file
251
src/main/java/traders/RandomTrader.java
Normal file
@ -0,0 +1,251 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package traders;
|
||||
|
||||
import sesim.Account;
|
||||
import sesim.Order;
|
||||
import java.util.Random;
|
||||
import sesim.AutoTrader;
|
||||
import sesim.TraderConfig;
|
||||
|
||||
public class RandomTrader extends AutoTrader {
|
||||
|
||||
protected enum Action {
|
||||
sell,buy
|
||||
}
|
||||
|
||||
// config for this trader
|
||||
final private RandomTraderConfig myconfig;
|
||||
|
||||
// object to generate random numbers
|
||||
final private Random rand = new Random();
|
||||
|
||||
public RandomTrader(Account account, TraderConfig config) {
|
||||
super(account, config);
|
||||
if (config == null) {
|
||||
config = new RandomTraderConfig();
|
||||
}
|
||||
myconfig = (RandomTraderConfig) config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a (long) random number between min an max
|
||||
*
|
||||
* @param min minimum value
|
||||
* @param max maximeum value
|
||||
* @return the number
|
||||
*/
|
||||
protected double getRandom(double min, double max) {
|
||||
double r = rand.nextDouble();
|
||||
return (max - min) * r + min;
|
||||
}
|
||||
|
||||
protected int getRandom(int[] minmax) {
|
||||
return (int) Math.round(getRandom(minmax[0], minmax[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param val
|
||||
* @param minmax
|
||||
* @return
|
||||
*/
|
||||
protected double getRandomAmmount(double val, float[] minmax) {
|
||||
double min = val * minmax[0] / 100.0;
|
||||
double max = val * minmax[1] / 100.0;
|
||||
return getRandom(min, max);
|
||||
}
|
||||
|
||||
public boolean waitForOrder(long seconds) {
|
||||
|
||||
for (int i = 0; (i < seconds) && (0 != account.pending.size()); i++) {
|
||||
doSleep(1);
|
||||
}
|
||||
|
||||
if (account.pending.size() != 0) {
|
||||
Order o = account.pending.get(0);
|
||||
account.se.cancelOrder(o);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean doBuy() {
|
||||
|
||||
double money = getRandomAmmount(account.money, myconfig.sell_volume);
|
||||
|
||||
double lp = account.se.getlastprice();
|
||||
double limit;
|
||||
limit = lp + getRandomAmmount(lp, myconfig.buy_limit);
|
||||
|
||||
long volume = (int) (money / (limit * 1));
|
||||
if (volume <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
buy(volume, limit);
|
||||
return waitForOrder(getRandom(myconfig.buy_order_wait));
|
||||
|
||||
}
|
||||
|
||||
public boolean doSell() {
|
||||
|
||||
long volume;
|
||||
volume = (long) Math.round(getRandomAmmount(account.shares, myconfig.sell_volume));
|
||||
|
||||
double lp = account.se.getlastprice();
|
||||
double limit;
|
||||
limit = lp + getRandomAmmount(lp, myconfig.sell_limit);
|
||||
|
||||
sell(volume, limit);
|
||||
return waitForOrder(getRandom(myconfig.sell_order_wait));
|
||||
|
||||
}
|
||||
|
||||
/* private boolean monitorTrades() {
|
||||
|
||||
int numpending = account.pending.size();
|
||||
if (numpending == 0) {
|
||||
// System.out.print("RT: pending = 0 - return false\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
Order o = account.pending.get(0);
|
||||
long age = o.getAge();
|
||||
|
||||
// System.out.print("RT: age is: "+age+"\n");
|
||||
if (age > myconfig.maxage) {
|
||||
// System.out.print("MaxAge is"+myconfig.maxage+"\n");
|
||||
account.se.cancelOrder(o);
|
||||
// System.out.print("Age reached - canel return false\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
//System.out.print("RT: monitor return true\n");
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
public void trade() {
|
||||
|
||||
float am[] = {-10, 200};
|
||||
|
||||
double x = Math.round(this.getRandomAmmount(1000, am));
|
||||
/* System.out.print(
|
||||
"Random:"
|
||||
+ x
|
||||
+ "\n"
|
||||
);
|
||||
|
||||
*/
|
||||
/*
|
||||
// System.out.print("RT: Now trading\n");
|
||||
if (monitorTrades()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// What next to do?
|
||||
int action = rand.nextInt(5);
|
||||
|
||||
if (account.money < 10 && account.shares < 5) {
|
||||
System.out.print("I'm almost ruined\n");
|
||||
}
|
||||
|
||||
if (action == 1) {
|
||||
doBuy();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == 2) {
|
||||
doSell();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
protected Action getAction() {
|
||||
if (rand.nextInt(2)==0){
|
||||
return Action.buy;
|
||||
}
|
||||
else{
|
||||
return Action.sell;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.print("Starting Random Trader\n");
|
||||
while (true) {
|
||||
|
||||
// What next to do?
|
||||
Action action = getAction();
|
||||
|
||||
if (account.isRuined()) {
|
||||
// System.out.print("I'm ruined\n");
|
||||
// System.exit(0);
|
||||
}
|
||||
boolean rc;
|
||||
// action=1;
|
||||
switch (action) {
|
||||
|
||||
case sell:
|
||||
if (account.shares <= 0) {
|
||||
// we have no shares
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Sell\n");
|
||||
rc = doSell();
|
||||
if (!rc) {
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Sold\n");
|
||||
doSleep(getRandom(myconfig.wait_after_sell));
|
||||
// System.out.print("Next\n");
|
||||
break;
|
||||
case buy:
|
||||
if (account.money <= 0) {
|
||||
// we have no money
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Sell\n");
|
||||
rc = doBuy();
|
||||
if (!rc) {
|
||||
continue;
|
||||
}
|
||||
// System.out.print("Bought\n");
|
||||
doSleep(getRandom(myconfig.wait_after_buy));
|
||||
// System.out.print("Next\n");
|
||||
break;
|
||||
|
||||
}
|
||||
// doSleep(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
73
src/main/java/traders/RandomTraderConfig.java
Normal file
73
src/main/java/traders/RandomTraderConfig.java
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package traders;
|
||||
|
||||
import sesim.Account;
|
||||
import sesim.TraderConfig;
|
||||
import sesim.Exchange;
|
||||
import sesim.AutoTrader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class RandomTraderConfig extends TraderConfig {
|
||||
|
||||
//public long maxage = 1000 * 10 * 1;
|
||||
|
||||
|
||||
/*public long hold_shares_min = 10;
|
||||
|
||||
public long hold_shares_max = 30;
|
||||
|
||||
public float buy_volume_min = 10;
|
||||
*/
|
||||
|
||||
/**
|
||||
* If shares are selled, this specifies
|
||||
* the minimum and maximum volume to be selled
|
||||
*/
|
||||
public float[] sell_volume= {100,100};
|
||||
public float[] sell_limit = {-15,15};
|
||||
public int[] sell_order_wait = {15,33};
|
||||
public int[] wait_after_sell = {10,30};
|
||||
|
||||
|
||||
public float[] buy_volume={100,100};
|
||||
public float[] buy_limit = {-15,15};
|
||||
public int[] buy_order_wait = {15,33};
|
||||
public int[] wait_after_buy = {10,30};
|
||||
|
||||
|
||||
@Override
|
||||
public AutoTrader createTrader(Exchange se, long shares, double money) {
|
||||
Account a = new Account(se, shares, money);
|
||||
return new RandomTrader(a, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
107
src/main/java/traders/SwitchingTrader.java
Normal file
107
src/main/java/traders/SwitchingTrader.java
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package traders;
|
||||
|
||||
import sesim.Account;
|
||||
import sesim.TraderConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class SwitchingTrader extends RandomTrader{
|
||||
|
||||
|
||||
private Action mode;
|
||||
|
||||
public SwitchingTrader(Account account, TraderConfig config) {
|
||||
|
||||
super(account, config);
|
||||
System.out.print("SWTrader Created\n");
|
||||
|
||||
if (account.shares>0)
|
||||
mode=Action.sell;
|
||||
else
|
||||
mode=Action.buy;
|
||||
printstartus();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void printstartus(){
|
||||
|
||||
System.out.print("SWTrader:");
|
||||
switch (mode){
|
||||
case buy:
|
||||
System.out.print("buy"
|
||||
+account.shares
|
||||
+" "
|
||||
+account.money
|
||||
);
|
||||
break;
|
||||
case sell:
|
||||
System.out.print("sell"
|
||||
+account.shares
|
||||
+" "
|
||||
+account.money
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
System.out.print("\n");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Action getAction(){
|
||||
|
||||
|
||||
|
||||
|
||||
if ( (account.shares>0) && (mode==Action.sell)){
|
||||
printstartus();
|
||||
return mode;
|
||||
}
|
||||
if ( (account.shares<=0 && mode==Action.sell)){
|
||||
mode=Action.buy;
|
||||
printstartus();
|
||||
return mode;
|
||||
}
|
||||
if (account.money>100.0 && mode==Action.buy){
|
||||
printstartus();
|
||||
return mode;
|
||||
}
|
||||
if (account.money<=100.0 && mode==Action.buy){
|
||||
mode=Action.sell;
|
||||
printstartus();
|
||||
return mode;
|
||||
}
|
||||
printstartus();
|
||||
return mode;
|
||||
}
|
||||
|
||||
}
|
57
src/main/java/traders/SwitchingTraderConfig.java
Normal file
57
src/main/java/traders/SwitchingTraderConfig.java
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 7u83 <7u83@mail.ru>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package traders;
|
||||
|
||||
import sesim.Account;
|
||||
import sesim.AutoTrader;
|
||||
import sesim.Exchange;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class SwitchingTraderConfig extends RandomTraderConfig {
|
||||
|
||||
@Override
|
||||
public AutoTrader createTrader(Exchange se, long shares, double money) {
|
||||
Account a = new Account(se, shares, money);
|
||||
System.out.print("Returning a new sw trader\n");
|
||||
return new SwitchingTrader(a, this);
|
||||
}
|
||||
|
||||
public SwitchingTraderConfig() {
|
||||
|
||||
sell_volume = new float[]{100, 100};
|
||||
sell_limit = new float[]{-30, 1};
|
||||
sell_order_wait = new int[]{1, 5};
|
||||
wait_after_sell = new int[]{1, 5};
|
||||
|
||||
buy_volume = new float[]{100, 100};
|
||||
buy_limit = new float[]{-1, 30};
|
||||
buy_order_wait = new int[]{1, 5};
|
||||
wait_after_buy = new int[]{1, 5};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user