Some improvements

This commit is contained in:
7u83 2017-02-02 18:39:55 +01:00
parent 3620fbcb04
commit df6c10ed59
28 changed files with 573 additions and 143 deletions

View File

@ -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);

View File

@ -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);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
@ -62,6 +62,11 @@
<Component class="javax.swing.JTextPane" name="jTextPane1">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="jTextPane1" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" value="/*&#xa; * Copyright (c) 2017, 7u83 &lt;7u83@mail.ru&gt;&#xa; * All rights reserved.&#xa; *&#xa; * Redistribution and use in source and binary forms, with or without&#xa; * modification, are permitted provided that the following conditions are met:&#xa; *&#xa; * * Redistributions of source code must retain the above copyright notice, this&#xa; * list of conditions and the following disclaimer.&#xa; * * Redistributions in binary form must reproduce the above copyright notice,&#xa; * this list of conditions and the following disclaimer in the documentation&#xa; * and/or other materials provided with the distribution.&#xa; *&#xa; * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;&#xa; * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&#xa; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE&#xa; * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE&#xa; * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&#xa; * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&#xa; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&#xa; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&#xa; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&#xa; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&#xa; * POSSIBILITY OF SUCH DAMAGE.&#xa; */"/>
</Properties>
</Component>

View File

@ -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);

View File

