diff --git a/nbproject/project.properties b/nbproject/project.properties index 93ffbf1..864fce9 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sat, 08 Apr 2017 22:54:05 +0200 +#Sun, 09 Apr 2017 00:33:50 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/gui/Globals.java b/src/gui/Globals.java index fb9e6b6..cfca00e 100644 --- a/src/gui/Globals.java +++ b/src/gui/Globals.java @@ -219,6 +219,7 @@ public class Globals { } + public static void saveFile(File f) throws FileNotFoundException { JSONObject sobj = new JSONObject(); @@ -237,12 +238,7 @@ public class Globals { } - public static void loadFile(File f) throws IOException { - - f.getAbsoluteFile(); - - String s; - s = new String(Files.readAllBytes(f.toPath())); + public static void loadString(String s) throws IOException{ JSONObject sobj = new JSONObject(s); Double version = sobj.getDouble(PrefKeys.SESIMVERSION); @@ -257,5 +253,15 @@ public class Globals { putTraders(traders); } + + public static void loadFile(File f) throws IOException { + + f.getAbsoluteFile(); + String s; + s = new String(Files.readAllBytes(f.toPath())); + + loadString(s); + + } } diff --git a/src/gui/MainChart.java b/src/gui/MainChart.java index b3e0e00..546d569 100644 --- a/src/gui/MainChart.java +++ b/src/gui/MainChart.java @@ -88,7 +88,7 @@ public class MainChart extends chart.Chart { 1 * 24 * 3600 * 1000, 2 * 24 * 3600 * 1000 }; - private final Integer default_cmopression = 60 * 1000; + private final Integer default_cmopression = 60 * 60 * 1000; private void initCtxMenu() { ButtonGroup group = new ButtonGroup(); diff --git a/src/gui/SeSimApplication.form b/src/gui/SeSimApplication.form index 32708d8..9e9fd6b 100644 --- a/src/gui/SeSimApplication.form +++ b/src/gui/SeSimApplication.form @@ -53,17 +53,6 @@ - - - - - - - - - - - @@ -101,6 +90,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -195,21 +205,6 @@ - - - - - - - - - - - - - - - diff --git a/src/gui/SeSimApplication.java b/src/gui/SeSimApplication.java index fcfc002..ae6cddd 100644 --- a/src/gui/SeSimApplication.java +++ b/src/gui/SeSimApplication.java @@ -34,8 +34,10 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Scanner; import java.util.TimerTask; import java.util.logging.Handler; import java.util.logging.Level; @@ -56,7 +58,6 @@ import sesim.AutoTraderConfig; import sesim.AutoTraderInterface; import sesim.Exchange; import sesim.Scheduler; -import traders.RandomTraderConfig; /** * @@ -70,6 +71,11 @@ public class SeSimApplication extends javax.swing.JFrame { public SeSimApplication() { initComponents(); setTitle(""); + boolean init = Globals.prefs.getBoolean("initilized", false); + if (!init){ + resetToDefaults(); + Globals.prefs.putBoolean("initilized", true); + } this.chartSrollPane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER); this.setLocationRelativeTo(null); } @@ -174,12 +180,13 @@ public class SeSimApplication extends javax.swing.JFrame { statistics1 = new gui.Statistics(); menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); - resetMenuItem = new javax.swing.JMenuItem(); - jSeparator5 = new javax.swing.JPopupMenu.Separator(); openMenuItem = new javax.swing.JMenuItem(); saveMenuItem = new javax.swing.JMenuItem(); saveAsMenuItem = new javax.swing.JMenuItem(); closeMenuItem = new javax.swing.JMenuItem(); + jSeparator5 = new javax.swing.JPopupMenu.Separator(); + resetToDefaultsMenuItem = new javax.swing.JMenuItem(); + clearMenuItem = new javax.swing.JMenuItem(); jSeparator4 = new javax.swing.JPopupMenu.Separator(); exitMenuItem = new javax.swing.JMenuItem(); editMenu = new javax.swing.JMenu(); @@ -193,9 +200,6 @@ public class SeSimApplication extends javax.swing.JFrame { simMenuStart = new javax.swing.JMenuItem(); simMenuPause = new javax.swing.JMenuItem(); simMenuStop = new javax.swing.JMenuItem(); - jSeparator3 = new javax.swing.JPopupMenu.Separator(); - jMenuItem4 = new javax.swing.JMenuItem(); - jMenuItem5 = new javax.swing.JMenuItem(); viewMenu = new javax.swing.JMenu(); viewTraderListCheckBox = new javax.swing.JCheckBoxMenuItem(); jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem(); @@ -334,16 +338,6 @@ public class SeSimApplication extends javax.swing.JFrame { fileMenu.setMnemonic('f'); fileMenu.setText("File"); - resetMenuItem.setMnemonic('r'); - resetMenuItem.setText("Reset"); - resetMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - resetMenuItemActionPerformed(evt); - } - }); - fileMenu.add(resetMenuItem); - fileMenu.add(jSeparator5); - openMenuItem.setMnemonic('o'); openMenuItem.setText("Open"); openMenuItem.addActionListener(new java.awt.event.ActionListener() { @@ -380,6 +374,26 @@ public class SeSimApplication extends javax.swing.JFrame { } }); fileMenu.add(closeMenuItem); + fileMenu.add(jSeparator5); + + resetToDefaultsMenuItem.setMnemonic('r'); + resetToDefaultsMenuItem.setText("Reset to defaults"); + resetToDefaultsMenuItem.setToolTipText(""); + resetToDefaultsMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + resetToDefaultsMenuItemActionPerformed(evt); + } + }); + fileMenu.add(resetToDefaultsMenuItem); + + clearMenuItem.setMnemonic('c'); + clearMenuItem.setText("Clear All"); + clearMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + clearMenuItemActionPerformed(evt); + } + }); + fileMenu.add(clearMenuItem); fileMenu.add(jSeparator4); exitMenuItem.setMnemonic('x'); @@ -465,18 +479,6 @@ public class SeSimApplication extends javax.swing.JFrame { } }); simMenu.add(simMenuStop); - simMenu.add(jSeparator3); - - jMenuItem4.setText("Point Zero"); - jMenuItem4.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jMenuItem4ActionPerformed(evt); - } - }); - simMenu.add(jMenuItem4); - - jMenuItem5.setText("jMenuItem5"); - simMenu.add(jMenuItem5); menuBar.add(simMenu); @@ -737,9 +739,29 @@ public class SeSimApplication extends javax.swing.JFrame { }//GEN-LAST:event_editExchangeMenuItemActionPerformed - private void resetMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetMenuItemActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_resetMenuItemActionPerformed + private void resetToDefaults(){ + InputStream is = getClass().getResourceAsStream("/resources/files/defaultcfg.json"); + String df = new Scanner(is, "UTF-8").useDelimiter("\\A").next(); + + try { + Globals.loadString(df); + } catch (IOException ex) { + JOptionPane.showMessageDialog(this, "Can't load file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); + + } + + } + + private void resetToDefaultsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetToDefaultsMenuItemActionPerformed + + int dialogResult = JOptionPane.showConfirmDialog(this, "Are you sure?", "Warning", JOptionPane.YES_NO_OPTION); + if (dialogResult != JOptionPane.YES_OPTION) { + return; + } + + this.resetToDefaults(); + + }//GEN-LAST:event_resetToDefaultsMenuItemActionPerformed private void simMenuStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simMenuStartActionPerformed startSim(); @@ -775,10 +797,6 @@ public class SeSimApplication extends javax.swing.JFrame { jd.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed - private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed - Globals.se.pointZero(); - }//GEN-LAST:event_jMenuItem4ActionPerformed - TraderListDialog tld = null; private void viewTraderListCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewTraderListCheckBoxActionPerformed @@ -822,6 +840,10 @@ public class SeSimApplication extends javax.swing.JFrame { setTitle(""); }//GEN-LAST:event_closeMenuItemActionPerformed + private void clearMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearMenuItemActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_clearMenuItemActionPerformed + /** * @param args the command line arguments * @throws java.lang.IllegalAccessException @@ -872,6 +894,7 @@ public class SeSimApplication extends javax.swing.JFrame { private javax.swing.JSpinner accelSpinner; private gui.MainChart chart; private javax.swing.JScrollPane chartSrollPane; + private javax.swing.JMenuItem clearMenuItem; private gui.Clock clock; private javax.swing.JMenuItem closeMenuItem; private javax.swing.JMenuItem deleteMenuItem; @@ -884,13 +907,10 @@ public class SeSimApplication extends javax.swing.JFrame { private javax.swing.JButton jButton2; private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1; private javax.swing.JLabel jLabel1; - private javax.swing.JMenuItem jMenuItem4; - private javax.swing.JMenuItem jMenuItem5; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator2; - private javax.swing.JPopupMenu.Separator jSeparator3; private javax.swing.JPopupMenu.Separator jSeparator4; private javax.swing.JPopupMenu.Separator jSeparator5; private javax.swing.JSplitPane jSplitPane1; @@ -905,7 +925,7 @@ public class SeSimApplication extends javax.swing.JFrame { private gui.orderbook.OrderBooksHorizontal orderBooksHorizontal1; private javax.swing.JMenuItem pasteMenuItem; private gui.orderbook.QuoteVertical quoteVertical1; - private javax.swing.JMenuItem resetMenuItem; + private javax.swing.JMenuItem resetToDefaultsMenuItem; private javax.swing.JButton runButton; private javax.swing.JMenuItem saveAsMenuItem; private javax.swing.JMenuItem saveMenuItem; diff --git a/src/resources/files/defaultcfg.json b/src/resources/files/defaultcfg.json index d387583..40824d6 100644 --- a/src/resources/files/defaultcfg.json +++ b/src/resources/files/defaultcfg.json @@ -1,101 +1,60 @@ { "traders": [ { - "Money": "100.0", - "Strategy": "Tube", + "Money": "1000000.0", + "Strategy": "SimpleRandom", "Enabled": "true", - "Count": "10000", - "Shares": "100.0", - "Name": "Mond" + "Count": "1", + "Shares": "10000.0", + "Name": "Alice" }, { - "Money": "1000.0", - "Strategy": "NasenTrading", + "Money": "10000.0", + "Strategy": "SimpleRandom", "Enabled": "true", - "Count": "100", - "Shares": "10.0", - "Name": "Nase" + "Count": "1", + "Shares": "100.0", + "Name": "Bob" } ], - "strategies": { - "Tube": { - "sell_wait": [ - 10000, - 50000 - ], - "initla_delay": [ - 0, - 5 - ], - "sell_limit": [ - -2, - 2 - ], - "sell_wait_after": [ - 1000, - 30000 - ], - "buy_wait": [ - 10000, - 50000 - ], - "sell_volume": [ - 100, - 100 - ], - "buy_wait_after": [ - 10, - 30 - ], - "buy_volume": [ - 100, - 100 - ], - "buy_limit": [ - -2, - 2 - ], - "base": "traders.RandomTraderA" - }, - "NasenTrading": { - "sell_wait": [ - 10000, - 50000 - ], - "initla_delay": [ - 0, - 111 - ], - "sell_limit": [ - -2, - 9 - ], - "sell_wait_after": [ - 1000, - 30000 - ], - "buy_wait": [ - 10000, - 50000 - ], - "sell_volume": [ - 100, - 100 - ], - "buy_wait_after": [ - 10, - 30 - ], - "buy_volume": [ - 100, - 100 - ], - "buy_limit": [ - -2, - 9 - ], - "base": "traders.RandomTraderA" - } - }, + "strategies": {"SimpleRandom": { + "sell_wait": [ + 10000, + 50000 + ], + "initla_delay": [ + 0, + 5 + ], + "sell_limit": [ + -2, + 2 + ], + "sell_wait_after": [ + 0, + 0 + ], + "buy_wait": [ + 10000, + 50000 + ], + "sell_volume": [ + 100, + 100 + ], + "buy_wait_after": [ + 0, + 0 + ], + "buy_volume": [ + 100, + 100 + ], + "buy_limit": [ + -2, + 2 + ], + "base": "traders.RandomTraderA" + }}, "version": 0.1 } \ No newline at end of file diff --git a/src/traders/RandomTraderA.java b/src/traders/RandomTraderA.java index 4a6d695..605da24 100644 --- a/src/traders/RandomTraderA.java +++ b/src/traders/RandomTraderA.java @@ -50,12 +50,12 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener { public Float[] sell_volume = {100f, 100f}; public Float[] sell_limit = {-2f, 2f}; public Long[] sell_wait = {10000L, 50000L}; - public Long[] wait_after_sell = {1000L, 30000L}; + public Long[] wait_after_sell = {0L, 0L}; public Float[] buy_volume = {100f, 100f}; public Float[] buy_limit = {-2f, 2f}; public Long[] buy_wait = {10000L, 50000L}; - public Long[] wait_after_buy = {10L, 30L}; + public Long[] wait_after_buy = {0L, 0L}; final String INITIAL_DELAY = "initla_delay"; final String SELL_VOLUME = "sell_volume";