Nice orderbook

This commit is contained in:
7u83 2016-12-27 20:16:56 +01:00
parent 7dde10a9f6
commit 1de297da36
13 changed files with 242 additions and 103 deletions

View File

@ -55,43 +55,7 @@ is divided into following sections:
<property file="nbproject/project.properties"/>
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
<condition property="platform.javac" value="${platform.home}/bin/javac">
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
</condition>
<property name="platform.javac" value="${platform.javac.tmp}"/>
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
<condition property="platform.java" value="${platform.home}/bin/java">
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
</condition>
<property name="platform.java" value="${platform.java.tmp}"/>
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
</condition>
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
<condition property="platform.invalid" value="true">
<or>
<contains string="${platform.javac}" substring="$${platforms."/>
<contains string="${platform.java}" substring="$${platforms."/>
<contains string="${platform.javadoc}" substring="$${platforms."/>
</or>
</condition>
<fail unless="platform.home">Must set platform.home</fail>
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
<fail unless="platform.java">Must set platform.java</fail>
<fail unless="platform.javac">Must set platform.javac</fail>
<fail if="platform.invalid">
The J2SE Platform is not correctly set up.
Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
Either open the project in the IDE and setup the Platform with the same name or add it manually.
For example like this:
ant -Duser.properties.file=&lt;path_to_property_file&gt; jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
or ant -Dplatforms.${platform.active}.home=&lt;path_to_JDK_home&gt; jar (where no properties file is used)
</fail>
<property name="platform.java" value="${java.home}/bin/java"/>
<available file="${manifest.file}" property="manifest.available"/>
<condition property="splashscreen.available">
<and>
@ -220,6 +184,20 @@ is divided into following sections:
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
<isset property="profile.available"/>
</condition>
<condition else="false" property="jdkBug6558476">
<and>
<matches pattern="1\.[56]" string="${java.specification.version}"/>
<not>
<os family="unix"/>
</not>
</and>
</condition>
<condition else="false" property="javac.fork">
<or>
<istrue value="${jdkBug6558476}"/>
<istrue value="${javac.external.vm}"/>
</or>
</condition>
<property name="jar.index" value="false"/>
<property name="jar.index.metainf" value="${jar.index}"/>
<property name="copylibs.rebase" value="true"/>
@ -289,7 +267,7 @@ is divided into following sections:
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<mkdir dir="@{apgeneratedsrcdir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -329,7 +307,7 @@ is divided into following sections:
<sequential>
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -410,7 +388,7 @@ is divided into following sections:
<element name="customize" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
@ -433,7 +411,7 @@ is divided into following sections:
<element name="customize" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
@ -472,7 +450,7 @@ is divided into following sections:
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="SeSim" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="SeSim" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@ -552,7 +530,7 @@ is divided into following sections:
<element name="customize" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
@ -577,7 +555,7 @@ is divided into following sections:
<element name="customize" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
@ -757,9 +735,6 @@ is divided into following sections:
<classpath>
<path path="@{classpath}"/>
</classpath>
<bootclasspath>
<path path="${platform.bootcp}"/>
</bootclasspath>
</nbjpdastart>
</sequential>
</macrodef>
@ -775,9 +750,7 @@ is divided into following sections:
</macrodef>
</target>
<target name="-init-debug-args">
<exec executable="${platform.java}" outputproperty="version-output">
<arg value="-version"/>
</exec>
<property name="version-output" value="java version &quot;${ant.java.version}"/>
<condition property="have-jdk-older-than-1.4">
<or>
<contains string="${version-output}" substring="java version &quot;1.0"/>
@ -802,7 +775,7 @@ is divided into following sections:
<attribute default="${debug.classpath}" name="classpath"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg line="${debug-args-line}"/>
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
@ -829,7 +802,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
@ -1027,7 +1000,7 @@ is divided into following sections:
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
<echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
@ -1236,13 +1209,10 @@ is divided into following sections:
</not>
</and>
</condition>
<exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output">
<arg value="-version"/>
</exec>
<condition else="" property="bug5101868workaround" value="*.java">
<matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
</condition>
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<classpath>
<path path="${javac.classpath}"/>
</classpath>

View File

