diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index b1ab11e..bafa321 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -99,7 +99,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab } String getAt(int unit) { - Date date = new Date(sesim.Scheduler.timeStart + unit * 5000); + Date date = new Date(/*sesim.Scheduler.timeStart*/ 0 + unit * 5000); // DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); String dateFormatted = formatter.format(date); diff --git a/src/main/java/chart/FullChart.java b/src/main/java/chart/FullChart.java index 4f7abf5..c4b512b 100644 --- a/src/main/java/chart/FullChart.java +++ b/src/main/java/chart/FullChart.java @@ -119,7 +119,7 @@ public class FullChart extends javax.swing.JPanel { } String getAt(int unit) { - Date date = new Date(sesim.Scheduler.timeStart + unit * 5000); + Date date = new Date(0 + unit * 5000); // DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); String dateFormatted = formatter.format(date); diff --git a/src/main/java/gui/AboutDialog.form b/src/main/java/gui/AboutDialog.form index 57b6897..48a2d59 100644 --- a/src/main/java/gui/AboutDialog.form +++ b/src/main/java/gui/AboutDialog.form @@ -1,6 +1,6 @@ -
+ @@ -62,6 +62,11 @@ + + + + + diff --git a/src/main/java/gui/AboutDialog.java b/src/main/java/gui/AboutDialog.java index b1f7da7..d029247 100644 --- a/src/main/java/gui/AboutDialog.java +++ b/src/main/java/gui/AboutDialog.java @@ -57,6 +57,7 @@ public class AboutDialog extends javax.swing.JDialog { setMinimumSize(new java.awt.Dimension(400, 300)); jTextPane1.setEditable(false); + jTextPane1.setFont(jTextPane1.getFont()); jTextPane1.setText("/*\n * Copyright (c) 2017, 7u83 <7u83@mail.ru>\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */"); jScrollPane1.setViewportView(jTextPane1); diff --git a/src/main/java/gui/Clock.form b/src/main/java/gui/Clock.form index d15c158..896cb73 100644 --- a/src/main/java/gui/Clock.form +++ b/src/main/java/gui/Clock.form @@ -16,13 +16,34 @@ - + + + + + - + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/gui/Clock.java b/src/main/java/gui/Clock.java index f986f64..7b3111a 100644 --- a/src/main/java/gui/Clock.java +++ b/src/main/java/gui/Clock.java @@ -25,19 +25,43 @@ */ package gui; +import java.util.Timer; +import java.util.TimerTask; +import sesim.Scheduler; + /** * * @author 7u83 <7u83@mail.ru> */ public class Clock extends javax.swing.JPanel { + private final Timer timer; + TimerTask clockUpdater; /** * Creates new form Clock */ public Clock() { initComponents(); - } + this.timer = new Timer(); + clockUpdater = new TimerTask() { + @Override + public void run() { + long t = Globals.se.timer.currentTimeMillis(); + + System.out.printf("The Clock: %d\n",t); + jLabel1.setText(Scheduler.formatTimeMillis(t)); + + } + }; + + timer.schedule(clockUpdater, 0, 1000); + + } + + + + /** * 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 @@ -47,19 +71,32 @@ public class Clock extends javax.swing.JPanel { // //GEN-BEGIN:initComponents private void initComponents() { + jLabel1 = new javax.swing.JLabel(); + + jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD, jLabel1.getFont().getSize()+6)); + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel1.setText("00:00:00"); + 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) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// //GEN-END:initComponents // 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/ClockDialog.form b/src/main/java/gui/ClockDialog.form new file mode 100644 index 0000000..3c797f4 --- /dev/null +++ b/src/main/java/gui/ClockDialog.form @@ -0,0 +1,54 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/gui/ClockDialog.java b/src/main/java/gui/ClockDialog.java new file mode 100644 index 0000000..76ce0ed --- /dev/null +++ b/src/main/java/gui/ClockDialog.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2017, tobias + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package gui; + +/** + * + * @author tobias + */ +public class ClockDialog extends javax.swing.JDialog { + + /** + * Creates new form ClockDialog + */ + public ClockDialog(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() { + + clock1 = new gui.Clock(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + jButton1.setText("Ok"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(clock1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jButton1) + .addGap(59, 59, 59)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(clock1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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(ClockDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(ClockDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(ClockDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(ClockDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ClockDialog dialog = new ClockDialog(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); + } + }); + } + + @Override + public void dispose(){ + super.dispose(); + System.out.print("Disposed\n"); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private gui.Clock clock1; + private javax.swing.JButton jButton1; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/gui/EditAutoTraderList.java b/src/main/java/gui/EditAutoTraderList.java index 0394314..f876ff7 100644 --- a/src/main/java/gui/EditAutoTraderList.java +++ b/src/main/java/gui/EditAutoTraderList.java @@ -32,6 +32,9 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; @@ -146,6 +149,24 @@ public class EditAutoTraderList extends javax.swing.JPanel { // model.setRowCount(3); list.setRowHeight(30); + + list.getModel().addTableModelListener((TableModelEvent e) -> { + System.out.printf("Table has changed\n", ""); +// if (summary==null) + // return; + + Double money=0.0; + Double shares=0.0; + + for (int r = 0; r < model.getRowCount(); r++) { + money+=(Double)list.getValueAt( r, list.getColumn("Money").getModelIndex()); + shares+=(Double)list.getValueAt( r, list.getColumn("Shares").getModelIndex()); + System.out.printf("Row: %d %f %f\n",r,money,shares); + } + + this.summary.setText(String.format("Fair Value: %.5f", money/shares)); + }); + } @@ -154,6 +175,8 @@ public class EditAutoTraderList extends javax.swing.JPanel { DefaultTableModel model = (DefaultTableModel) list.getModel(); model.setRowCount(model.getRowCount()+1); } + + JLabel summary=null; /** * This method is called from within the constructor to initialize the form. diff --git a/src/main/java/gui/EditAutoTraderListDialog.form b/src/main/java/gui/EditAutoTraderListDialog.form index 1f601db..1343718 100644 --- a/src/main/java/gui/EditAutoTraderListDialog.form +++ b/src/main/java/gui/EditAutoTraderListDialog.form @@ -24,7 +24,9 @@ - + + + @@ -44,6 +46,7 @@ + @@ -80,5 +83,7 @@ + + diff --git a/src/main/java/gui/EditAutoTraderListDialog.java b/src/main/java/gui/EditAutoTraderListDialog.java index acf6e46..9ef1a15 100644 --- a/src/main/java/gui/EditAutoTraderListDialog.java +++ b/src/main/java/gui/EditAutoTraderListDialog.java @@ -39,6 +39,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { initComponents(); this.setTitle("Edit Auto Traders"); this.setLocationRelativeTo(this.getParent()); + this.editAutoTraderList1.summary=this.jLabelSummary; //this.setLocationRelativeTo(MainWin.instance); } @@ -55,6 +56,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { jButton1 = new javax.swing.JButton(); jOkButton = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); + jLabelSummary = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -87,7 +89,9 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap() + .addComponent(jLabelSummary, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jOkButton) @@ -104,7 +108,8 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jOkButton) - .addComponent(jButton2)) + .addComponent(jButton2) + .addComponent(jLabelSummary)) .addContainerGap()) ); @@ -171,6 +176,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { private gui.EditAutoTraderList editAutoTraderList1; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabelSummary; private javax.swing.JButton jOkButton; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/gui/EditPreferencesDialog.form b/src/main/java/gui/EditPreferencesDialog.form index b2882de..68f394e 100644 --- a/src/main/java/gui/EditPreferencesDialog.form +++ b/src/main/java/gui/EditPreferencesDialog.form @@ -39,11 +39,8 @@ - - - - - + + @@ -59,11 +56,9 @@ - - - - - + + + @@ -122,18 +117,12 @@ - + - + - - - - - - - + diff --git a/src/main/java/gui/EditPreferencesDialog.java b/src/main/java/gui/EditPreferencesDialog.java index 209e18f..1d531e9 100644 --- a/src/main/java/gui/EditPreferencesDialog.java +++ b/src/main/java/gui/EditPreferencesDialog.java @@ -62,6 +62,10 @@ public class EditPreferencesDialog extends javax.swing.JDialog { lafComboBox.addItem(lafInfo1.getName()); } lafComboBox.setSelectedItem(Globals.prefs.get("laf", "Nimbus")); + + String selstr = Globals.prefs.get(Globals.DEVELSTATUS,"false"); + + this.jDevleopmentFeaturesCheckBox.setSelected(selstr.equals("true")); } /** @@ -78,8 +82,7 @@ public class EditPreferencesDialog extends javax.swing.JDialog { applyButton = new javax.swing.JButton(); okButton = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); - jCheckBox2 = new javax.swing.JCheckBox(); - jLabel2 = new javax.swing.JLabel(); + jDevleopmentFeaturesCheckBox = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -114,12 +117,9 @@ public class EditPreferencesDialog extends javax.swing.JDialog { } }); - jLabel1.setText("jLabel1"); + jLabel1.setText("Look and Feel:"); - jCheckBox2.setText("jCheckBox2"); - jCheckBox2.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING); - - jLabel2.setText("jLabel2"); + jDevleopmentFeaturesCheckBox.setText("Develeopment"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -140,9 +140,7 @@ public class EditPreferencesDialog extends javax.swing.JDialog { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton)) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel2) - .addComponent(jCheckBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jDevleopmentFeaturesCheckBox) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); @@ -153,11 +151,9 @@ public class EditPreferencesDialog extends javax.swing.JDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lafComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jCheckBox2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 191, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 178, Short.MAX_VALUE) + .addComponent(jDevleopmentFeaturesCheckBox) + .addGap(40, 40, 40) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(applyButton) @@ -207,6 +203,8 @@ public class EditPreferencesDialog extends javax.swing.JDialog { this.applyButtonActionPerformed(evt); String selected = (String) this.lafComboBox.getSelectedItem(); Globals.prefs.put("laf", selected); + String sel = this.jDevleopmentFeaturesCheckBox.isSelected() == true ? "true" : "false"; + Globals.prefs.put(Globals.DEVELSTATUS,sel); this.dispose(); }//GEN-LAST:event_okButtonActionPerformed @@ -255,9 +253,8 @@ public class EditPreferencesDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton applyButton; private javax.swing.JButton cancelButton; - private javax.swing.JCheckBox jCheckBox2; + private javax.swing.JCheckBox jDevleopmentFeaturesCheckBox; private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; private javax.swing.JComboBox lafComboBox; private javax.swing.JButton okButton; // End of variables declaration//GEN-END:variables diff --git a/src/main/java/gui/Globals.java b/src/main/java/gui/Globals.java index e763de2..a064a74 100644 --- a/src/main/java/gui/Globals.java +++ b/src/main/java/gui/Globals.java @@ -47,6 +47,8 @@ public class Globals { static final String STRATEGYPREFS = "Strategies"; static final String TRADERPREFS = "Traders"; + + static final String DEVELSTATUS = "devel_status"; static public sesim.Exchange se; diff --git a/src/main/java/gui/NewMDIApplication.form b/src/main/java/gui/NewMDIApplication.form index 6472f5d..7ed2347 100644 --- a/src/main/java/gui/NewMDIApplication.form +++ b/src/main/java/gui/NewMDIApplication.form @@ -110,7 +110,7 @@ - + @@ -131,6 +131,14 @@ + + + + + + + + @@ -188,12 +196,16 @@ - - - - - + + + + + + + + + @@ -204,7 +216,7 @@ - + diff --git a/src/main/java/gui/NewMDIApplication.java b/src/main/java/gui/NewMDIApplication.java index b34a147..081a642 100644 --- a/src/main/java/gui/NewMDIApplication.java +++ b/src/main/java/gui/NewMDIApplication.java @@ -28,6 +28,7 @@ package gui; import java.awt.Dialog; import java.awt.Frame; import java.io.File; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.logging.Handler; import java.util.logging.LogRecord; @@ -61,6 +62,10 @@ public class NewMDIApplication extends javax.swing.JFrame { public void startTraders() { JSONArray tlist = Globals.getTraders(); + + Double moneyTotal=0.0; + Double sharesTotal=0.0; + for (int i=0; i at_class : traders) { + System.out.printf("Class = %s\n",at_class.getName()); + if (Modifier.isAbstract(at_class.getModifiers())) { + continue; + } + AutoTraderConfig cfg = at_class.newInstance(); System.out.printf("Have a Trader with name: %s\n", cfg.getDisplayName()); } @@ -510,7 +544,6 @@ public class NewMDIApplication extends javax.swing.JFrame { private javax.swing.JMenu fileMenu; private javax.swing.JMenu helpMenu; private javax.swing.JButton jButton2; - private javax.swing.JMenu jMenu1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JButton jRunButton; @@ -526,6 +559,8 @@ public class NewMDIApplication extends javax.swing.JFrame { private javax.swing.JMenuItem pasteMenuItem; private javax.swing.JMenuItem saveAsMenuItem; private javax.swing.JMenuItem saveMenuItem; + private javax.swing.JMenuItem viewClock; + private javax.swing.JMenu viewMenu; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/gui/NewStrategyDialog.java b/src/main/java/gui/NewStrategyDialog.java index 102b151..7809412 100644 --- a/src/main/java/gui/NewStrategyDialog.java +++ b/src/main/java/gui/NewStrategyDialog.java @@ -41,7 +41,8 @@ public class NewStrategyDialog extends EscDialog { super(parent, modal); initComponents(); this.setLocationRelativeTo(this.getParent()); - ArrayList names = Globals.tloader.getDefaultStrategyNames(); + boolean devel = Globals.prefs.get(Globals.DEVELSTATUS, "false").equals("true"); + ArrayList names = Globals.tloader.getDefaultStrategyNames(devel); this.jStrategyComboBox.removeAllItems(); names.stream().forEach((s) -> { this.jStrategyComboBox.addItem(s); diff --git a/src/main/java/gui/OrderBook.java b/src/main/java/gui/OrderBook.java index 7c12c09..17ed3b4 100644 --- a/src/main/java/gui/OrderBook.java +++ b/src/main/java/gui/OrderBook.java @@ -178,7 +178,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B case 2: double v = o.getVolume(); if(v<=0){ - System.out.printf("Order: %s %f %f\n",o.getType().toString(),o.getVolume(),o.getLimit()); +// System.out.printf("Order: %s %f %f\n",o.getType().toString(),o.getVolume(),o.getLimit()); // System.exit(0); } diff --git a/src/main/java/gui/TraderListPanel.java b/src/main/java/gui/TraderListPanel.java index 86dc8ab..019205a 100644 --- a/src/main/java/gui/TraderListPanel.java +++ b/src/main/java/gui/TraderListPanel.java @@ -164,7 +164,7 @@ public class TraderListPanel extends javax.swing.JPanel case 3: return "Shares"; case 4: - return "Welth"; + return "Wealth"; } return ""; } @@ -202,7 +202,7 @@ public class TraderListPanel extends javax.swing.JPanel case 3: return String.format("%.2f", ti.shares); case 4: - return String.format("%.2f", ti.welth); + return ti.welth; //String.format("%.2f", ti.welth); } return "x"; diff --git a/src/main/java/sesim/AutoTraderBase.java b/src/main/java/sesim/AutoTraderBase.java new file mode 100644 index 0000000..ffede0e --- /dev/null +++ b/src/main/java/sesim/AutoTraderBase.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, tobias + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package sesim; + +import org.json.JSONObject; + +/** + * + * @author tobias + */ +public abstract class AutoTraderBase implements AutoTraderConfig{ + + + + @Override + public boolean getDevelStatus() { + return true; + } + + +} + \ No newline at end of file diff --git a/src/main/java/sesim/AutoTraderConfig.java b/src/main/java/sesim/AutoTraderConfig.java index c15da37..2d63915 100644 --- a/src/main/java/sesim/AutoTraderConfig.java +++ b/src/main/java/sesim/AutoTraderConfig.java @@ -38,5 +38,6 @@ public abstract interface AutoTraderConfig { public abstract AutoTraderGui getGui(); public abstract JSONObject getConfig(); public abstract void putConfig(JSONObject cfg); + public abstract boolean getDevelStatus(); } diff --git a/src/main/java/sesim/AutoTraderLoader.java b/src/main/java/sesim/AutoTraderLoader.java index ed4ea48..ecf12f8 100644 --- a/src/main/java/sesim/AutoTraderLoader.java +++ b/src/main/java/sesim/AutoTraderLoader.java @@ -146,7 +146,7 @@ public class AutoTraderLoader { } - public ArrayList getDefaultStrategyNames() { + public ArrayList getDefaultStrategyNames(boolean devel) { ArrayList> trclasses; trclasses = this.getTraders(); ArrayList ret = new ArrayList<>(); @@ -154,9 +154,13 @@ public class AutoTraderLoader { for (int i = 0; i < trclasses.size(); i++) { try { + AutoTraderConfig ac = trclasses.get(i).newInstance(); + if (ac.getDevelStatus() && devel==false){ + continue; + } ret.add(ac.getClass().getCanonicalName()); - } catch (Exception ex) { + } catch (InstantiationException | IllegalAccessException ex) { } @@ -164,6 +168,10 @@ public class AutoTraderLoader { return ret; } + + public ArrayList getDefaultStrategyNames() { + return this.getDefaultStrategyNames(true); + } public AutoTraderConfig getStrategyBase(String name) { ArrayList> traders = this.getTraders(); diff --git a/src/main/java/sesim/Exchange.java b/src/main/java/sesim/Exchange.java index 431e125..3c7cfc0 100644 --- a/src/main/java/sesim/Exchange.java +++ b/src/main/java/sesim/Exchange.java @@ -22,19 +22,18 @@ public class Exchange { //extends Thread { public void setSharesDecimals(int n) { shares_df = Math.pow(10, n); } - - public double roundToDecimals(double val,double f){ - return Math.floor(val*f)/f; - } - - public double roundShares(double shares){ - return roundToDecimals(shares,shares_df); - } - public double roundMoney(double money){ - return roundToDecimals(money,money_df); + + public double roundToDecimals(double val, double f) { + return Math.floor(val * f) / f; } - + public double roundShares(double shares) { + return roundToDecimals(shares, shares_df); + } + + public double roundMoney(double money) { + return roundToDecimals(money, money_df); + } public enum OrderType { BID, ASK @@ -131,9 +130,9 @@ public class Exchange { //extends Thread { if (d != 0) { return d > 0 ? 1 : -1; } - - d=right.initial_volume-left.initial_volume; - if (d!=0){ + + d = right.initial_volume - left.initial_volume; + if (d != 0) { return d > 0 ? 1 : -1; } @@ -376,17 +375,16 @@ public class Exchange { //extends Thread { ArrayList ret = new ArrayList<>(); Iterator it = book.iterator(); - - for (int i = 0; i < depth && it.hasNext(); i++) { - Order o=it.next(); - // System.out.print(o.volume); - if (o.volume<=0) + Order o = it.next(); + // System.out.print(o.volume); + if (o.volume <= 0) { System.exit(0); + } ret.add(o); } - // System.out.println(); + // System.out.println(); tradelock.unlock(); return ret; } @@ -429,12 +427,29 @@ public class Exchange { //extends Thread { return ret; } + Random random = new Random(); + + public int randNextInt() { + return random.nextInt(); + } + + public int randNextInt(int bounds) { + return random.nextInt(bounds); + } + + public double randNextDouble() { + return random.nextDouble(); + + } + /** * * @param o */ long nextQuoteId = 0; + public double fairValue = 0; + private void removeOrderIfExecuted(Order o) { if (o.volume != 0) { return; @@ -443,7 +458,7 @@ public class Exchange { //extends Thread { o.account.orders.remove(o.id); SortedSet book = order_books.get(o.type); - + book.remove(book.first()); } @@ -465,8 +480,6 @@ public class Exchange { //extends Thread { Order a = ask.first(); //System.out.printf("In %f (%f) < %f (%f)\n",b.limit,b.volume,a.limit,a.volume); - - if (b.limit < a.limit) { break; } @@ -474,9 +487,8 @@ public class Exchange { //extends Thread { // There is a match, calculate price and volume double price = b.id < a.id ? b.limit : a.limit; double volume = b.volume >= a.volume ? a.volume : b.volume; - - //System.out.printf("Price %f Vol %f\n", price,volume); + //System.out.printf("Price %f Vol %f\n", price,volume); // Transfer money and shares transferMoneyAndShares(b.account, a.account, volume * price, -volume); //System.out.print("Transfer Shares was called with volume "+volume+"\n"); @@ -485,7 +497,6 @@ public class Exchange { //extends Thread { a.volume -= volume; //System.out.printf("In %f (%f) < %f (%f)\n",b.limit,b.volume,a.limit,a.volume); - volume_total += volume; money_total += price * volume; @@ -530,9 +541,9 @@ public class Exchange { //extends Thread { } Order o = new Order(a, type, volume, limit); - if (o.volume<=0 || o.limit<=0){ + if (o.volume <= 0 || o.limit <= 0) { System.out.print("binweg\n"); - return -1; + return -1; } tradelock.lock(); diff --git a/src/main/java/sesim/Scheduler.java b/src/main/java/sesim/Scheduler.java index 72d0876..81669ca 100644 --- a/src/main/java/sesim/Scheduler.java +++ b/src/main/java/sesim/Scheduler.java @@ -25,7 +25,11 @@ */ package sesim; +import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Comparator; +import java.util.Date; import java.util.Iterator; import java.util.SortedMap; import java.util.SortedSet; @@ -48,8 +52,9 @@ public class Scheduler extends Thread { long timerTask(); } - /**\ - * + /** + * \ + * */ public void halt() { halt = true; @@ -59,7 +64,7 @@ public class Scheduler extends Thread { } /** - * + * */ private class ObjectComparator implements Comparator { @@ -69,23 +74,35 @@ public class Scheduler extends Thread { } } + long last_time_millis = System.currentTimeMillis(); + double current_time_millis = 0.0; + /** * * @return */ - public static long currentTimeMillis() { - return System.currentTimeMillis(); + public long currentTimeMillis() { + long diff = System.currentTimeMillis() - last_time_millis; + last_time_millis += diff; + this.current_time_millis += diff * 1; + + return (long) this.current_time_millis; + + } + + static public String formatTimeMillis(long t) { + Date date = new Date(t); + DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); + String dateFormatted = formatter.format(date); + + return dateFormatted; } - - public static long timeStart=Scheduler.currentTimeMillis(); - - /** - * + * * @param e - * @param time + * @param time */ public void startTimerEvent(TimerTask e, long time) { long evtime = time + currentTimeMillis(); @@ -96,13 +113,13 @@ public class Scheduler extends Thread { notify(); } } - - private boolean pause=false; - - public void pause(){ - pause=!pause; - synchronized(this){ - this.notify(); + + private boolean pause = false; + + public void pause() { + pause = !pause; + synchronized (this) { + this.notify(); } } @@ -150,18 +167,18 @@ public class Scheduler extends Thread { @Override public void run() { + while (!halt) { - - long wtime = runEvents(); + if (wtime == 0) { continue; } synchronized (this) { try { - + if (wtime != -1 && !pause) { wait(wtime); } else { diff --git a/src/main/java/traders/RandomTrader.java b/src/main/java/traders/RandomTrader.java index decd34e..09d3fa9 100644 --- a/src/main/java/traders/RandomTrader.java +++ b/src/main/java/traders/RandomTrader.java @@ -25,6 +25,7 @@ */ package traders; +import gui.Globals; import java.util.*; import java.util.Random; //import java.util.TimerTask; @@ -46,7 +47,7 @@ public class RandomTrader extends AutoTrader { sesim.Exchange.Account a = se.getAccount(account_id); long rc = this.doTrade(); - return rc/80 ; + return rc ; } @@ -66,7 +67,7 @@ public class RandomTrader extends AutoTrader { public long timerTask() { sesim.Exchange.Account a = se.getAccount(account_id); long rc = this.doTrade(); - return rc /100; + return rc / 1; // return this.event(); } @@ -76,7 +77,7 @@ public class RandomTrader extends AutoTrader { } protected Action getAction() { - if (rand.nextInt(2) == 0) { + if (se.randNextInt(2) == 0) { return Action.BUY; } else { return Action.SELL; @@ -84,7 +85,10 @@ public class RandomTrader extends AutoTrader { } - double start = 0.1; + double getStart (){ + return Globals.se.fairValue; + + } //Timer timer = new Timer(); @Override @@ -99,7 +103,7 @@ public class RandomTrader extends AutoTrader { // config for this trader //final private RandomTraderConfig_old myconfig; // object to generate random numbers - final private Random rand = new Random(); + //final private Random rand = new Random(); /** * Get a (long) random number between min an max @@ -109,7 +113,8 @@ public class RandomTrader extends AutoTrader { * @return the number */ protected double getRandom(double min, double max) { - double r = rand.nextDouble(); + double r = se.randNextDouble(); + return (max - min) * r + min; } @@ -117,6 +122,7 @@ public class RandomTrader extends AutoTrader { return (int) Math.round(getRandom(minmax[0], minmax[1])); } + /** * * @param val @@ -124,6 +130,8 @@ public class RandomTrader extends AutoTrader { * @return */ protected double getRandomAmmount(double val, Float[] minmax) { + + //System.out.printf("RandomAmmount: %f (%f,%f)\n",val, minmax[0], minmax[1]); double min = val * minmax[0] / 100.0; double max = val * minmax[1] / 100.0; return getRandom(min, max); @@ -163,11 +171,13 @@ public class RandomTrader extends AutoTrader { double money = getRandomAmmount(ad.money, myconfig.buy_volume); Quote q = se.getCurrentPrice(); - double lp = q == null ? start : q.price; + double lp = q == null ? getStart() : q.price; double limit; limit = lp + getRandomAmmount(lp, myconfig.buy_limit); +// System.out.printf("MyLimit: %f\n",limit); + long volume = (long) (money / (limit * 1)); if (volume <= 0) { @@ -196,7 +206,7 @@ public class RandomTrader extends AutoTrader { // double lp = 100.0; //se.getBestLimit(type); Quote q = se.getCurrentPrice(); - double lp = q == null ? start : q.price; + double lp = q == null ? getStart() : q.price; double limit; limit = lp + getRandomAmmount(lp, myconfig.sell_limit); diff --git a/src/main/java/traders/RandomTraderConfig.java b/src/main/java/traders/RandomTraderConfig.java index 817e170..5948d4a 100644 --- a/src/main/java/traders/RandomTraderConfig.java +++ b/src/main/java/traders/RandomTraderConfig.java @@ -31,6 +31,7 @@ import javax.swing.JPanel; import org.json.JSONArray; import org.json.JSONObject; import sesim.AutoTrader; +import sesim.AutoTraderBase; import sesim.AutoTraderConfig; import sesim.AutoTraderGui; import sesim.Exchange; @@ -39,7 +40,7 @@ import sesim.Exchange; * * @author 7u83 */ -public class RandomTraderConfig implements AutoTraderConfig { +public class RandomTraderConfig extends AutoTraderBase implements AutoTraderConfig { public Float[] sell_volume = {100f, 100f}; public Float[] sell_limit = {-0.1f, 0.10101f}; @@ -154,4 +155,10 @@ public class RandomTraderConfig implements AutoTraderConfig { wait_after_buy = to_integer(cfg.getJSONArray(WAIT_AFTER_BUY)); } + + @Override + public boolean getDevelStatus() { + return false; + + } } diff --git a/src/main/java/traders/SuperTraderConfig.java b/src/main/java/traders/SuperTraderConfig.java index 8785d8a..de70d7f 100644 --- a/src/main/java/traders/SuperTraderConfig.java +++ b/src/main/java/traders/SuperTraderConfig.java @@ -67,5 +67,10 @@ public class SuperTraderConfig implements AutoTraderConfig{ public void putConfig(JSONObject cfg) { } + + @Override + public boolean getDevelStatus() { + return true; + } } diff --git a/src/main/java/traders/SwitchingTraderConfig.java b/src/main/java/traders/SwitchingTraderConfig.java index 67418f1..642e02e 100644 --- a/src/main/java/traders/SwitchingTraderConfig.java +++ b/src/main/java/traders/SwitchingTraderConfig.java @@ -34,13 +34,13 @@ import sesim.Exchange; * * @author 7u83 <7u83@mail.ru> */ -public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTraderConfig{ +public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTraderConfig { @Override public AutoTrader createTrader(Exchange se, JSONObject cfg, double money, double shares) { - + return new traders.SwitchingTrader(se, money, shares, this); - + } public SwitchingTraderConfig() { @@ -55,9 +55,15 @@ public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTra buy_wait = new Integer[]{1, 5}; wait_after_buy = new Integer[]{1, 5}; } - + @Override - public String getDisplayName(){ + public String getDisplayName() { return "SwitchingTrader"; } + + @Override + public boolean getDevelStatus() { + return true; + } + }