diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index 1be1534..ff79643 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -9,6 +9,7 @@ import java.awt.*; import sesim.Exchange.*; import sesim.Quote; import gui.MainWin; +import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Iterator; @@ -41,11 +42,56 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { OHLCDataItem current = null; - long rasterTime(long time) { + /* long rasterTime(long time) { long rt = time / 5000; return rt * 5000; + } + */ + void drawXLegend(Graphics2D g) { + int xl_height = 30; + Dimension dim = this.getSize(); + + int sheight = g.getFontMetrics().getHeight(); + + int y = dim.height - sheight * 3; + + g.drawLine(0, y, dim.width, y); + + + + for (int i = 0; i < items; i ++) { + int x = i * this.item_width; + + if (i%5==0) + g.drawLine(x, y, x, y + 6); + else + g.drawLine(x, y, x, y + 3); + + OHLCDataItem d; + try { + d = data.data.get(i); + } catch (Exception e) { + d = null; + } + + String text; + if (d != null) { + text = " "; + } else { + text = " "; + } + + + + int swidth = g.getFontMetrics().stringWidth(text); + + g.drawString(text, x - swidth / 2, y + sheight * 2); + + } + + //for(int x=0; x) } private void realTimeAdd(long time, float price, float volume) { @@ -58,7 +104,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { // System.out.print("new raster ----------------------------------\n"); current = null; - ntime = rasterTime(time) + 5000; +// ntime = rasterTime(time) + 5000; // System.out.print(ntime+"\n"); // System.out.print((time)+"\n"); // System.exit(0); @@ -93,6 +139,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { } private void draw(Graphics2D g) { + + this.drawXLegend(g); + this.getSize(); int pwidth = item_width * items; @@ -105,14 +154,14 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { g.setColor(Color.RED); - g.drawLine(0, 0, 100, 100); +// g.drawLine(0, 0, 100, 100); - for (int i = 0; i < items; i++) { + /* for (int i = 0; i < items; i++) { int x = i * this.item_width; g.drawLine(x, 0, x, 50); } - + */ // if (this.current == null) { // return; // } @@ -122,22 +171,21 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { g.setColor(Color.BLUE); g.setStroke(new BasicStroke(3)); - Iterator it = od.iterator(); int myi = 0; - - int lastx=0; - int lasty=0; - + + int lastx = 0; + int lasty = 0; + while (it.hasNext()) { OHLCDataItem di = it.next(); float y = di.close; float max = data.max; float min = data.min; - - max = max/10.0f+max; - min = min-min/10.0f; + + max = max / 10.0f + max; + min = min - min / 10.0f; if (min == max) { min = y / 2; @@ -145,9 +193,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { } - // max = 5; - // min = 0; - + // max = 5; + // min = 0; System.out.print("Fval: " + y + " " + min + "\n"); y -= min; System.out.print("VAL New" + y + "\n"); @@ -155,16 +202,15 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { //val/ ((data.max-data.min)/dim.height); System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n"); - y = dim.height-(dim.height * y / (max - min)); + y = dim.height - (dim.height * y / (max - min)); int x = myi * this.item_width; myi++; - + g.drawLine(lastx, lasty, x, (int) y); - - lastx=x; - lasty=(int)y; - + + lastx = x; + lasty = (int) y; System.out.print("Draw Line: " + x + " " + y + "\n"); diff --git a/src/main/java/chart/NewJPanel.form b/src/main/java/chart/NewJPanel.form index 612b102..4b72163 100644 --- a/src/main/java/chart/NewJPanel.form +++ b/src/main/java/chart/NewJPanel.form @@ -22,9 +22,12 @@ - + - + + + + @@ -56,10 +59,12 @@ - + - + + + @@ -141,5 +146,9 @@ + + + + diff --git a/src/main/java/chart/NewJPanel.java b/src/main/java/chart/NewJPanel.java index 7f38b54..513c986 100644 --- a/src/main/java/chart/NewJPanel.java +++ b/src/main/java/chart/NewJPanel.java @@ -56,6 +56,7 @@ public class NewJPanel extends javax.swing.JPanel { jCheckBox1 = new javax.swing.JCheckBox(); jScrollPane3 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); + jSplitPane1 = new javax.swing.JSplitPane(); jToolBar1.setRollover(true); @@ -88,9 +89,11 @@ public class NewJPanel extends javax.swing.JPanel { .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) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() - .addComponent(jCheckBox1) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jCheckBox1) + .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -112,10 +115,12 @@ public class NewJPanel extends javax.swing.JPanel { .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) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jCheckBox1) - .addGap(0, 0, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(43, 43, 43)) .addComponent(jScrollPane3)) .addContainerGap()) ); @@ -129,6 +134,7 @@ public class NewJPanel extends javax.swing.JPanel { private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; + private javax.swing.JSplitPane jSplitPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; private javax.swing.JToolBar jToolBar1; diff --git a/src/main/java/chart/NewMDIApplication.form b/src/main/java/chart/NewMDIApplication.form new file mode 100644 index 0000000..9ca0ada --- /dev/null +++ b/src/main/java/chart/NewMDIApplication.form @@ -0,0 +1,138 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/chart/NewMDIApplication.java b/src/main/java/chart/NewMDIApplication.java new file mode 100644 index 0000000..c80a7ab --- /dev/null +++ b/src/main/java/chart/NewMDIApplication.java @@ -0,0 +1,202 @@ +/* + * 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 NewMDIApplication extends javax.swing.JFrame { + + /** + * Creates new form NewMDIApplication + */ + public NewMDIApplication() { + 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() { + + desktopPane = new javax.swing.JDesktopPane(); + menuBar = new javax.swing.JMenuBar(); + fileMenu = new javax.swing.JMenu(); + openMenuItem = new javax.swing.JMenuItem(); + saveMenuItem = new javax.swing.JMenuItem(); + saveAsMenuItem = new javax.swing.JMenuItem(); + exitMenuItem = new javax.swing.JMenuItem(); + editMenu = new javax.swing.JMenu(); + cutMenuItem = new javax.swing.JMenuItem(); + copyMenuItem = new javax.swing.JMenuItem(); + pasteMenuItem = new javax.swing.JMenuItem(); + deleteMenuItem = new javax.swing.JMenuItem(); + helpMenu = new javax.swing.JMenu(); + contentMenuItem = new javax.swing.JMenuItem(); + aboutMenuItem = new javax.swing.JMenuItem(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + fileMenu.setMnemonic('f'); + fileMenu.setText("File"); + + openMenuItem.setMnemonic('o'); + openMenuItem.setText("Open"); + fileMenu.add(openMenuItem); + + saveMenuItem.setMnemonic('s'); + saveMenuItem.setText("Save"); + fileMenu.add(saveMenuItem); + + saveAsMenuItem.setMnemonic('a'); + saveAsMenuItem.setText("Save As ..."); + saveAsMenuItem.setDisplayedMnemonicIndex(5); + fileMenu.add(saveAsMenuItem); + + exitMenuItem.setMnemonic('x'); + exitMenuItem.setText("Exit"); + exitMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + exitMenuItemActionPerformed(evt); + } + }); + fileMenu.add(exitMenuItem); + + menuBar.add(fileMenu); + + editMenu.setMnemonic('e'); + editMenu.setText("Edit"); + + cutMenuItem.setMnemonic('t'); + cutMenuItem.setText("Cut"); + editMenu.add(cutMenuItem); + + copyMenuItem.setMnemonic('y'); + copyMenuItem.setText("Copy"); + editMenu.add(copyMenuItem); + + pasteMenuItem.setMnemonic('p'); + pasteMenuItem.setText("Paste"); + editMenu.add(pasteMenuItem); + + deleteMenuItem.setMnemonic('d'); + deleteMenuItem.setText("Delete"); + editMenu.add(deleteMenuItem); + + menuBar.add(editMenu); + + helpMenu.setMnemonic('h'); + helpMenu.setText("Help"); + + contentMenuItem.setMnemonic('c'); + contentMenuItem.setText("Contents"); + helpMenu.add(contentMenuItem); + + aboutMenuItem.setMnemonic('a'); + aboutMenuItem.setText("About"); + helpMenu.add(aboutMenuItem); + + menuBar.add(helpMenu); + + setJMenuBar(menuBar); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE) + ); + + pack(); + }// //GEN-END:initComponents + + private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed + System.exit(0); + }//GEN-LAST:event_exitMenuItemActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(NewMDIApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new NewMDIApplication().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JMenuItem aboutMenuItem; + private javax.swing.JMenuItem contentMenuItem; + private javax.swing.JMenuItem copyMenuItem; + private javax.swing.JMenuItem cutMenuItem; + private javax.swing.JMenuItem deleteMenuItem; + private javax.swing.JDesktopPane desktopPane; + private javax.swing.JMenu editMenu; + private javax.swing.JMenuItem exitMenuItem; + private javax.swing.JMenu fileMenu; + private javax.swing.JMenu helpMenu; + private javax.swing.JMenuBar menuBar; + private javax.swing.JMenuItem openMenuItem; + private javax.swing.JMenuItem pasteMenuItem; + private javax.swing.JMenuItem saveAsMenuItem; + private javax.swing.JMenuItem saveMenuItem; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/main/java/chart/OHLCData.java b/src/main/java/chart/OHLCData.java index bb1f4bd..4a68415 100644 --- a/src/main/java/chart/OHLCData.java +++ b/src/main/java/chart/OHLCData.java @@ -36,7 +36,7 @@ public class OHLCData { //extends ArrayList { float max=0; float min=0; - int ras=20000; + int ras=60000; long time_start; diff --git a/src/main/java/gui/AboutDialog.form b/src/main/java/gui/AboutDialog.form new file mode 100644 index 0000000..d070e78 --- /dev/null +++ b/src/main/java/gui/AboutDialog.form @@ -0,0 +1,50 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/gui/AboutDialog.java b/src/main/java/gui/AboutDialog.java new file mode 100644 index 0000000..b4d1d81 --- /dev/null +++ b/src/main/java/gui/AboutDialog.java @@ -0,0 +1,123 @@ +/* + * 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 gui; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class AboutDialog extends javax.swing.JDialog { + + /** + * Creates new form aboutDialog + */ + public AboutDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + 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() { + + jLabel1 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jLabel1.setText("jLabel1"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(45, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(AboutDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + AboutDialog dialog = new AboutDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/gui/MainWin.form b/src/main/java/gui/MainWin.form index f7e6e33..4e0547a 100644 --- a/src/main/java/gui/MainWin.form +++ b/src/main/java/gui/MainWin.form @@ -51,16 +51,24 @@ - + + + + + + - + + + + diff --git a/src/main/java/gui/MainWin.java b/src/main/java/gui/MainWin.java index 92039c7..fd7f52c 100644 --- a/src/main/java/gui/MainWin.java +++ b/src/main/java/gui/MainWin.java @@ -25,6 +25,8 @@ */ package gui; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; import sesim.AutoTrader; import sesim.Exchange; import traders.RandomTrader; @@ -106,8 +108,9 @@ public class MainWin extends javax.swing.JFrame { 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(); + viewMenu = new javax.swing.JMenu(); + helpMenu = new javax.swing.JMenu(); + helpAbout = new javax.swing.JMenuItem(); jButton1.setText("jButton1"); jButton1.addActionListener(new java.awt.event.ActionListener() { @@ -149,13 +152,21 @@ public class MainWin extends javax.swing.JFrame { jMenu2.setText("Edit"); MainMenu.add(jMenu2); - jMenu1.setText("Help"); + viewMenu.setText("View"); + MainMenu.add(viewMenu); - jMenuItem2.setText("About"); - jMenuItem2.setToolTipText("About this Software"); - jMenu1.add(jMenuItem2); + helpMenu.setText("Help"); - MainMenu.add(jMenu1); + helpAbout.setText("About"); + helpAbout.setToolTipText("About this Software"); + helpAbout.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + helpAboutActionPerformed(evt); + } + }); + helpMenu.add(helpAbout); + + MainMenu.add(helpMenu); setJMenuBar(MainMenu); @@ -175,6 +186,11 @@ public class MainWin extends javax.swing.JFrame { se.start(); }//GEN-LAST:event_FileRunActionPerformed + private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed + AboutDialog d=new AboutDialog(this,true); + d.show(); + }//GEN-LAST:event_helpAboutActionPerformed + /** * @param args the command line arguments */ @@ -187,14 +203,17 @@ public class MainWin extends javax.swing.JFrame { //RandomTrader rt = rcfg.createTrader(se, 1000, 100); //rt.start(); - SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig(); + // SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig(); + RandomTraderConfig rcfg1 = new RandomTraderConfig(); AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 0); rt1.start(); + AutoTrader rt2 = rcfg1.createTrader(se, 1, 100); + rt2.start(); RandomTraderConfig cfg = new RandomTraderConfig(); - for (int i=0; i<1000; i++){ - AutoTrader randt = cfg.createTrader(se, 100, 100); + for (int i=0; i<10000; i++){ + AutoTrader randt = cfg.createTrader(se, 1, 100); randt.start(); } @@ -224,7 +243,7 @@ public class MainWin extends javax.swing.JFrame { // 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 | @@ -270,11 +289,12 @@ public class MainWin extends javax.swing.JFrame { private javax.swing.JMenuBar MainMenu; private gui.ControlPanel controlPanel2; private chart.FullChart fullChart2; + private javax.swing.JMenuItem helpAbout; + private javax.swing.JMenu helpMenu; private javax.swing.JButton jButton1; - private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuItem jMenuItem1; - private javax.swing.JMenuItem jMenuItem2; private gui.OrderBookPanel orderBookPanel1; + private javax.swing.JMenu viewMenu; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/traders/RandomTrader.java b/src/main/java/traders/RandomTrader.java index 409ae3c..7420646 100644 --- a/src/main/java/traders/RandomTrader.java +++ b/src/main/java/traders/RandomTrader.java @@ -171,7 +171,7 @@ public class RandomTrader extends AutoTrader { double money = getRandomAmmount(ad.money, myconfig.buy_volume); Quote q = se.getCurrentPrice(); - double lp = q == null ? 0.0 : q.price; + double lp = q == null ? 0.0001 : q.price; diff --git a/src/main/java/traders/RandomTraderConfig.java b/src/main/java/traders/RandomTraderConfig.java index 209b759..59e99fe 100644 --- a/src/main/java/traders/RandomTraderConfig.java +++ b/src/main/java/traders/RandomTraderConfig.java @@ -37,12 +37,12 @@ public class RandomTraderConfig extends AutoTraderConfig { public float[] sell_volume = {100, 100}; public float[] sell_limit = {-1, 0}; - public int[] sell_order_wait = {15, 33}; + public int[] sell_order_wait = {1, 5}; public int[] wait_after_sell = {10, 30}; public float[] buy_volume = {100, 100}; public float[] buy_limit = {0, 1}; - public int[] buy_order_wait = {15, 33}; + public int[] buy_order_wait = {1, 5}; public int[] wait_after_buy = {10, 30}; @Override diff --git a/src/main/java/traders/RandomTraderConfig_old.java b/src/main/java/traders/RandomTraderConfig_old.java deleted file mode 100644 index f6c57aa..0000000 --- a/src/main/java/traders/RandomTraderConfig_old.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2016, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package traders; - -import sesim.Account_old; -import sesim.TraderConfig_old; -import sesim.Exchange; -import sesim.AutoTrader_old; - -/** - * - * @author 7u83 <7u83@mail.ru> - */ -public class RandomTraderConfig_old extends TraderConfig_old { - - //public long maxage = 1000 * 10 * 1; - - - /*public long hold_shares_min = 10; - - public long hold_shares_max = 30; - - public float buy_volume_min = 10; - */ - - /** - * If shares are selled, this specifies - * the minimum and maximum volume to be selled - */ - public float[] sell_volume= {100,100}; - public float[] sell_limit = {-15,15}; - public int[] sell_order_wait = {15,33}; - public int[] wait_after_sell = {10,30}; - - - public float[] buy_volume={100,100}; - public float[] buy_limit = {-15,15}; - public int[] buy_order_wait = {15,33}; - public int[] wait_after_buy = {10,30}; - - - @Override - public AutoTrader_old createTrader(Exchange se, long shares, double money) { - Account_old a = new Account_old(se, shares, money); - return new RandomTrader_old(a, this); - } - - - -} diff --git a/src/main/java/traders/RandomTrader_old.java b/src/main/java/traders/RandomTrader_old.java deleted file mode 100644 index 086ca9a..0000000 --- a/src/main/java/traders/RandomTrader_old.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2016, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package traders; - -import sesim.Account_old; -import sesim.Order_old; -import java.util.Random; -import sesim.AutoTrader_old; -import sesim.TraderConfig_old; - -public class RandomTrader_old extends AutoTrader_old { - - protected enum Action { - sell,buy - } - - // config for this trader - final private RandomTraderConfig_old myconfig; - - // object to generate random numbers - final private Random rand = new Random(); - - public RandomTrader_old(Account_old account, TraderConfig_old config) { - super(account, config); - if (config == null) { - config = new RandomTraderConfig_old(); - } - myconfig = (RandomTraderConfig_old) config; - } - - /** - * Get a (long) random number between min an max - * - * @param min minimum value - * @param max maximeum value - * @return the number - */ - protected double getRandom(double min, double max) { - double r = rand.nextDouble(); - return (max - min) * r + min; - } - - protected int getRandom(int[] minmax) { - return (int) Math.round(getRandom(minmax[0], minmax[1])); - } - - /** - * - * @param val - * @param minmax - * @return - */ - protected double getRandomAmmount(double val, float[] minmax) { - double min = val * minmax[0] / 100.0; - double max = val * minmax[1] / 100.0; - return getRandom(min, max); - } - - public boolean waitForOrder(long seconds) { - - for (int i = 0; (i < seconds) && (0 != account.pending.size()); i++) { - doSleep(1); - } - - if (account.pending.size() != 0) { - Order_old o = account.pending.get(0); - account.se.cancelOrder_old(o); - return false; - } - return true; - } - - public boolean doBuy() { - - double money = getRandomAmmount(account.money, myconfig.sell_volume); - - double lp = account.se.getlastprice(); - double limit; - limit = lp + getRandomAmmount(lp, myconfig.buy_limit); - - long volume = (int) (money / (limit * 1)); - if (volume <= 0) { - return false; - } - - buy(volume, limit); - return waitForOrder(getRandom(myconfig.buy_order_wait)); - - } - - public boolean doSell() { - - long volume; - volume = (long) Math.round(getRandomAmmount(account.shares, myconfig.sell_volume)); - - double lp = account.se.getlastprice(); - double limit; - limit = lp + getRandomAmmount(lp, myconfig.sell_limit); - - sell(volume, limit); - return waitForOrder(getRandom(myconfig.sell_order_wait)); - - } - - /* private boolean monitorTrades() { - - int numpending = account.pending.size(); - if (numpending == 0) { -// System.out.print("RT: pending = 0 - return false\n"); - return false; - } - - Order_old o = account.pending.get(0); - long age = o.getAge(); - - // System.out.print("RT: age is: "+age+"\n"); - if (age > myconfig.maxage) { - // System.out.print("MaxAge is"+myconfig.maxage+"\n"); - account.se.cancelOrder_old(o); -// System.out.print("Age reached - canel return false\n"); - return false; - } - - //System.out.print("RT: monitor return true\n"); - return true; - } - */ - public void trade() { - - float am[] = {-10, 200}; - - double x = Math.round(this.getRandomAmmount(1000, am)); - /* System.out.print( - "Random:" - + x - + "\n" - ); - - */ - /* - // System.out.print("RT: Now trading\n"); - if (monitorTrades()) { - return; - } - - // What next to do? - int action = rand.nextInt(5); - - if (account.money < 10 && account.shares < 5) { - System.out.print("I'm almost ruined\n"); - } - - if (action == 1) { - doBuy(); - return; - } - - if (action == 2) { - doSell(); - return; - } - */ - } - - protected Action getAction() { - if (rand.nextInt(2)==0){ - return Action.buy; - } - else{ - return Action.sell; - } - - - } - - @Override - public void run() { - System.out.print("Starting Random Trader\n"); - while (true) { - -// What next to do? - Action action = getAction(); - - if (account.isRuined()) { -// System.out.print("I'm ruined\n"); -// System.exit(0); - } - boolean rc; - // action=1; - switch (action) { - - case sell: - if (account.shares <= 0) { - // we have no shares - continue; - } -// System.out.print("Sell\n"); - rc = doSell(); - if (!rc) { - continue; - } -// System.out.print("Sold\n"); - doSleep(getRandom(myconfig.wait_after_sell)); -// System.out.print("Next\n"); - break; - case buy: - if (account.money <= 0) { - // we have no money - continue; - } -// System.out.print("Sell\n"); - rc = doBuy(); - if (!rc) { - continue; - } -// System.out.print("Bought\n"); - doSleep(getRandom(myconfig.wait_after_buy)); -// System.out.print("Next\n"); - break; - - } - // doSleep(1); - - } - - } - -}