@ -1,8 +1,8 @@
build.xml.data.CRC32=1799545a
build.xml.data.CRC32=56c4c4cc
build.xml.script.CRC32=cbcf3329
build.xml.stylesheet.CRC32=8064a381@1.79.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=1799545a
nbproject/build-impl.xml.script.CRC32=71cc6074
nbproject/build-impl.xml.data.CRC32=56c4c4cc
nbproject/build-impl.xml.script.CRC32=beaa60d7
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48

View File

@ -13,10 +13,8 @@
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/OrderBook.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/manifest.mf</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/Account.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/nbproject/build-impl.xml</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/Exchange.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/Chart.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/nbproject/project.properties</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/OrderBookCell.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/AskBook.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/BidBook.java</file>

View File

@ -43,7 +43,7 @@ javac.classpath=\
${file.reference.jfreechart-1.5.0.jar}:\
${file.reference.jcommon-1.0.23.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.compilerargs=-Xlint:unchecked
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
@ -88,6 +88,7 @@ manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
#platforms.default_platform.home=${java.home}
project.license=bsd
run.classpath=\
${javac.classpath}:\

View File

@ -10,7 +10,6 @@
</buildExtensions>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>SeSim</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>

View File

@ -16,17 +16,17 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="1" pref="162" max="32767" 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="jScrollPane1" alignment="0" pref="300" max="32767" attributes="0"/>
<Component id="orderBookScroller" alignment="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Container class="javax.swing.JScrollPane" name="orderBookScroller">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
@ -73,6 +73,7 @@
<Column editable="false" title="Title 3" type="java.lang.Object"/>
</Table>
</Property>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>

View File

@ -29,6 +29,12 @@ import java.util.ArrayList;
import java.util.Formatter;
import java.util.concurrent.Callable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
/**
*
@ -37,6 +43,26 @@ import javax.swing.table.AbstractTableModel;
public abstract class OrderBook extends javax.swing.JPanel {
abstract ArrayList getArrayList();
public class DateCellRenderer extends DefaultTableCellRenderer {
String pattern;
public DateCellRenderer(String pattern){
this.pattern = pattern;
}
@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);
//renderer.setBorder(BorderFactory.createLineBorder(Color.BLACK));
// renderer.setText("Halloe");
return renderer;
}
}
Color hdr_color = Color.LIGHT_GRAY;
boolean getDesc() {
return false;
@ -104,11 +130,42 @@ public abstract class OrderBook extends javax.swing.JPanel {
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.orderBookList.setModel(new SListModel());
orderBookList.setBorder(BorderFactory.createEmptyBorder());
JTableHeader h = this.orderBookList.getTableHeader();
h.setBackground(hdr_color);
h.setForeground(Color.green);
// h.setDefaultRenderer(this.orderBookList.getCellRenderer(0, 0));
// h.setBorder(BorderFactory.createLineBorder(Color.yellow));
h.setDefaultRenderer(new DateCellRenderer("Hhu"));
/* h.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer(){
@Override
public Component getTableCellRendererComponent(
JTable x, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
JComponent component = (JComponent)orderBookList.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(orderBookList, value, false, false, -1, -2);
component.setBackground(new Color(250, 250, 250));
component.setBorder(BorderFactory.createEmptyBorder());
return component;
}
});
*/
}
/**
@ -120,7 +177,7 @@ public abstract class OrderBook extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
orderBookScroller = new javax.swing.JScrollPane();
orderBookList = new javax.swing.JTable();
orderBookList.setModel(new javax.swing.table.DefaultTableModel(
@ -168,23 +225,24 @@ public abstract class OrderBook extends javax.swing.JPanel {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(orderBookList);
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(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
.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(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.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.JScrollPane jScrollPane1;
private javax.swing.JTable orderBookList;
private javax.swing.JScrollPane orderBookScroller;
// End of variables declaration//GEN-END:variables
}

View File

@ -3,7 +3,7 @@
<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="[150, 262]"/>
<Dimension value="[220, 262]"/>
</Property>
</Properties>
<AuxValues>

View File

@ -26,6 +26,7 @@
package Gui;
//import SeSim.*;
import static java.lang.Thread.sleep;
import javax.swing.AbstractListModel;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
@ -53,6 +54,14 @@ public class OrderBookPanel extends javax.swing.JPanel {
MainWin.myAccount.Sell(100, 19.3, MainWin.se);
try {
sleep(1000);
} catch (InterruptedException e) {
System.out.println("Interrupted");
return;
}
MainWin.myAccount.Sell(310, 6112.156, MainWin.se);
MainWin.myAccount.Sell(3, 7112.156, MainWin.se);
@ -86,7 +95,7 @@ public class OrderBookPanel extends javax.swing.JPanel {
jLabel4 = new javax.swing.JLabel();
bidBook1 = new Gui.BidBook();
setPreferredSize(new java.awt.Dimension(150, 262));
setPreferredSize(new java.awt.Dimension(220, 262));
setLayout(new java.awt.GridBagLayout());
askBook1.setPreferredSize(new java.awt.Dimension(200, 200));

View File

@ -2,18 +2,21 @@ package SeSim;
public class BuyOrder extends Order implements Comparable<Order> {
@Override
public int compareTo(Order o) {
/* @Override
public int compareLimit(Order o) {
if (o.limit < limit) {
//System.out.println("return 1");
return -1;
}
if (o.limit > limit) {
//System.out.println("return -1");
return +1;
}
// System.out.println("0000000000000000000000");
return 0;
}
*/
public BuyOrder(){
type=OrderType.buy;
}
}

