diff --git a/nb-configuration.xml b/nb-configuration.xml new file mode 100644 index 0000000..df2f8ba --- /dev/null +++ b/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + bsd + + diff --git a/src/main/java/chart/Chart.form b/src/main/java/chart/Chart.form index ebc46c9..74576d7 100644 --- a/src/main/java/chart/Chart.form +++ b/src/main/java/chart/Chart.form @@ -2,13 +2,16 @@
+ + + - - + + - + @@ -27,12 +30,12 @@ - + - + diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index 4ca9d20..cc28e1b 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -5,31 +5,91 @@ */ package chart; -import javax.swing.*; import java.awt.*; +import sesim.Exchange.*; +import sesim.Quote; +import gui.MainWin; /** * * @author 7u83 <7u83@mail.ru> */ -public class Chart extends javax.swing.JPanel { +public class Chart extends javax.swing.JPanel implements QuoteReceiver{ /** * Creates new form Chart */ public Chart() { initComponents(); + + MainWin.se.addQuoteReceiver(this); //Graphics g = this.getGraphics(); //g.drawString("Hello world", 0, 0); } + + int item_width=10; + int items=350; + + + OHLCData data; + + + OHLCDataItem current=null; + + private void realTimeAdd(long time,float price,float volume){ + if (current==null){ + current=new OHLCDataItem(price,price,price,price,volume); + return; + } + + boolean rc = current.update(price,volume); + if (rc){ + System.out.print("Updated -" + +" High:" + +current.high + +" Low:" + +current.low + +" Volume" + +current.volume + +"\n" + + ); + } + + + } + + + private void getData(){ + + } + + private void draw(Graphics2D g){ + this.getSize(); + + int pwidth = item_width*items; + + this.setPreferredSize(new Dimension(pwidth,400)); + + for (int i=0; i//GEN-BEGIN:initComponents private void initComponents() { - setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); - setPreferredSize(new java.awt.Dimension(900, 300)); + setBackground(java.awt.Color.white); + setBorder(javax.swing.BorderFactory.createTitledBorder("")); + setPreferredSize(new java.awt.Dimension(300, 300)); setRequestFocusEnabled(false); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 396, Short.MAX_VALUE) + .addGap(0, 316, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 296, Short.MAX_VALUE) + .addGap(0, 280, Short.MAX_VALUE) ); }// //GEN-END:initComponents + @Override + public void UpdateQuote(Quote q) { + // System.out.print("Quote Received\n"); + this.realTimeAdd(q.time, (float)q.price , q.volume); + } + // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables diff --git a/src/main/java/chart/FullChart.form b/src/main/java/chart/FullChart.form new file mode 100644 index 0000000..976047a --- /dev/null +++ b/src/main/java/chart/FullChart.form @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/chart/FullChart.java b/src/main/java/chart/FullChart.java new file mode 100644 index 0000000..b583bc9 --- /dev/null +++ b/src/main/java/chart/FullChart.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2017, 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 chart; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class FullChart extends javax.swing.JPanel { + + /** + * Creates new form FullChart + */ + public FullChart() { + 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + legend1 = new chart.Legend(); + jScrollPane1 = new javax.swing.JScrollPane(); + chart1 = new chart.Chart(); + + legend1.setBackground(new java.awt.Color(255, 204, 204)); + + javax.swing.GroupLayout legend1Layout = new javax.swing.GroupLayout(legend1); + legend1.setLayout(legend1Layout); + legend1Layout.setHorizontalGroup( + legend1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 75, Short.MAX_VALUE) + ); + legend1Layout.setVerticalGroup( + legend1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 0, Short.MAX_VALUE) + ); + + javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1); + chart1.setLayout(chart1Layout); + chart1Layout.setHorizontalGroup( + chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 737, Short.MAX_VALUE) + ); + chart1Layout.setVerticalGroup( + chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 295, Short.MAX_VALUE) + ); + + jScrollPane1.setViewportView(chart1); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 763, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(legend1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(legend1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private chart.Chart chart1; + private javax.swing.JScrollPane jScrollPane1; + private chart.Legend legend1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/chart/Legend.form b/src/main/java/chart/Legend.form new file mode 100644 index 0000000..c638b68 --- /dev/null +++ b/src/main/java/chart/Legend.form @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/chart/Legend.java b/src/main/java/chart/Legend.java new file mode 100644 index 0000000..e159b7c --- /dev/null +++ b/src/main/java/chart/Legend.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, 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 chart; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class Legend extends javax.swing.JPanel { + + /** + * Creates new form Legend + */ + public Legend() { + 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/chart/NewJPanel.form b/src/main/java/chart/NewJPanel.form new file mode 100644 index 0000000..612b102 --- /dev/null +++ b/src/main/java/chart/NewJPanel.form @@ -0,0 +1,145 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/chart/NewJPanel.java b/src/main/java/chart/NewJPanel.java new file mode 100644 index 0000000..7f38b54 --- /dev/null +++ b/src/main/java/chart/NewJPanel.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2017, 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 chart; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class NewJPanel extends javax.swing.JPanel { + + /** + * Creates new form NewJPanel + */ + public NewJPanel() { + 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jToolBar1 = new javax.swing.JToolBar(); + jButton1 = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList<>(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jCheckBox1 = new javax.swing.JCheckBox(); + jScrollPane3 = new javax.swing.JScrollPane(); + jTextArea2 = new javax.swing.JTextArea(); + + jToolBar1.setRollover(true); + + jButton1.setText("jButton1"); + + jList1.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; + public int getSize() { return strings.length; } + public String getElementAt(int i) { return strings[i]; } + }); + jScrollPane1.setViewportView(jList1); + + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jScrollPane2.setViewportView(jTextArea1); + + jCheckBox1.setText("jCheckBox1"); + + jTextArea2.setColumns(20); + jTextArea2.setRows(5); + jScrollPane3.setViewportView(jTextArea2); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jCheckBox1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE) + .addComponent(jScrollPane1)))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(8, 8, 8) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jCheckBox1) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(jScrollPane3)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JCheckBox jCheckBox1; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JScrollPane jScrollPane3; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTextArea jTextArea2; + private javax.swing.JToolBar jToolBar1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/chart/OHLCData.java b/src/main/java/chart/OHLCData.java new file mode 100644 index 0000000..7324c85 --- /dev/null +++ b/src/main/java/chart/OHLCData.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, 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 chart; + +import java.util.*; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class OHLCData extends ArrayList { + + float max; + + long start_time; + long time_step; + + public float getMax(){ + return max; + } + + @Override + public boolean add (OHLCDataItem o){ + super.add(o); + + return true; + } + + +} diff --git a/src/main/java/chart/OHLCDataItem.java b/src/main/java/chart/OHLCDataItem.java new file mode 100644 index 0000000..d5ebdac --- /dev/null +++ b/src/main/java/chart/OHLCDataItem.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017, 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 chart; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class OHLCDataItem { + + public float open; + public float high; + public float low; + public float close; + public float volume; + + public OHLCDataItem(float open, float high, float low, float close, float volume) { + this.open = open; + this.high = high; + this.low = low; + this.close = close; + this.volume = volume; + } + + public OHLCDataItem() { + this(0, 0, 0, 0, 0); + } + + public boolean update(float price, float volume) { + boolean ret = false; + if (price > high) { + high = price; + ret = true; + + } + if (price < low) { + low = price; + ret = true; + } + this.volume = this.volume + volume; + this.close = price; + return ret; + } + +} diff --git a/src/main/java/gui/ControlPanel.form b/src/main/java/gui/ControlPanel.form index 057d9f3..233d6f5 100644 --- a/src/main/java/gui/ControlPanel.form +++ b/src/main/java/gui/ControlPanel.form @@ -11,65 +11,96 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + + + + + + - + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/gui/ControlPanel.java b/src/main/java/gui/ControlPanel.java index e29de67..dd64a58 100644 --- a/src/main/java/gui/ControlPanel.java +++ b/src/main/java/gui/ControlPanel.java @@ -47,55 +47,99 @@ public class ControlPanel extends javax.swing.JPanel { // //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(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + jTextField1 = new javax.swing.JTextField(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jTextField2 = new javax.swing.JTextField(); - 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() { + jButton1.setText("Byu"); + jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - SellButtonActionPerformed(evt); + jButton1ActionPerformed(evt); } }); - add(SellButton); - jTextArea1.setColumns(20); - jTextArea1.setRows(5); - jScrollPane1.setViewportView(jTextArea1); + jButton2.setText("Sell"); - 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() { + jTextField1.setText("325"); + jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - BuyButtonActionPerformed(evt); + jTextField1ActionPerformed(evt); } }); - add(BuyButton); + + jLabel1.setText("Shares:"); + + jLabel2.setText("Limit:"); + + jTextField2.setText("127.00"); + jTextField2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jTextField2ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTextField2) + .addComponent(jTextField1))) + .addGroup(layout.createSequentialGroup() + .addContainerGap(37, Short.MAX_VALUE) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jTextField1) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton1) + .addComponent(jButton2)) + .addContainerGap(358, Short.MAX_VALUE)) + ); }// //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 jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jButton1ActionPerformed - private void BuyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BuyButtonActionPerformed - MainWin.myAccount.buy(44, 66.0); - }//GEN-LAST:event_BuyButtonActionPerformed + private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField2ActionPerformed + + private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_jTextField1ActionPerformed // 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; + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/gui/MainWin.form b/src/main/java/gui/MainWin.form index 81d3fbd..f7e6e33 100644 --- a/src/main/java/gui/MainWin.form +++ b/src/main/java/gui/MainWin.form @@ -51,6 +51,19 @@ + + + + + + + + + + + + + @@ -75,7 +88,7 @@ - + @@ -94,31 +107,12 @@ - + - - - - - - - - - - - - - - - - - - - - + diff --git a/src/main/java/gui/MainWin.java b/src/main/java/gui/MainWin.java index 1f37e56..cdd90b6 100644 --- a/src/main/java/gui/MainWin.java +++ b/src/main/java/gui/MainWin.java @@ -41,7 +41,7 @@ import javax.swing.*; */ public class MainWin extends javax.swing.JFrame { - static sesim.Exchange se; + static public sesim.Exchange se; static sesim.Account myAccount; static traders.ManTrader myTrader; @@ -52,7 +52,15 @@ public class MainWin extends javax.swing.JFrame { initComponents(); - + 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); } @@ -69,13 +77,14 @@ public class MainWin extends javax.swing.JFrame { jMenuItem1 = new javax.swing.JMenuItem(); controlPanel2 = new gui.ControlPanel(); orderBookPanel1 = new gui.OrderBookPanel(); - jScrollPane1 = new javax.swing.JScrollPane(); - chart2 = new chart.Chart(); + fullChart2 = new chart.FullChart(); 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(); + jMenu1 = new javax.swing.JMenu(); + jMenuItem2 = new javax.swing.JMenuItem(); jButton1.setText("jButton1"); jButton1.addActionListener(new java.awt.event.ActionListener() { @@ -90,21 +99,7 @@ public class MainWin extends javax.swing.JFrame { setMinimumSize(new java.awt.Dimension(640, 480)); 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, 231, Short.MAX_VALUE) - ); - chart2Layout.setVerticalGroup( - chart2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 572, Short.MAX_VALUE) - ); - - jScrollPane1.setViewportView(chart2); - - getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); + getContentPane().add(fullChart2, java.awt.BorderLayout.CENTER); FileMenu.setBackground(new java.awt.Color(254, 203, 1)); FileMenu.setText("File"); @@ -131,6 +126,14 @@ public class MainWin extends javax.swing.JFrame { jMenu2.setText("Edit"); MainMenu.add(jMenu2); + jMenu1.setText("Help"); + + jMenuItem2.setText("About"); + jMenuItem2.setToolTipText("About this Software"); + jMenu1.add(jMenuItem2); + + MainMenu.add(jMenu1); + setJMenuBar(MainMenu); pack(); @@ -171,27 +174,19 @@ public class MainWin extends javax.swing.JFrame { 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 { + /* 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 */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. @@ -229,12 +224,13 @@ public class MainWin extends javax.swing.JFrame { private javax.swing.JMenuItem FileNew; private javax.swing.JMenuItem FileRun; private javax.swing.JMenuBar MainMenu; - private chart.Chart chart2; private gui.ControlPanel controlPanel2; + private chart.FullChart fullChart2; private javax.swing.JButton jButton1; + private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuItem jMenuItem1; - private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JMenuItem jMenuItem2; private gui.OrderBookPanel orderBookPanel1; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/sesim/BuyOrder.java b/src/main/java/sesim/BuyOrder.java index a706ccf..d4a5e86 100644 --- a/src/main/java/sesim/BuyOrder.java +++ b/src/main/java/sesim/BuyOrder.java @@ -3,7 +3,7 @@ package sesim; public class BuyOrder extends Order implements Comparable { public BuyOrder(){ - type=OrderType.bid; + super(OrderType.bid); } } diff --git a/src/main/java/sesim/Exchange.java b/src/main/java/sesim/Exchange.java index ae50abe..d3cad49 100644 --- a/src/main/java/sesim/Exchange.java +++ b/src/main/java/sesim/Exchange.java @@ -221,6 +221,10 @@ public class Exchange extends Thread { } + /** + * + * @param o + */ public void cancelOrder(Order o) { tradelock.lock(); TreeSet book = this.selectOrderBook(o.type); @@ -249,7 +253,100 @@ public class Exchange extends Thread { long nextQuoteId = 0; - private void executeOrders() { + /** + * + */ + protected void executeOrders() { + + while (!bid.isEmpty() && !ask.isEmpty()) { + + Order b = bid.first(); + Order a = ask.first(); + + if (b.limit < a.limit) { + // no match, nothing to do + return; + } + + double price = b.id < a.id ? b.limit : a.limit; + long volume = b.volume>=a.volume ? a.volume : b.volume; + + + + 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) { + + price = b.id < a.id ? b.limit : a.limit; + + /* if (b.id < a.id) { + price = b.limit; + } else { + price = a.limit; + } + */ + + + 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); + + + quoteHistory.add(q); + continue; + + } + + return; + } + } + + private void executeOrdersX() { while (!bid.isEmpty() && !ask.isEmpty()) { @@ -285,15 +382,15 @@ public class Exchange extends Thread { if (b.limit >= a.limit) { double price; - - price = b.id= a.volume) { diff --git a/src/main/java/sesim/Order.java b/src/main/java/sesim/Order.java index ffed02a..2051901 100644 --- a/src/main/java/sesim/Order.java +++ b/src/main/java/sesim/Order.java @@ -25,12 +25,13 @@ public abstract class Order implements Comparable { /** * Type of order */ - public OrderType type; + public final OrderType type; public Account account = null; protected int compareLimit(Order o){ + int r=0; if (o.limit < limit) { r=-1; @@ -58,13 +59,7 @@ public abstract class Order implements Comparable { if (r!=0) return r; - /* if (o.timestamp> timestamp) - return -1; - - if (o.timestampid) return -1; @@ -104,7 +99,7 @@ public abstract class Order implements Comparable { return String.format("%d", volume); } - Order() { - + Order(OrderType type) { + this.type=type; } } diff --git a/src/main/java/sesim/SellOrder.java b/src/main/java/sesim/SellOrder.java index e6a9c29..b6b72fe 100644 --- a/src/main/java/sesim/SellOrder.java +++ b/src/main/java/sesim/SellOrder.java @@ -3,6 +3,6 @@ package sesim; public class SellOrder extends Order { public SellOrder(){ - type=OrderType.ask; + super(OrderType.ask); } }