Design of Orderbook in progress

This commit is contained in:
7u83 2016-12-27 12:04:37 +01:00
parent e3dc0ae3f2
commit 32c47eabc6
12 changed files with 522 additions and 323 deletions

View File

@ -3,20 +3,25 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/tube/NetBeansProjects/SeSim/additional/README.txt</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/Trader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/TraderRun.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/MTrader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/build.xml</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/Order.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/ControlPanel.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/MainWin.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/RandomTrader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/OrderBook.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/ThreadedTrader.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/src/Gui/OrderBookCell.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/AskBook.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/build.xml</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Gui/OrderBookPanel.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/RandomTrader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/ThreadedTrader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/SeSim/BuyOrder.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/src/Traders/ManTrader.java</file>
<file>file:/home/tube/NetBeansProjects/SeSim/README.md</file>

51
src/Gui/AskBook.java Normal file
View 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 Gui;
import java.util.ArrayList;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class AskBook extends OrderBook {
@Override
ArrayList getArrayList() {
return MainWin.se.geAskBook(10);
}
@Override
boolean getDesc(){
return true;
}
public AskBook(){
System.out.print("init askbook\n");
}
}

41
src/Gui/BidBook.java Normal file
View File

@ -0,0 +1,41 @@
/*
* 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 java.util.ArrayList;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class BidBook extends OrderBook{
@Override
ArrayList getArrayList() {
return MainWin.se.geBidBook(10);
}
}

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" 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="[300, 300]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>

View File

@ -155,6 +155,8 @@ public class Chart extends javax.swing.JPanel implements Exchange.QuoteReceiver
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
setPreferredSize(new java.awt.Dimension(300, 300));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(

View File

@ -80,33 +80,6 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel1"/>
</Properties>
<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="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel2"/>
</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>
<Component class="Gui.OrderBook" name="orderBook1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Last"/>
</Constraint>
</Constraints>
</Component>
<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">
@ -114,12 +87,32 @@
</Constraint>
</Constraints>
</Component>
<Component class="Gui.Chart" name="chart2">
<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>
<Container class="Gui.Chart" name="chart2">
<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>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="287" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="582" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Form>

View File

@ -71,10 +71,8 @@ public class MainWin extends javax.swing.JFrame {
jButton1 = new javax.swing.JButton();
jMenuItem1 = new javax.swing.JMenuItem();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
orderBook1 = new Gui.OrderBook();
controlPanel2 = new Gui.ControlPanel();
orderBookPanel1 = new Gui.OrderBookPanel();
chart2 = new Gui.Chart();
MainMenu = new javax.swing.JMenuBar();
FileMenu = new javax.swing.JMenu();
@ -93,14 +91,20 @@ public class MainWin extends javax.swing.JFrame {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(640, 480));
jLabel1.setText("jLabel1");
getContentPane().add(jLabel1, java.awt.BorderLayout.LINE_START);
jLabel2.setText("jLabel2");
getContentPane().add(jLabel2, java.awt.BorderLayout.CENTER);
getContentPane().add(orderBook1, java.awt.BorderLayout.PAGE_END);
getContentPane().add(controlPanel2, java.awt.BorderLayout.LINE_END);
getContentPane().add(orderBookPanel1, java.awt.BorderLayout.LINE_START);
javax.swing.GroupLayout chart2Layout = new javax.swing.GroupLayout(chart2);
chart2.setLayout(chart2Layout);
chart2Layout.setHorizontalGroup(
chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 287, Short.MAX_VALUE)
);
chart2Layout.setVerticalGroup(
chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 582, Short.MAX_VALUE)
);
getContentPane().add(chart2, java.awt.BorderLayout.CENTER);
FileMenu.setBackground(new java.awt.Color(254, 203, 1));
@ -153,6 +157,13 @@ public class MainWin extends javax.swing.JFrame {
se = new Exchange();
myAccount = new Account(1000,100000000.0);
SeSim.SellOrder so = new SeSim.SellOrder();
so.limit = 20.0;
so.volume = 12;
so.timestamp = 12;
se.SendOrder(so);
/*
SeSim.BuyOrder bo = new SeSim.BuyOrder();
@ -228,10 +239,8 @@ public class MainWin extends javax.swing.JFrame {
private Gui.Chart chart2;
private Gui.ControlPanel controlPanel2;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuItem jMenuItem1;
private Gui.OrderBook orderBook1;
private Gui.OrderBookPanel orderBookPanel1;
// End of variables declaration//GEN-END:variables
}

View File

@ -1,11 +1,6 @@
<?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="[500, 262]"/>
</Property>
</Properties>
<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"/>
@ -16,152 +11,68 @@
<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,-127,0,0,2,20"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" 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"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Bid"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="16" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="Ask"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 226]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<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="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JList" name="BidList">
<Properties>
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
<StringArray count="14">
<StringItem index="0" value="a"/>
<StringItem index="1" value="b"/>
<StringItem index="2" value="c"/>
<StringItem index="3" value="d"/>
<StringItem index="4" value="e"/>
<StringItem index="5" value="f"/>
<StringItem index="6" value="g"/>
<StringItem index="7" value="h"/>
<StringItem index="8" value="i"/>
<StringItem index="9" value="j"/>
<StringItem index="10" value="k"/>
<StringItem index="11" value="l"/>
<StringItem index="12" value="m"/>
<StringItem index="13" value=" "/>
</StringArray>
</Property>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[52, 200]"/>
</Property>
<Property name="name" type="java.lang.String" value="" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[100, 392]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="20.00"/>
</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="2" 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>
<Container class="javax.swing.JScrollPane" name="jScrollPane4">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 150]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[100, 150]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="1.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="AskList">
<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="4">
<Column editable="false" title="ID" type="java.lang.String">
<Data value="#0010"/>
<Data value="#0071"/>
<Data value="null"/>
<Data value="null"/>
</Column>
<Column editable="false" title="Price" type="java.lang.String">
<Data value="50.00"/>
<Data value="120.25"/>
<Data value="null"/>
<Data value="null"/>
</Column>
<Column editable="false" title="Volume" type="java.lang.String">
<Data value="100"/>
<Data value="30"/>
<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="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Crosshair Cursor"/>
</Property>
<Property name="opaque" type="boolean" value="false"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[100, 72]"/>
</Property>
<Property name="rowSelectionAllowed" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>

View File

@ -25,76 +25,90 @@
*/
package Gui;
//import SeSim.*;
import javax.swing.AbstractListModel;
import java.util.SortedSet;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.concurrent.Callable;
import javax.swing.table.AbstractTableModel;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class OrderBook extends javax.swing.JPanel {
public abstract class OrderBook extends javax.swing.JPanel {
private class SListModel extends AbstractListModel {
SortedSet model;
public SListModel(SortedSet set) {
model = set;
}
@Override
public Object getElementAt(int index) {
SeSim.Order o = (SeSim.Order) model.toArray()[index];
return "<html>"
+ "<div style=\"border:1px solid black;\">"
+o.limit
+"</div>"
+"<div style=\"align:right; border:1px solid blue; \">"
+o.volume
+"</div>"
+"</html>";
}
@Override
public int getSize() {
return model.size();
}
abstract ArrayList getArrayList();
boolean getDesc() {
return false;
}
SeSim.Exchange se;
protected class SListModel extends AbstractTableModel {
SListModel bid;
SListModel ask;
private ArrayList m;
private boolean desc = false;
public SListModel() {
m = getArrayList();
}
@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() {
return m.size();
}
@Override
public int getColumnCount() {
return 3;
}
@Override
public Object getValueAt(int r, int c) {
SeSim.Order o;
if (!getDesc()) {
o = (SeSim.Order) m.get(r);
} else {
o = (SeSim.Order) m.get(m.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() {
this.se = MainWin.se;
System.out.print("init Orderbook]\n");
initComponents();
if (this.se == null) {
if (MainWin.se == null) {
return;
}
System.out.print("Order boo init\n");
MainWin.myAccount.Sell(100, 20.0, MainWin.se);
MainWin.myAccount.Sell(100, 10.0, MainWin.se);
bid = new SListModel(se.bid);
BidList.setModel(bid);
MainWin.myAccount.Buy(100, 2.0, MainWin.se);
MainWin.myAccount.Buy(100, 1.0, MainWin.se);
ask = new SListModel(se.ask);
//AskList.setModel(ask);
this.orderBookList.setModel(new SListModel());
}
/**
@ -105,116 +119,72 @@ System.out.print("Order boo init\n");
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
BidList = new javax.swing.JList<>();
jLabel2 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
AskList = new javax.swing.JTable();
orderBookList = new javax.swing.JTable();
setPreferredSize(new java.awt.Dimension(500, 262));
setLayout(new java.awt.GridBagLayout());
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Bid");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
add(jLabel1, gridBagConstraints);
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("Ask");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
add(jLabel3, gridBagConstraints);
jScrollPane1.setPreferredSize(new java.awt.Dimension(0, 226));
BidList.setModel(new javax.swing.AbstractListModel<String>() {
String[] strings = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", " " };
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
BidList.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
BidList.setMinimumSize(new java.awt.Dimension(52, 200));
BidList.setName(""); // NOI18N
BidList.setPreferredSize(new java.awt.Dimension(100, 392));
jScrollPane1.setViewportView(BidList);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
add(jScrollPane1, gridBagConstraints);
jLabel2.setForeground(new java.awt.Color(255, 0, 0));
jLabel2.setText("20.00");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
add(jLabel2, gridBagConstraints);
jScrollPane4.setMinimumSize(new java.awt.Dimension(300, 150));
jScrollPane4.setPreferredSize(new java.awt.Dimension(100, 150));
AskList.setModel(new javax.swing.table.DefaultTableModel(
orderBookList.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"#0010", "50.00", "100"},
{"#0071", "120.25", "30"},
{"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", "Price", "Volume"
"id", "Title 2pri", "Title 3"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
AskList.setCursor(new java.awt.Cursor(java.awt.Cursor.CROSSHAIR_CURSOR));
AskList.setOpaque(false);
AskList.setPreferredSize(new java.awt.Dimension(100, 72));
AskList.setRowSelectionAllowed(false);
jScrollPane4.setViewportView(AskList);
jScrollPane1.setViewportView(orderBookList);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
add(jScrollPane4, gridBagConstraints);
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)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, 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 AskList;
private javax.swing.JList<String> BidList;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JTable orderBookList;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,62 @@
<?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="[150, 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,1,-127,0,0,0,-72"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<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="-1" gridY="-1" 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="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" value="123.00"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[150, 25]"/>
</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="1" gridWidth="1" gridHeight="3" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.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>
</SubComponents>
</Form>

125
src/Gui/OrderBookPanel.java Normal file
View File

@ -0,0 +1,125 @@
/*
* 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 javax.swing.AbstractListModel;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.Formatter;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class OrderBookPanel extends javax.swing.JPanel {
SeSim.Exchange se;
public OrderBookPanel() {
this.se = MainWin.se;
MainWin.myAccount.Sell(100, 820.0, MainWin.se);
MainWin.myAccount.Sell(100, 90.0, MainWin.se);
MainWin.myAccount.Sell(310, 112.156, MainWin.se);
MainWin.myAccount.Sell(3, 112.156, MainWin.se);
MainWin.myAccount.Sell(9, 1112.156, MainWin.se);
MainWin.myAccount.Sell(17, 122.156, MainWin.se);
MainWin.myAccount.Sell(100, 120.0, MainWin.se);
MainWin.myAccount.Sell(100, 19.5, MainWin.se);
MainWin.myAccount.Sell(100, 19.5, MainWin.se);
MainWin.myAccount.Sell(100, 19.3, MainWin.se);
MainWin.myAccount.Sell(310, 6112.156, MainWin.se);
MainWin.myAccount.Sell(3, 7112.156, MainWin.se);
MainWin.myAccount.Buy(100, 2.0, MainWin.se);
MainWin.myAccount.Buy(100, 3.0, MainWin.se);
MainWin.myAccount.Buy(100, 2.0, MainWin.se);
MainWin.myAccount.Buy(100, 1.0, MainWin.se);
MainWin.myAccount.Buy(100, 3.0, MainWin.se);
MainWin.myAccount.Buy(100, 5.0, 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();
jLabel4 = new javax.swing.JLabel();
bidBook1 = new Gui.BidBook();
setPreferredSize(new java.awt.Dimension(150, 262));
setLayout(new java.awt.GridBagLayout());
askBook1.setPreferredSize(new java.awt.Dimension(200, 200));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
add(askBook1, gridBagConstraints);
jLabel4.setText("123.00");
jLabel4.setPreferredSize(new java.awt.Dimension(150, 25));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weighty = 1.0;
add(jLabel4, 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);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private Gui.AskBook askBook1;
private Gui.BidBook bidBook1;
private javax.swing.JLabel jLabel4;
// End of variables declaration//GEN-END:variables
}

View File

@ -3,6 +3,7 @@ package SeSim;
import java.util.*;
import java.util.concurrent.*;
import SeSim.Order.OrderStatus;
/**
@ -91,9 +92,33 @@ public class Exchange extends Thread {
available.release();
}
public void getBidBook(){
public ArrayList geAskBook(int n){
ArrayList ret = new ArrayList();
Iterator it=ask.iterator();
for(int i=0;i<n && it.hasNext();i++){
SellOrder o;
o = (SellOrder)it.next();
ret.add(o);
System.out.print("Order"+o.limit);
System.out.println();
}
return ret;
}
public ArrayList geBidBook(int n){
ArrayList ret = new ArrayList();
Iterator it=bid.iterator();
for(int i=0;i<n && it.hasNext();i++){
BuyOrder o;
o = (BuyOrder)it.next();
ret.add(o);
System.out.print("Order"+o.limit);
System.out.println();
}
return ret;
}
public void print_current() {