View File

@ -74,8 +74,8 @@ public class Exchange extends Thread {
double lastprice = 300.0;
long lastsize;
public TreeSet<BuyOrder> bid;
public TreeSet<SellOrder> ask;
public TreeSet<Order> bid;
public TreeSet<Order> ask;
private final Semaphore available = new Semaphore(1, true);
@ -93,7 +93,7 @@ public class Exchange extends Thread {
}
public ArrayList geAskBook(int n){
ArrayList ret = new ArrayList();
ArrayList <Order> ret= new ArrayList<>();
Iterator it=ask.iterator();
for(int i=0;i<n && it.hasNext();i++){
SellOrder o;
@ -106,7 +106,7 @@ public class Exchange extends Thread {
}
public ArrayList geBidBook(int n){
ArrayList ret = new ArrayList();
ArrayList <Order> ret = new ArrayList<>();
Iterator it=bid.iterator();
for(int i=0;i<n && it.hasNext();i++){
BuyOrder o;
@ -122,8 +122,8 @@ public class Exchange extends Thread {
public void print_current() {
BuyOrder b;
SellOrder a;
Order b;
Order a;
//String bid;
if (bid.isEmpty()) {
@ -176,8 +176,8 @@ public class Exchange extends Thread {
return;
}
BuyOrder b = bid.first();
SellOrder a = ask.first();
Order b = bid.first();
Order a = ask.first();
if (a.volume == 0) {
// This order is fully executed, remove
@ -251,6 +251,7 @@ public class Exchange extends Thread {
return true;
}
/*
public void SendOrder(SellOrder o) {
// System.out.println("EX Sellorder");
Lock();
@ -263,11 +264,42 @@ public class Exchange extends Thread {
Unlock();
Lock();
OrderMatching();
// OrderMatching();
Unlock();
}
*/
private void addOrder(Order o){
switch (o.type){
case buy:
bid.add(o);
break;
case sell:
ask.add(o);
break;
default:
return;
}
}
public void SendOrder(Order o){
Lock();
o.timestamp = System.currentTimeMillis();
boolean rc = InitOrder(o);
System.out.print(o.timestamp+" TS:\n");
o.id = orderid++;
addOrder(o);
Unlock();
}
/*
public void SendOrder(BuyOrder o) {
//System.out.println("EX Buyorder");
Lock();
@ -277,11 +309,11 @@ public class Exchange extends Thread {
Unlock();
Lock();
OrderMatching();
// OrderMatching();
Unlock();
}
*/
/*
* public void SendOrder(Order o){
*
@ -308,6 +340,10 @@ public class Exchange extends Thread {
return 0.7;
}
/**
*
*/
@Override
public void run() {
while (true) {
try {

View File

@ -17,14 +17,74 @@ public abstract class Order implements Comparable<Order> {
*/
public double limit;
// double money = 0;
/**
* 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 (r==0)
return 0;
if (type==OrderType.sell)
return 1-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
}
enum OrderType {
buy,sell
}
OrderStatus status = OrderStatus.open;

View File

@ -1,16 +1,20 @@
package SeSim;
public class SellOrder extends Order {
/*
@Override
public int compareTo(Order o) {
if (o.limit < limit) {
return 1;
}
if (o.limit > limit) {
return -1;
}
return 0;
return super.compareTo(o);
}
public SellOrder(){
type=OrderType.buy;
}
*/
public SellOrder(){
type=OrderType.sell;
}
}