@ -16,13 +16,34 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" pref="154" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" pref="42" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font bold="true" component="jLabel1" property="font" relativeSize="true" size="6"/>
</FontInfo>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="00:00:00"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -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 {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="clock1" alignment="1" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="59" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="clock1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="gui.Clock" name="clock1">
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="Ok"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* 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);
}
//</editor-fold>
/* 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
}

View File

@ -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.

View File

@ -24,7 +24,9 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabelSummary" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jOkButton" min="-2" max="-2" attributes="0"/>
@ -44,6 +46,7 @@
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jOkButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabelSummary" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -80,5 +83,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabelSummary">
</Component>
</SubComponents>
</Form>

View File

@ -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
}

View File

@ -39,11 +39,8 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<Component id="jCheckBox2" alignment="0" min="-2" pref="99" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jDevleopmentFeaturesCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
@ -59,11 +56,9 @@
<Component id="lafComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jCheckBox2" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="191" max="32767" attributes="0"/>
<EmptySpace pref="178" max="32767" attributes="0"/>
<Component id="jDevleopmentFeaturesCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="40" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="applyButton" alignment="3" min="-2" max="-2" attributes="0"/>
@ -122,18 +117,12 @@
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel1"/>
<Property name="text" type="java.lang.String" value="Look and Feel:"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="jCheckBox2">
<Component class="javax.swing.JCheckBox" name="jDevleopmentFeaturesCheckBox">
<Properties>
<Property name="text" type="java.lang.String" value="jCheckBox2"/>
<Property name="horizontalTextPosition" type="int" value="10"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel2"/>
<Property name="text" type="java.lang.String" value="Develeopment"/>
</Properties>
</Component>
</SubComponents>

View File

@ -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<String> lafComboBox;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables

View File

@ -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;

View File

@ -110,7 +110,7 @@
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu1">
<Menu class="javax.swing.JMenu" name="viewMenu">
<Properties>
<Property name="text" type="java.lang.String" value="View"/>
</Properties>
@ -131,6 +131,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem3ActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="viewClock">
<Properties>
<Property name="text" type="java.lang.String" value="Clock"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="viewClockActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="helpMenu">
@ -188,12 +196,16 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jToolBar1" pref="798" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" min="-2" pref="233" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" min="-2" pref="233" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<Component id="jToolBar1" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -204,7 +216,7 @@
<Component id="jToolBar1" min="-2" pref="60" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="orderBookPanel1" pref="466" max="32767" attributes="0"/>
<Component id="orderBookPanel1" max="32767" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>

View File

@ -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<tlist.length();i++){
JSONObject t=tlist.getJSONObject(i);
String strategy_name = t.getString("Strategy");
@ -81,15 +86,20 @@ public class NewMDIApplication extends javax.swing.JFrame {
for (int i1=0;i1<count;i1++){
AutoTrader trader = ac.createTrader(Globals.se, strategy, money, shares);
Globals.se.traders.add(trader);
trader.setName(t.getString("Name"));
trader.start();
trader.setName(t.getString("Name")+i1);
moneyTotal+=money;
sharesTotal+=shares;
// trader.start();
}
//AutoTraderConfig ac = Globals.tloader.getStrategyBase(t.getString("base"));
//ac.putConfig(t);
}
Globals.se.fairValue=moneyTotal/sharesTotal;
for (int i=0; i<Globals.se.traders.size(); i++){
Globals.se.traders.get(i).start();
}
// System.exit(0);
@ -146,9 +156,10 @@ public class NewMDIApplication extends javax.swing.JFrame {
deleteMenuItem = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
editPreferences = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
viewMenu = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
viewClock = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
contentMenuItem = new javax.swing.JMenuItem();
aboutMenuItem = new javax.swing.JMenuItem();
@ -283,7 +294,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
menuBar.add(editMenu);
jMenu1.setText("View");
viewMenu.setText("View");
jMenuItem2.setText("Traders");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
@ -291,7 +302,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
viewMenu.add(jMenuItem2);
jMenuItem3.setText("LogWindow");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
@ -299,9 +310,17 @@ public class NewMDIApplication extends javax.swing.JFrame {
jMenuItem3ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem3);
viewMenu.add(jMenuItem3);
menuBar.add(jMenu1);
viewClock.setText("Clock");
viewClock.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
viewClockActionPerformed(evt);
}
});
viewMenu.add(viewClock);
menuBar.add(viewMenu);
helpMenu.setMnemonic('h');
helpMenu.setText("Help");
@ -327,12 +346,14 @@ public class NewMDIApplication extends javax.swing.JFrame {
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1))
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
@ -341,7 +362,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1))
.addContainerGap())
);
@ -415,7 +436,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
FileNameExtensionFilter filter = new FileNameExtensionFilter("SeSim Files","sesim");
fc.setFileFilter(filter);
if (fc.showSaveDialog(this.getParent()) != JFileChooser.APPROVE_OPTION){
if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION){
return;
}
@ -449,6 +472,12 @@ public class NewMDIApplication extends javax.swing.JFrame {
}//GEN-LAST:event_editExchangeMenuItemActionPerformed
private void viewClockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewClockActionPerformed
ClockDialog cd = new ClockDialog(this,true);
cd.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_viewClockActionPerformed
/**
* @param args the command line arguments
* @throws java.lang.IllegalAccessException
@ -484,6 +513,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
}
for (Class<AutoTraderConfig> 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
}

View File

@ -41,7 +41,8 @@ public class NewStrategyDialog extends EscDialog {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(this.getParent());
ArrayList <String> names = Globals.tloader.getDefaultStrategyNames();
boolean devel = Globals.prefs.get(Globals.DEVELSTATUS, "false").equals("true");
ArrayList <String> names = Globals.tloader.getDefaultStrategyNames(devel);
this.jStrategyComboBox.removeAllItems();
names.stream().forEach((s) -> {
this.jStrategyComboBox.addItem(s);

View File

@ -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);
}

View File

@ -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";

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -146,7 +146,7 @@ public class AutoTraderLoader {
}
public ArrayList<String> getDefaultStrategyNames() {
public ArrayList<String> getDefaultStrategyNames(boolean devel) {
ArrayList<Class<AutoTraderConfig>> trclasses;
trclasses = this.getTraders();
ArrayList<String> 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<String> getDefaultStrategyNames() {
return this.getDefaultStrategyNames(true);
}
public AutoTraderConfig getStrategyBase(String name) {
ArrayList<Class<AutoTraderConfig>> traders = this.getTraders();

View File

@ -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<Order> ret = new ArrayList<>();
Iterator<Order> 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();

View File

@ -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<Object> {
@ -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 {

View File

@ -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);

View File

@ -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;
}
}

View File

@ -67,5 +67,10 @@ public class SuperTraderConfig implements AutoTraderConfig{
public void putConfig(JSONObject cfg) {
}
@Override
public boolean getDevelStatus() {
return true;
}
}

View File

@ -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;
}
}