diff --git a/nbproject/project.properties b/nbproject/project.properties index 1661fa6..10751bd 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 16 Apr 2017 08:07:50 +0200 +#Sun, 16 Apr 2017 16:33:56 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/gui/EditStrategies.java b/src/gui/EditStrategies.java index 8845f0c..9022840 100644 --- a/src/gui/EditStrategies.java +++ b/src/gui/EditStrategies.java @@ -284,7 +284,7 @@ public final class EditStrategies extends javax.swing.JDialog { Globals.LOGGER.info(String.format("Base %s\n", base)); - ac = Globals.tloader.getStrategyBase(base); + ac = Globals.tloader.getAutoTraderInterface(base); if (ac == null) { System.out.print("BASE IST NULL\n"); Globals.LOGGER.info(String.format("Can't load: %s\n", base)); @@ -401,7 +401,7 @@ System.out.printf("The big name: %s\n", ac.getClass().getCanonicalName()); if (sd.result==null) return; - AutoTraderInterface ac = Globals.tloader.getStrategyBase(sd.result.base); + AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(sd.result.base); JSONObject cfg = ac.getConfig(); System.out.printf("Initial cfg %s\n", cfg.toString(2)); cfg.put("base", ac.getClass().getCanonicalName()); diff --git a/src/gui/Globals.java b/src/gui/Globals.java index 9d3b47c..7f46413 100644 --- a/src/gui/Globals.java +++ b/src/gui/Globals.java @@ -49,12 +49,11 @@ import sesim.AutoTraderLoader; * @author 7u83 <7u83@mail.ru> */ public class Globals { - + public static final String SESIM_FILEEXTENSION = "sesim"; public static final Double SESIM_FILEVERSION = 0.1; - + public static final String SESIM_APPTITLE = "SeSim - Stock Exchange Simulator"; - public interface CfgListener { @@ -75,9 +74,8 @@ public class Globals { public static JFrame frame; - // static final String STRATEGYPREFS = "Strategies"; - // static final String TRADERPREFS = "Traders"; - + // static final String STRATEGYPREFS = "Strategies"; + // static final String TRADERPREFS = "Traders"; static final String DEVELSTATUS = "devel_status"; public static final String GODMODE = "godmode"; @@ -86,19 +84,17 @@ public class Globals { /** * Defines keys for preferences */ - public static final class PrefKeys{ + public static final class PrefKeys { public static String WORKDIR = "workdir"; public static final String CURRENTFILE = "currentfile"; - + public static final String SESIMVERSION = "version"; public static final String STRATEGIES = "strategies"; public static final String TRADERS = "traders"; - - } - + static public Preferences prefs; public static class CfgStrings { @@ -140,20 +136,14 @@ public class Globals { static AutoTraderLoader tloader; static void initGlobals() { - String[] a = System.getProperty("java.class.path").split(System.getProperty("path.separator")); - ArrayList pathlist = new ArrayList<>(Arrays.asList(a)); - System.out.printf("Init tloader\n"); - - pathlist = new ArrayList<>(); - String dp = new java.io.File(SeSimApplication.class.getProtectionDomain() + ArrayList pathlist = new ArrayList<>(); + String default_path = new java.io.File(SeSimApplication.class.getProtectionDomain() .getCodeSource() .getLocation() .getPath()).toString(); - pathlist.add(dp); - LOGGER.info(String.format("Path %s", dp)); + pathlist.add(default_path); tloader = new AutoTraderLoader(pathlist); - } static public final Logger LOGGER = Logger.getLogger("com.cauwersin.sesim"); @@ -169,16 +159,15 @@ public class Globals { JSONObject cfgs = new JSONObject(cfglist); return cfgs; } - - static public final void putStrategies(JSONObject strategies){ + + static public final void putStrategies(JSONObject strategies) { Globals.prefs.put(Globals.PrefKeys.STRATEGIES, strategies.toString()); } - static public final void putTraders (JSONArray traders){ + static public final void putTraders(JSONArray traders) { Globals.prefs.put(Globals.PrefKeys.TRADERS, traders.toString()); } - static public JSONObject getStrategy(String name) { return getStrategies().getJSONObject(name); } @@ -213,9 +202,6 @@ public class Globals { prefs.put(PrefKeys.STRATEGIES, cfgs.toString()); } - - - public static void saveFile(File f) throws FileNotFoundException { JSONObject sobj = new JSONObject(); @@ -233,37 +219,36 @@ public class Globals { out.close(); } - - public static void loadString(String s) throws IOException{ + + public static void loadString(String s) throws IOException { JSONObject sobj = new JSONObject(s); - + Double version = sobj.getDouble(PrefKeys.SESIMVERSION); - if (version > SESIM_FILEVERSION){ + if (version > SESIM_FILEVERSION) { throw new IOException("File has wrong version."); } - + JSONArray traders = sobj.getJSONArray(PrefKeys.TRADERS); JSONObject strategies = sobj.getJSONObject(PrefKeys.STRATEGIES); - + putStrategies(strategies); putTraders(traders); - + } - - public static void clearAll(){ + public static void clearAll() { putStrategies(new JSONObject()); putTraders(new JSONArray()); } - + 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/SeSimApplication.java b/src/gui/SeSimApplication.java index df58e92..d1b3a06 100644 --- a/src/gui/SeSimApplication.java +++ b/src/gui/SeSimApplication.java @@ -93,10 +93,10 @@ public class SeSimApplication extends javax.swing.JFrame { //this.setLocationRelativeTo(null); } - AutoTraderInterface createTraderNew(Exchange se, long id, String name, double money, double shares, JSONObject cfg) { + AutoTraderInterface createTrader(Exchange se, long id, String name, double money, double shares, JSONObject cfg) { String base = cfg.getString("base"); - AutoTraderInterface ac = Globals.tloader.getStrategyBase(base); + AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(base); if (ac == null) { return null; } @@ -122,7 +122,7 @@ public class SeSimApplication extends javax.swing.JFrame { String strategy_name = t.getString("Strategy"); JSONObject strategy = Globals.getStrategy(strategy_name); String base = strategy.getString("base"); - AutoTraderInterface ac = Globals.tloader.getStrategyBase(base); + AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(base); System.out.printf("Load Strat: %s\n", strategy_name); System.out.printf("Base %s\n", base); @@ -140,7 +140,7 @@ public class SeSimApplication extends javax.swing.JFrame { for (int i1 = 0; i1 < count; i1++) { AutoTraderInterface trader; - trader = this.createTraderNew(Globals.se, id, t.getString("Name") + i1, money, shares, strategy); + trader = this.createTrader(Globals.se, id, t.getString("Name") + i1, money, shares, strategy); Globals.se.traders.add(trader); diff --git a/src/gui/StatisticsDialog.form b/src/gui/StatisticsDialog.form deleted file mode 100644 index bfea7a3..0000000 --- a/src/gui/StatisticsDialog.form +++ /dev/null @@ -1,60 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/gui/StatisticsDialog.java b/src/gui/StatisticsDialog.java deleted file mode 100644 index 9ad5a07..0000000 --- a/src/gui/StatisticsDialog.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 StatisticsDialog extends javax.swing.JDialog { - - /** - * Creates new form StatisticsDialog - */ - public StatisticsDialog(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() { - - statisticsPanel1 = new gui.StatisticsPanel(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - javax.swing.GroupLayout statisticsPanel1Layout = new javax.swing.GroupLayout(statisticsPanel1); - statisticsPanel1.setLayout(statisticsPanel1Layout); - statisticsPanel1Layout.setHorizontalGroup( - statisticsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 388, Short.MAX_VALUE) - ); - statisticsPanel1Layout.setVerticalGroup( - statisticsPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 288, Short.MAX_VALUE) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(statisticsPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(statisticsPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addContainerGap()) - ); - - 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(StatisticsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(StatisticsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(StatisticsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(StatisticsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - /* Create and display the dialog */ - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - StatisticsDialog dialog = new StatisticsDialog(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 gui.StatisticsPanel statisticsPanel1; - // End of variables declaration//GEN-END:variables -} diff --git a/src/sesim/AutoTraderLoader.java b/src/sesim/AutoTraderLoader.java index e203a84..5e1c4f4 100644 --- a/src/sesim/AutoTraderLoader.java +++ b/src/sesim/AutoTraderLoader.java @@ -307,37 +307,36 @@ public class AutoTraderLoader { return this.getDefaultStrategyNames(true); } - public AutoTraderInterface getStrategyBase(String name) { + public AutoTraderInterface getAutoTraderInterface(String name) { ArrayList> traders = this.getInstalledTraders(); - - System.out.printf("Installed traders %d\n", traders.size()); - // System.exit(0); - - for (int i = 0; i < traders.size(); i++) { try { - traders.get(i).getCanonicalName(); + if (!name.equals(traders.get(i).getCanonicalName())){ + // System.out.printf("Contnue trader\n"); + continue; + } // System.out.printf("Canon name %s\n", traders.get(i).getCanonicalName()); // System.exit(0); - Globals.LOGGER.info(String.format("Making lll instance of %s", traders.get(i).getCanonicalName())); + // Globals.LOGGER.info(String.format("Making lll instance of %s", traders.get(i).getCanonicalName())); - if (traders.get(i)==null){ - Globals.LOGGER.info("We have null"); - } + // if (traders.get(i)==null){ + // Globals.LOGGER.info("We have null"); + // } // AutoTraderInterface ac = traders.get(i).newInstance(); - AutoTraderInterface ac = this.MakeInstance(traders.get(i)); + AutoTraderInterface ac = MakeInstance(traders.get(i)); - System.out.printf("Looking for in %s == %s\n", ac.getClass().getCanonicalName(), name); + return ac; + // System.out.printf("Looking for in %s == %s\n", ac.getClass().getCanonicalName(), name); - if (ac.getClass().getCanonicalName().equals(name)) { - return ac; + // if (ac.getClass().getCanonicalName().equals(name)) { + // return ac; // if (ac.getDisplayName().equals(name)) { // return ac;} - } + // } } catch (Exception ex) { Globals.LOGGER.info(String.format("Instance failed %s", ex.getMessage())); } diff --git a/src/sesim/Exchange.java b/src/sesim/Exchange.java index 9ebcb2d..2aaab83 100644 --- a/src/sesim/Exchange.java +++ b/src/sesim/Exchange.java @@ -1155,7 +1155,7 @@ public class Exchange { buy_failed++; break; } - System.out.printf("Order ffailed %f %f \n",o.volume,o.limit); + // System.out.printf("Order ffailed %f %f \n",o.volume,o.limit); return -1; diff --git a/src/sesim/Scheduler.java b/src/sesim/Scheduler.java index 394c65a..4602072 100644 --- a/src/sesim/Scheduler.java +++ b/src/sesim/Scheduler.java @@ -294,10 +294,10 @@ public class Scheduler extends Thread { // if (evtime == null) { // return; // } - System.out.printf("Cancel my %d\n", e.id); + SortedSet s = event_queue.get(e.curevtime); if (s == null) { - System.out.printf("My not found\n"); + // System.out.printf("My not found\n"); return; } @@ -391,7 +391,7 @@ public class Scheduler extends Thread { while (!set_tasks.isEmpty()) { TimerTaskDef td = set_tasks.poll(); - System.out.printf("There is a set task %d %d\n",td.curevtime,td.newevtime); + // System.out.printf("There is a set task %d %d\n",td.curevtime,td.newevtime); this.cancelMy(td); this.addTimerTask(td);