TraderList implemented
This commit is contained in:
parent
ebe3f7e6f4
commit
563e902613
@ -55,6 +55,18 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<Property name="text" type="java.lang.String" value="View"/>
|
<Property name="text" type="java.lang.String" value="View"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
<SubComponents>
|
||||||
|
<MenuItem class="javax.swing.JMenuItem" name="traderList">
|
||||||
|
<Properties>
|
||||||
|
<Property name="mnemonic" type="int" value="116"/>
|
||||||
|
<Property name="text" type="java.lang.String" value="Traders"/>
|
||||||
|
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||||
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="traderListActionPerformed"/>
|
||||||
|
</Events>
|
||||||
|
</MenuItem>
|
||||||
|
</SubComponents>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu class="javax.swing.JMenu" name="helpMenu">
|
<Menu class="javax.swing.JMenu" name="helpMenu">
|
||||||
<Properties>
|
<Properties>
|
||||||
@ -63,6 +75,7 @@
|
|||||||
<SubComponents>
|
<SubComponents>
|
||||||
<MenuItem class="javax.swing.JMenuItem" name="helpAbout">
|
<MenuItem class="javax.swing.JMenuItem" name="helpAbout">
|
||||||
<Properties>
|
<Properties>
|
||||||
|
<Property name="mnemonic" type="int" value="97"/>
|
||||||
<Property name="text" type="java.lang.String" value="About"/>
|
<Property name="text" type="java.lang.String" value="About"/>
|
||||||
<Property name="toolTipText" type="java.lang.String" value="About this Software"/>
|
<Property name="toolTipText" type="java.lang.String" value="About this Software"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
import sesim.AutoTrader;
|
import sesim.AutoTrader;
|
||||||
import sesim.Exchange;
|
import sesim.Exchange;
|
||||||
import traders.*;
|
import traders.*;
|
||||||
@ -106,6 +108,7 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
FileRun = new javax.swing.JMenuItem();
|
FileRun = new javax.swing.JMenuItem();
|
||||||
jMenu2 = new javax.swing.JMenu();
|
jMenu2 = new javax.swing.JMenu();
|
||||||
viewMenu = new javax.swing.JMenu();
|
viewMenu = new javax.swing.JMenu();
|
||||||
|
traderList = new javax.swing.JMenuItem();
|
||||||
helpMenu = new javax.swing.JMenu();
|
helpMenu = new javax.swing.JMenu();
|
||||||
helpAbout = new javax.swing.JMenuItem();
|
helpAbout = new javax.swing.JMenuItem();
|
||||||
|
|
||||||
@ -150,10 +153,22 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
MainMenu.add(jMenu2);
|
MainMenu.add(jMenu2);
|
||||||
|
|
||||||
viewMenu.setText("View");
|
viewMenu.setText("View");
|
||||||
|
|
||||||
|
traderList.setMnemonic('t');
|
||||||
|
traderList.setText("Traders");
|
||||||
|
traderList.setToolTipText("");
|
||||||
|
traderList.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
traderListActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
viewMenu.add(traderList);
|
||||||
|
|
||||||
MainMenu.add(viewMenu);
|
MainMenu.add(viewMenu);
|
||||||
|
|
||||||
helpMenu.setText("Help");
|
helpMenu.setText("Help");
|
||||||
|
|
||||||
|
helpAbout.setMnemonic('a');
|
||||||
helpAbout.setText("About");
|
helpAbout.setText("About");
|
||||||
helpAbout.setToolTipText("About this Software");
|
helpAbout.setToolTipText("About this Software");
|
||||||
helpAbout.addActionListener(new java.awt.event.ActionListener() {
|
helpAbout.addActionListener(new java.awt.event.ActionListener() {
|
||||||
@ -188,6 +203,11 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
d.show();
|
d.show();
|
||||||
}//GEN-LAST:event_helpAboutActionPerformed
|
}//GEN-LAST:event_helpAboutActionPerformed
|
||||||
|
|
||||||
|
private void traderListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_traderListActionPerformed
|
||||||
|
TraderListDialog tl = new TraderListDialog(this,false);
|
||||||
|
tl.setVisible(true);
|
||||||
|
}//GEN-LAST:event_traderListActionPerformed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
@ -204,10 +224,12 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
|
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
|
||||||
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
|
// SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
|
||||||
RandomTraderConfig rcfg1 = new RandomTraderConfig();
|
RandomTraderConfig rcfg1 = new RandomTraderConfig();
|
||||||
AutoTrader rt1 = rcfg1.createTrader(se, 0, 1000000);
|
AutoTrader rt1 = rcfg1.createTrader(se, 1000, 1000);
|
||||||
|
se.traders.add(rt1);
|
||||||
rt1.setName("Bob");
|
rt1.setName("Bob");
|
||||||
rt1.start();
|
rt1.start();
|
||||||
|
|
||||||
|
|
||||||
//AutoTrader rt2 = rcfg1.createTrader(se, 1, 100);
|
//AutoTrader rt2 = rcfg1.createTrader(se, 1, 100);
|
||||||
//rt2.start();
|
//rt2.start();
|
||||||
|
|
||||||
@ -215,9 +237,10 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
// SwitchingTraderConfig cfg = new SwitchingTraderConfig();
|
// SwitchingTraderConfig cfg = new SwitchingTraderConfig();
|
||||||
RandomTraderConfig cfg= new RandomTraderConfig();
|
RandomTraderConfig cfg= new RandomTraderConfig();
|
||||||
|
|
||||||
for (int i=0; i<1; i++){
|
for (int i=0; i<530; i++){
|
||||||
AutoTrader randt = cfg.createTrader(se, 100000, 0);
|
AutoTrader randt = cfg.createTrader(se, 100, 100);
|
||||||
|
|
||||||
|
se.traders.add(randt);
|
||||||
randt.setName("Alice");
|
randt.setName("Alice");
|
||||||
randt.start();
|
randt.start();
|
||||||
}
|
}
|
||||||
@ -230,13 +253,13 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
// at.add(10, rcfg, se, 1000000, 0);
|
// at.add(10, rcfg, se, 1000000, 0);
|
||||||
|
|
||||||
|
|
||||||
/* try {
|
/* try {
|
||||||
// Set cross-platform Java L&F (also called "Metal")
|
// Set cross-platform Java L&F (also called "Metal")
|
||||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
|
||||||
} catch (UnsupportedLookAndFeelException | ClassNotFoundException |
|
} catch (UnsupportedLookAndFeelException | ClassNotFoundException |
|
||||||
InstantiationException | IllegalAccessException e) {
|
InstantiationException | IllegalAccessException e) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/* Set the Nimbus look and feel */
|
/* Set the Nimbus look and feel */
|
||||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
//<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.
|
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||||
@ -280,6 +303,7 @@ public class MainWin extends javax.swing.JFrame {
|
|||||||
private javax.swing.JMenu jMenu2;
|
private javax.swing.JMenu jMenu2;
|
||||||
private javax.swing.JMenuItem jMenuItem1;
|
private javax.swing.JMenuItem jMenuItem1;
|
||||||
private gui.OrderBookPanel orderBookPanel1;
|
private gui.OrderBookPanel orderBookPanel1;
|
||||||
|
private javax.swing.JMenuItem traderList;
|
||||||
private javax.swing.JMenu viewMenu;
|
private javax.swing.JMenu viewMenu;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
@ -106,14 +106,14 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
|
|||||||
list = getOrderBook();
|
list = getOrderBook();
|
||||||
}
|
}
|
||||||
|
|
||||||
int update_calls = 0;
|
// int update_calls = 0;
|
||||||
int colcount_calls = 0;
|
int colcount_calls = 0;
|
||||||
|
|
||||||
public void update(ArrayList newlist) {
|
public void update(ArrayList newlist) {
|
||||||
list = newlist; //getOrderBook();
|
list = newlist; //getOrderBook();
|
||||||
this.fireTableDataChanged();
|
this.fireTableDataChanged();
|
||||||
|
|
||||||
this.update_calls++;
|
// this.update_calls++;
|
||||||
// int hc = this.hashCode();
|
// int hc = this.hashCode();
|
||||||
//System.out.print("Update/ColCalls = " + update_calls + "/" + colcount_calls + " HC: " + hc + "\n");
|
//System.out.print("Update/ColCalls = " + update_calls + "/" + colcount_calls + " HC: " + hc + "\n");
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
|
|||||||
} else {
|
} else {
|
||||||
o = list.get(list.size() - r - 1);
|
o = list.get(list.size() - r - 1);
|
||||||
}
|
}
|
||||||
Formatter f = new Formatter();
|
// Formatter f = new Formatter();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0:
|
case 0:
|
||||||
return String.format("#%06x", o.getID());
|
return String.format("#%06x", o.getID());
|
||||||
|
47
src/main/java/gui/TraderListDialog.form
Normal file
47
src/main/java/gui/TraderListDialog.form
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?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">
|
||||||
|
<Group type="102" alignment="1" attributes="0">
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="traderListPanel1" max="32767" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
<DimensionLayout dim="1">
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Group type="102" alignment="1" attributes="0">
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Component id="traderListPanel1" pref="294" max="32767" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
</Layout>
|
||||||
|
<SubComponents>
|
||||||
|
<Component class="gui.TraderListPanel" name="traderListPanel1">
|
||||||
|
</Component>
|
||||||
|
</SubComponents>
|
||||||
|
</Form>
|
124
src/main/java/gui/TraderListDialog.java
Normal file
124
src/main/java/gui/TraderListDialog.java
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
package gui;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author 7u83 <7u83@mail.ru>
|
||||||
|
*/
|
||||||
|
public class TraderListDialog extends javax.swing.JDialog {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new form TraderList
|
||||||
|
* @param parent
|
||||||
|
* @param modal
|
||||||
|
*/
|
||||||
|
public TraderListDialog(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() {
|
||||||
|
|
||||||
|
traderListPanel1 = new gui.TraderListPanel();
|
||||||
|
|
||||||
|
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
|
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(traderListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
|
.addContainerGap())
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addComponent(traderListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
|
||||||
|
.addContainerGap())
|
||||||
|
);
|
||||||
|
|
||||||
|
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(TraderListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (InstantiationException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(TraderListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (IllegalAccessException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(TraderListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(TraderListDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
|
/* Create and display the dialog */
|
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
TraderListDialog dialog = new TraderListDialog(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.TraderListPanel traderListPanel1;
|
||||||
|
// End of variables declaration//GEN-END:variables
|
||||||
|
}
|
51
src/main/java/gui/TraderListPanel.form
Normal file
51
src/main/java/gui/TraderListPanel.form
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||||
|
<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="traderListScroller" alignment="1" pref="400" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
<DimensionLayout dim="1">
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="traderListScroller" alignment="0" pref="300" max="32767" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</DimensionLayout>
|
||||||
|
</Layout>
|
||||||
|
<SubComponents>
|
||||||
|
<Container class="javax.swing.JScrollPane" name="traderListScroller">
|
||||||
|
<AuxValues>
|
||||||
|
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||||
|
</AuxValues>
|
||||||
|
|
||||||
|
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||||
|
<SubComponents>
|
||||||
|
<Component class="javax.swing.JTable" name="traderList">
|
||||||
|
<Properties>
|
||||||
|
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
|
||||||
|
<Table columnCount="4" rowCount="4">
|
||||||
|
<Column editable="true" title="Title 1" type="java.lang.Object"/>
|
||||||
|
<Column editable="true" title="Title 2" type="java.lang.Object"/>
|
||||||
|
<Column editable="true" title="Title 3" type="java.lang.Object"/>
|
||||||
|
<Column editable="true" title="Title 4" type="java.lang.Object"/>
|
||||||
|
</Table>
|
||||||
|
</Property>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
</SubComponents>
|
||||||
|
</Container>
|
||||||
|
</SubComponents>
|
||||||
|
</Form>
|
255
src/main/java/gui/TraderListPanel.java
Normal file
255
src/main/java/gui/TraderListPanel.java
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Formatter;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.ListModel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import javax.swing.table.JTableHeader;
|
||||||
|
import sesim.AutoTrader;
|
||||||
|
import sesim.Exchange;
|
||||||
|
import sesim.Scheduler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author 7u83 <7u83@mail.ru>
|
||||||
|
*/
|
||||||
|
public class TraderListPanel extends javax.swing.JPanel
|
||||||
|
implements Scheduler.TimerTask {
|
||||||
|
|
||||||
|
Exchange se;
|
||||||
|
TraderListModel model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new form TraderListPanel
|
||||||
|
*/
|
||||||
|
public TraderListPanel() {
|
||||||
|
initComponents();
|
||||||
|
|
||||||
|
this.setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
// this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
|
||||||
|
|
||||||
|
if (MainWin.se == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.model = new TraderListModel();
|
||||||
|
this.traderList.setModel(this.model);
|
||||||
|
|
||||||
|
traderList.setBorder(BorderFactory.createEmptyBorder());
|
||||||
|
|
||||||
|
JTableHeader h = this.traderList.getTableHeader();
|
||||||
|
// h.setBackground(Color.BLUE);
|
||||||
|
// h.setForeground(Color.green);
|
||||||
|
|
||||||
|
if (MainWin.se != null) {
|
||||||
|
this.se = MainWin.se;
|
||||||
|
this.list = this.getTraderList();
|
||||||
|
se.timer.startTimerEvent(this, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList<TraderListItem> getTraderList() {
|
||||||
|
|
||||||
|
sesim.Quote q = se.getLastQuoete();
|
||||||
|
double price = q == null ? 0 : q.price;
|
||||||
|
Iterator<AutoTrader> it = se.traders.iterator();
|
||||||
|
ArrayList<TraderListItem> tlist = new ArrayList<>();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
AutoTrader at = it.next();
|
||||||
|
Exchange.Account a = at.getAccount();
|
||||||
|
|
||||||
|
TraderListItem ti = new TraderListItem();
|
||||||
|
ti.name = at.getName();
|
||||||
|
ti.shares = a.getShares();
|
||||||
|
ti.money = a.getMoney();
|
||||||
|
ti.welth = price==0 ? 0 : ti.shares * price + ti.money;
|
||||||
|
tlist.add(ti);
|
||||||
|
|
||||||
|
}
|
||||||
|
return tlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long timerTask() {
|
||||||
|
class Updater implements Runnable {
|
||||||
|
|
||||||
|
TraderListModel model;
|
||||||
|
ArrayList<TraderListItem> newlist;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.print("TTrunner\n");
|
||||||
|
model.update(this.newlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
Updater(TraderListModel model, ArrayList newlist) {
|
||||||
|
this.model = model;
|
||||||
|
this.newlist = newlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("TimerTaskUpdater\n");
|
||||||
|
|
||||||
|
ArrayList <TraderListItem> newlist = getTraderList();
|
||||||
|
SwingUtilities.invokeLater(new Updater(this.model, newlist));
|
||||||
|
|
||||||
|
return 2000;
|
||||||
|
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
class TraderListItem {
|
||||||
|
|
||||||
|
public String name;
|
||||||
|
public double shares;
|
||||||
|
public double money;
|
||||||
|
public double welth;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<TraderListItem> list = new ArrayList<>();
|
||||||
|
|
||||||
|
protected class TraderListModel extends AbstractTableModel {
|
||||||
|
|
||||||
|
//private final boolean desc = false;
|
||||||
|
public TraderListModel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(ArrayList newlist) {
|
||||||
|
|
||||||
|
|
||||||
|
list = newlist; //getOrderBook();
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int c) {
|
||||||
|
switch (c) {
|
||||||
|
case 0:
|
||||||
|
return "ID";
|
||||||
|
case 1:
|
||||||
|
return "Name";
|
||||||
|
case 2:
|
||||||
|
return "Money";
|
||||||
|
case 3:
|
||||||
|
return "Shares";
|
||||||
|
case 4:
|
||||||
|
return "Welth";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
int rc = list.size();
|
||||||
|
//System.out.print("Size" + rc + "\n");
|
||||||
|
return list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int r, int c) {
|
||||||
|
TraderListItem ti;
|
||||||
|
ti = list.get(r);
|
||||||
|
|
||||||
|
int s = list.size();
|
||||||
|
Formatter f = new Formatter();
|
||||||
|
switch (c) {
|
||||||
|
case 0:
|
||||||
|
return String.format("#%06x", 0);
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
return String.format("%s", ti.name);
|
||||||
|
case 2:
|
||||||
|
return String.format("%.2f", ti.money);
|
||||||
|
case 3:
|
||||||
|
return String.format("%.2f", ti.shares);
|
||||||
|
case 4:
|
||||||
|
return String.format("%.2f", ti.welth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "x";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() {
|
||||||
|
|
||||||
|
traderListScroller = new javax.swing.JScrollPane();
|
||||||
|
traderList = new javax.swing.JTable();
|
||||||
|
|
||||||
|
traderList.setModel(new javax.swing.table.DefaultTableModel(
|
||||||
|
new Object [][] {
|
||||||
|
{null, null, null, null},
|
||||||
|
{null, null, null, null},
|
||||||
|
{null, null, null, null},
|
||||||
|
{null, null, null, null}
|
||||||
|
},
|
||||||
|
new String [] {
|
||||||
|
"Title 1", "Title 2", "Title 3", "Title 4"
|
||||||
|
}
|
||||||
|
));
|
||||||
|
traderListScroller.setViewportView(traderList);
|
||||||
|
|
||||||
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||||
|
this.setLayout(layout);
|
||||||
|
layout.setHorizontalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(traderListScroller, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
|
||||||
|
);
|
||||||
|
layout.setVerticalGroup(
|
||||||
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(traderListScroller, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
|
||||||
|
);
|
||||||
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
|
|
||||||
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
private javax.swing.JTable traderList;
|
||||||
|
private javax.swing.JScrollPane traderListScroller;
|
||||||
|
// End of variables declaration//GEN-END:variables
|
||||||
|
}
|
@ -53,6 +53,10 @@ public abstract class AutoTrader implements Scheduler.TimerTask {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Exchange.Account getAccount(){
|
||||||
|
return se.getAccount(account_id);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void start();
|
public abstract void start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ public class Exchange { //extends Thread {
|
|||||||
//public static Timer timer = new Timer();
|
//public static Timer timer = new Timer();
|
||||||
|
|
||||||
public Scheduler timer = new Scheduler();
|
public Scheduler timer = new Scheduler();
|
||||||
|
//public AutoTraderList traders = new AutoTraderList();
|
||||||
|
public ArrayList <AutoTrader> traders = new ArrayList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -353,7 +355,7 @@ public class Exchange { //extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Quote getLastQuoete() {
|
public Quote getLastQuoete() {
|
||||||
return this.quoteHistory.first();
|
return this.quoteHistory.last();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, tobias
|
* Copyright (c) 2017, 7u83
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -38,16 +38,15 @@ import sesim.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author tobias
|
* @author 7u83
|
||||||
*/
|
*/
|
||||||
public class RandomTrader extends AutoTrader {
|
public class RandomTrader extends AutoTrader {
|
||||||
|
|
||||||
|
|
||||||
long event() {
|
long event() {
|
||||||
|
|
||||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||||
long rc = this.doTrade();
|
long rc = this.doTrade();
|
||||||
return rc/3;
|
return rc / 3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +58,15 @@ public class RandomTrader extends AutoTrader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long timerTask() {
|
public long timerTask() {
|
||||||
sesim.Exchange.Account a = se.getAccount(account_id);
|
sesim.Exchange.Account a = se.getAccount(account_id);
|
||||||
long rc = this.doTrade();
|
long rc = this.doTrade();
|
||||||
return rc/33;
|
return rc / 33;
|
||||||
|
|
||||||
// return this.event();
|
// return this.event();
|
||||||
}
|
}
|
||||||
@ -81,7 +84,7 @@ public class RandomTrader extends AutoTrader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double start = 0.1;
|
double start = 1.1;
|
||||||
//Timer timer = new Timer();
|
//Timer timer = new Timer();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -152,7 +155,7 @@ public class RandomTrader extends AutoTrader {
|
|||||||
OrderType type = OrderType.BID;
|
OrderType type = OrderType.BID;
|
||||||
|
|
||||||
if (ad == null || myconfig == null) {
|
if (ad == null || myconfig == null) {
|
||||||
System.out.print(ad + "\n");
|
// System.out.print(ad + "\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -194,7 +197,7 @@ public class RandomTrader extends AutoTrader {
|
|||||||
|
|
||||||
// long volume = (long) (money / (limit * 1));
|
// long volume = (long) (money / (limit * 1));
|
||||||
if (volume <= 0) {
|
if (volume <= 0) {
|
||||||
System.out.print("SellVolume 0\n");
|
// System.out.print("SellVolume 0\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,6 +246,5 @@ public class RandomTrader extends AutoTrader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,12 @@ import sesim.Exchange;
|
|||||||
public class RandomTraderConfig extends AutoTraderConfig {
|
public class RandomTraderConfig extends AutoTraderConfig {
|
||||||
|
|
||||||
public float[] sell_volume = {100, 100};
|
public float[] sell_volume = {100, 100};
|
||||||
public float[] sell_limit = {-10f, 10f};
|
public float[] sell_limit = {-1f, 1f};
|
||||||
public int[] sell_order_wait = {1000, 5000};
|
public int[] sell_order_wait = {1000, 5000};
|
||||||
public int[] wait_after_sell = {10, 30};
|
public int[] wait_after_sell = {10, 30};
|
||||||
|
|
||||||
public float[] buy_volume = {100, 100};
|
public float[] buy_volume = {100, 100};
|
||||||
public float[] buy_limit = {-10, 10f};
|
public float[] buy_limit = {-1, 1f};
|
||||||
public int[] buy_order_wait = {1000, 5000};
|
public int[] buy_order_wait = {1000, 5000};
|
||||||
public int[] wait_after_buy = {10, 30};
|
public int[] wait_after_buy = {10, 30};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user