Work on manual trading

This commit is contained in:
7u83 2017-02-13 00:07:50 +01:00
parent 4090947001
commit 6039c95d6a
34 changed files with 699 additions and 316 deletions

View File

@ -38,6 +38,11 @@
<artifactId>keytool-api-1.7</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jdesktop</groupId>
<artifactId>beansbinding</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -33,7 +33,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<Component id="okButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
@ -44,8 +44,8 @@
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSpinner2" alignment="1" min="-2" pref="70" max="-2" attributes="0"/>
<Component id="jSpinner1" alignment="1" min="-2" pref="70" max="-2" attributes="0"/>
<Component id="moneyDecimalsSpinner" alignment="1" min="-2" pref="70" max="-2" attributes="0"/>
<Component id="sharesDecimalsSpinner" alignment="1" min="-2" pref="70" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
@ -58,18 +58,18 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jSpinner1" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
<Component id="sharesDecimalsSpinner" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jSpinner2" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
<Component id="moneyDecimalsSpinner" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="32" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="okButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -77,7 +77,7 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JSpinner" name="jSpinner1">
<Component class="javax.swing.JSpinner" name="sharesDecimalsSpinner">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" maximum="10" minimum="0" numberType="java.lang.Integer" stepSize="1" type="number"/>
@ -89,7 +89,7 @@
<Property name="text" type="java.lang.String" value="Number of decimals for shares:"/>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="jSpinner2">
<Component class="javax.swing.JSpinner" name="moneyDecimalsSpinner">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="2" maximum="10" minimum="0" numberType="java.lang.Integer" stepSize="1" type="number"/>
@ -106,14 +106,17 @@
<Property name="mnemonic" type="int" value="99"/>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton2">
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="mnemonic" type="int" value="111"/>
<Property name="text" type="java.lang.String" value="Ok"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>

View File

@ -25,6 +25,8 @@
*/
package gui;
import org.json.JSONObject;
/**
*
* @author 7u83 <7u83@mail.ru>
@ -38,9 +40,12 @@ public class EditExchangeDialog extends javax.swing.JDialog {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(parent);
JSONObject jo = new JSONObject(Globals.prefs.get("Exchange", "{}"));
this.moneyDecimalsSpinner.setValue(jo.getInt(Globals.se.CFG_MONEY_DECIMALS));
this.sharesDecimalsSpinner.setValue(jo.getInt(Globals.se.CFG_SHARES_DECIMALS));
}
int showdialog(){
int showdialog() {
this.setVisible(true);
return 3;
}
@ -54,34 +59,39 @@ public class EditExchangeDialog extends javax.swing.JDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSpinner1 = new javax.swing.JSpinner();
sharesDecimalsSpinner = new javax.swing.JSpinner();
jLabel1 = new javax.swing.JLabel();
jSpinner2 = new javax.swing.JSpinner();
moneyDecimalsSpinner = new javax.swing.JSpinner();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
okButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("SeSim ExchangeSettings");
setMinimumSize(new java.awt.Dimension(300, 142));
setModal(true);
jSpinner1.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10, 1));
sharesDecimalsSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 10, 1));
jLabel1.setText("Number of decimals for shares:");
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(2, 0, 10, 1));
moneyDecimalsSpinner.setModel(new javax.swing.SpinnerNumberModel(2, 0, 10, 1));
jLabel2.setText("Number of decimals for money:");
jButton1.setMnemonic('c');
jButton1.setText("Cancel");
jButton2.setMnemonic('o');
jButton2.setText("Ok");
jButton2.addActionListener(new java.awt.event.ActionListener() {
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
jButton1ActionPerformed(evt);
}
});
okButton.setMnemonic('o');
okButton.setText("Ok");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
@ -94,7 +104,7 @@ public class EditExchangeDialog extends javax.swing.JDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2)
.addComponent(okButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
@ -103,8 +113,8 @@ public class EditExchangeDialog extends javax.swing.JDialog {
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSpinner2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addComponent(moneyDecimalsSpinner, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sharesDecimalsSpinner, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
layout.setVerticalGroup(
@ -112,25 +122,34 @@ public class EditExchangeDialog extends javax.swing.JDialog {
.addGroup(layout.createSequentialGroup()
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sharesDecimalsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(moneyDecimalsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addComponent(okButton))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// Globals.prefs.put("money_decimals", value);
}//GEN-LAST:event_jButton2ActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
JSONObject jo = new JSONObject();
jo.put(Globals.se.CFG_MONEY_DECIMALS, (Integer) this.moneyDecimalsSpinner.getValue());
jo.put(Globals.se.CFG_SHARES_DECIMALS, (Integer) this.sharesDecimalsSpinner.getValue());
System.out.printf("EC: %s\n", jo.toString(3));
Globals.prefs.put("Exchange", jo.toString());
dispose();
}//GEN-LAST:event_okButtonActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
@ -177,10 +196,10 @@ public class EditExchangeDialog extends javax.swing.JDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JSpinner jSpinner2;
private javax.swing.JSpinner moneyDecimalsSpinner;
private javax.swing.JButton okButton;
private javax.swing.JSpinner sharesDecimalsSpinner;
// End of variables declaration//GEN-END:variables
}

View File

@ -35,7 +35,7 @@ import java.util.logging.Logger;
import javax.swing.JPanel;
import org.json.JSONArray;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
import sesim.AutoTraderInterface;

View File

@ -27,7 +27,7 @@ package gui;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import sesim.AutoTrader;
import sesim.Exchange;
import traders.*;

View File

@ -243,16 +243,12 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel2" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="orderBookPanel" min="-2" pref="233" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jChartScrollPane" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="orderBookPanel" min="-2" pref="233" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jChartScrollPane" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">

View File

@ -39,7 +39,7 @@ import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.json.JSONArray;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderConfig;
import sesim.AutoTraderInterface;
import sesim.Exchange;
@ -73,8 +73,8 @@ public class NewMDIApplication extends javax.swing.JFrame {
public void startTraders() {
Globals.se.setMoneyDecimals(8);
Globals.se.setSharesDecimals(0);
// Globals.se.setMoneyDecimals(8);
// Globals.se.setSharesDecimals(0);
JSONArray tlist = Globals.getTraders();
@ -458,13 +458,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(orderBookPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jChartScrollPane)))
.addComponent(orderBookPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jChartScrollPane)
.addContainerGap())
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -496,8 +494,13 @@ public class NewMDIApplication extends javax.swing.JFrame {
}
void startSim() {
resetSim();
JSONObject jo = new JSONObject(Globals.prefs.get("Exchange", "{}"));
Globals.se.putConfig(jo);
this.stopButton.setEnabled(true);
this.orderBookPanel.invalidate();

View File

@ -38,12 +38,14 @@
<SubComponents>
<Component class="javax.swing.JTable" name="order_table">
<Properties>
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="4" rowCount="4">
<Column editable="true" title="ID" type="java.lang.Long"/>
<Column editable="true" title="Type" type="java.lang.String"/>
<Column editable="true" title="Price" type="java.lang.Double"/>
<Column editable="true" title="Volume" type="java.lang.Double"/>
<Table columnCount="5" rowCount="4">
<Column editable="false" title="ID" type="java.lang.Long"/>
<Column editable="false" title="Type" type="java.lang.String"/>
<Column editable="false" title="Limit" type="java.lang.Double"/>
<Column editable="false" title="Volume" type="java.lang.Double"/>
<Column editable="false" title="Status" type="java.lang.String"/>
</Table>
</Property>
</Properties>

View File

@ -25,9 +25,13 @@
*/
package gui;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import javax.swing.table.DefaultTableModel;
import sesim.Exchange.Account;
import sesim.Exchange.Order;
/**
*
@ -37,24 +41,33 @@ public class OrdersList extends javax.swing.JPanel {
public Account account;
DefaultTableModel model;
public final void updateModel(){
if (null==account)
return;
account.getOrders().forEach(new BiConsumer() {
@Override
public void accept(Object k, Object u) {
System.out.printf("Key: %d\n", (Long)k);
}
});
public final void updateModel() {
if (null == account) {
return;
}
int row = 0;
Iterator<Map.Entry<Long, Order>> it = account.getOrders().entrySet().iterator();
model.setRowCount(account.getOrders().size());
while (it.hasNext()) {
Map.Entry e = it.next();
Long k = (Long) e.getKey();
Order o = (Order) e.getValue();
model.setValueAt(k, row, 0);
model.setValueAt(((Order) o).getType().toString(), row, 1);
model.setValueAt(((Order) o).getLimit(), row, 2);
model.setValueAt(((Order) o).getVolume(), row, 3);
model.setValueAt(((Order) o).getOrderStatus().toString(), row, 4);
row++;
}
this.order_table.getRowSorter().allRowsChanged();
}
/**
* Creates new form OrdersList
*/
@ -76,24 +89,32 @@ public class OrdersList extends javax.swing.JPanel {
jScrollPane1 = new javax.swing.JScrollPane();
order_table = new javax.swing.JTable();
order_table.setAutoCreateRowSorter(true);
order_table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"ID", "Type", "Price", "Volume"
"ID", "Type", "Limit", "Volume", "Status"
}
) {
Class[] types = new Class [] {
java.lang.Long.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class
java.lang.Long.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane1.setViewportView(order_table);

View File

@ -0,0 +1,28 @@
<?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">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View File

@ -0,0 +1,65 @@
/*
* 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 TestPanel extends TraderListPanel {
/**
* Creates new form TestPanel
*/
public TestPanel() {
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() {
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)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@ -3,6 +3,7 @@
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="Trader List"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@ -23,25 +24,17 @@
<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>
<Component id="traderListPanel22" alignment="1" pref="574" max="32767" attributes="0"/>
</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>
<Component id="traderListPanel22" alignment="0" pref="312" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="gui.TraderListPanel" name="traderListPanel1">
<Component class="gui.TraderListPanel2" name="traderListPanel22">
</Component>
</SubComponents>
</Form>

View File

@ -52,25 +52,20 @@ public class TraderListDialog extends javax.swing.JDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
traderListPanel1 = new gui.TraderListPanel();
traderListPanel22 = new gui.TraderListPanel2();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Trader List");
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())
.addComponent(traderListPanel22, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 574, Short.MAX_VALUE)
);
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())
.addComponent(traderListPanel22, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
);
pack();
@ -120,6 +115,6 @@ public class TraderListDialog extends javax.swing.JDialog {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private gui.TraderListPanel traderListPanel1;
private gui.TraderListPanel2 traderListPanel22;
// End of variables declaration//GEN-END:variables
}

View File

@ -45,6 +45,9 @@
</Table>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="traderListMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>

View File

@ -36,7 +36,7 @@ import javax.swing.ListModel;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;
import sesim.AutoTrader;
import sesim.AutoTraderInterface;
import sesim.Exchange;
import sesim.Scheduler;
@ -247,6 +247,11 @@ public class TraderListPanel extends javax.swing.JPanel {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
traderList.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
traderListMouseClicked(evt);
}
});
traderListScroller.setViewportView(traderList);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
@ -261,6 +266,10 @@ public class TraderListPanel extends javax.swing.JPanel {
);
}// </editor-fold>//GEN-END:initComponents
private void traderListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_traderListMouseClicked
}//GEN-LAST:event_traderListMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable traderList;

View File

@ -0,0 +1,56 @@
<?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="jScrollPane1" alignment="1" pref="537" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<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="list">
<Properties>
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="5" rowCount="5">
<Column editable="false" title="ID" type="java.lang.Long"/>
<Column editable="false" title="Name" type="java.lang.String"/>
<Column editable="false" title="Money" type="java.lang.Double"/>
<Column editable="false" title="Shares" type="java.lang.Double"/>
<Column editable="false" title="Wealth" type="java.lang.Double"/>
</Table>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -0,0 +1,181 @@
/*
* 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.util.ArrayList;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import sesim.AutoTraderInterface;
import sesim.Exchange;
import sesim.Exchange.Account;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class TraderListPanel2 extends javax.swing.JPanel {
DefaultTableModel model;
final void updateModel() {
if (Globals.se == null) {
return;
}
if (Globals.se.traders == null) {
return;
}
sesim.Quote q = Globals.se.getLastQuoete();
double price = q == null ? 0 : q.price;
int size = Globals.se.traders.size();
model.setRowCount(size);
for (int i = 0; i < size; i++) {
AutoTraderInterface at = Globals.se.traders.get(i);
Account a = at.getAccount();
model.setValueAt(i, i, 0);
model.setValueAt(at.getName(), i, 1);
model.setValueAt(a.getMoney(), i, 2);
model.setValueAt(a.getShares(), i, 3);
double wealth = a.getShares() * price + a.getMoney();
model.setValueAt(wealth, i, 4);
}
list.getRowSorter().allRowsChanged();
}
TimerTask updater;
/**
* Creates new form TraderListPanel2
*/
public TraderListPanel2() {
initComponents();
model = (DefaultTableModel) list.getModel();
updateModel();
Timer timer = new Timer();
updater = new TimerTask() {
@Override
public void run() {
updateModel();
}
};
timer.schedule(updater, 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
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
list = new javax.swing.JTable();
list.setAutoCreateRowSorter(true);
list.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"ID", "Name", "Money", "Shares", "Wealth"
}
) {
Class[] types = new Class [] {
java.lang.Long.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
list.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
listMouseClicked(evt);
}
});
jScrollPane1.setViewportView(list);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
if (evt.getClickCount() == 2) {
int index = list.rowAtPoint(evt.getPoint());
index = list.getRowSorter().convertRowIndexToModel(index);
Integer tid = (Integer)model.getValueAt(index, 0);
System.out.printf("Trader ID %d\n", tid);
JDialog console = Globals.se.traders.get(tid).getGuiConsole();
if (console == null)
return;
console.setVisible(true);
}
}//GEN-LAST:event_listMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable list;
// End of variables declaration//GEN-END:variables
}

View File

@ -32,9 +32,9 @@ import sesim.Scheduler.TimerTask;
*
* @author 7u83 <7u83@mail.ru>
*/
public abstract class AutoTraderBase implements AutoTraderInterface, TimerTask{
public abstract class AutoTraderBase implements AutoTraderInterface, TimerTask {
protected double account_id;
protected double account_id;
protected Exchange se;
protected AutoTraderConfig config;
@ -43,19 +43,18 @@ public abstract class AutoTraderBase implements AutoTraderInterface, TimerTask{
public AutoTraderBase(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) {
account_id = se.createAccount(money, shares);
Exchange.Account a = se.getAccount(account_id);
// a.owner=this;
// a.owner=this;
this.se = se;
this.config = config;
this.name = name;
this.id=id;
this.id = id;
}
public AutoTraderBase(){
se=null;
id=0;
public AutoTraderBase() {
se = null;
id = 0;
}
public void setName(String name) {
@ -65,35 +64,30 @@ public abstract class AutoTraderBase implements AutoTraderInterface, TimerTask{
public String getName() {
return name;
}
// @Override
public long getID(){
// @Override
public long getID() {
return id;
}
private long id;
public Exchange.Account getAccount(){
public Exchange.Account getAccount() {
return se.getAccount(account_id);
}
public void init(Exchange se,long id,String name, double money, double shares, JSONObject cfg){
this.account_id=se.createAccount(money, shares);
se.getAccount(account_id).owner=this;
this.se = se;
public void init(Exchange se, long id, String name, double money, double shares, JSONObject cfg) {
this.account_id = se.createAccount(money, shares);
se.getAccount(account_id).owner = this;
this.se = se;
this.name = name;
this.id=id;
this.id = id;
}
public Exchange getSE(){
public Exchange getSE() {
return se;
}
public abstract void start();
}

View File

@ -34,7 +34,7 @@ import org.json.JSONObject;
*/
public abstract interface AutoTraderConfig {
public abstract AutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares);
public abstract OldAutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares);
public abstract String getDisplayName();

View File

@ -25,6 +25,7 @@
*/
package sesim;
import javax.swing.JDialog;
import org.json.JSONObject;
/**
@ -39,13 +40,15 @@ public interface AutoTraderInterface {
public abstract AutoTraderGui getGui();
public abstract JDialog getGuiConsole();
public abstract JSONObject getConfig();
public abstract void putConfig(JSONObject cfg);
public abstract String getName();
public void init(Exchange se,long id,String name, double money, double shares, JSONObject cfg);
public void init(Exchange se, long id, String name, double money, double shares, JSONObject cfg);
public Exchange.Account getAccount();

View File

@ -35,7 +35,7 @@ import java.util.ArrayList;
*/
public class AutoTraderList {
SortedSet <AutoTrader> traders;
SortedSet <OldAutoTrader> traders;
AutoTraderList(){

View File

@ -60,11 +60,21 @@ public class Exchange {
public ArrayList<AutoTraderInterface> traders;
/**
*
*/
public interface AccountListener {
public void accountUpdated(Account a, Order o);
}
/**
* Implements a trading account
*/
public class Account implements Comparable {
private AccountListener listener = null;
private final double id;
private double shares;
private double money;
@ -101,10 +111,21 @@ public class Exchange {
return owner;
}
public HashMap<Long,Order> getOrders() {
public HashMap<Long, Order> getOrders() {
return orders;
}
public void setListener(AccountListener al) {
this.listener = al;
}
public void update(Order o) {
if (listener == null) {
return;
}
listener.accountUpdated(this, o);
}
}
public void createTraders(JSONArray traderdefs) {
@ -128,6 +149,13 @@ public class Exchange {
return a.id;
}
public enum OrderStatus {
OPEN,
PARTIALLY_EXECUTED,
CLOSED,
CANCELED
}
class OrderComparator implements Comparator<Order> {
OrderType type;
@ -141,12 +169,12 @@ public class Exchange {
double d;
switch (this.type) {
case BUYLIMIT:
case STOPBUY:
case BUY:
case STOPBUY:
case BUY:
d = right.limit - left.limit;
break;
case SELLLIMIT:
case STOPLOSS:
case STOPLOSS:
case SELL:
d = left.limit - right.limit;
break;
@ -182,6 +210,7 @@ public class Exchange {
public class Order {
OrderStatus status;
OrderType type;
private double limit;
private double volume;
@ -198,6 +227,7 @@ public class Exchange {
this.volume = roundShares(volume);
this.initial_volume = this.volume;
this.created = timer.currentTimeMillis();
this.status=OrderStatus.OPEN;
}
public long getID() {
@ -227,6 +257,11 @@ public class Exchange {
public Account getAccount() {
return account;
}
public OrderStatus getOrderStatus(){
return status;
}
}
@ -322,8 +357,25 @@ public class Exchange {
}
public final String CFG_MONEY_DECIMALS = "money_decimals";
public final String CFG_SHARES_DECIMALS = "shares_decimals";
public void putConfig(JSONObject cfg) {
this.setMoneyDecimals(cfg.getInt(CFG_MONEY_DECIMALS));
this.setSharesDecimals(cfg.getInt(CFG_SHARES_DECIMALS));
}
public Quote getCurrentPrice() {
/* if (!this.quoteHistory.isEmpty()){
Quote q = this.quoteHistory.pollLast();
System.out.printf("Quote: %f\n", q.price);
return q;
}
return null;
*/
SortedSet<Order> bid = order_books.get(OrderType.BUYLIMIT);
SortedSet<Order> ask = order_books.get(OrderType.SELLLIMIT);
@ -420,7 +472,6 @@ public class Exchange {
// long time = 0;
//double theprice = 12.9;
// long orderid = 1;
double lastprice = 100.0;
long lastsvolume;
@ -451,7 +502,10 @@ public class Exchange {
}
public Quote getLastQuoete() {
return this.quoteHistory.last();
if (this.quoteHistory.isEmpty()) {
return null;
}
return this.quoteHistory.pollLast();
}
private void transferMoneyAndShares(Account src, Account dst, double money, double shares) {
@ -459,6 +513,7 @@ public class Exchange {
dst.money += money;
src.shares -= shares;
dst.shares += shares;
}
public boolean cancelOrder(double account_id, long order_id) {
@ -516,6 +571,8 @@ public class Exchange {
private void removeOrderIfExecuted(Order o) {
if (o.volume != 0) {
o.status=OrderStatus.PARTIALLY_EXECUTED;
o.account.update(o);
return;
}
@ -525,23 +582,27 @@ public class Exchange {
book.remove(book.first());
o.status=OrderStatus.CLOSED;
o.account.update(o);
}
void checkSLOrders(double price){
void checkSLOrders(double price) {
SortedSet<Order> sl = order_books.get(OrderType.STOPLOSS);
SortedSet<Order> ask = order_books.get(OrderType.SELLLIMIT);
if (sl.isEmpty())
if (sl.isEmpty()) {
return;
}
Order s = sl.first();
if (price<=s.limit){
if (price <= s.limit) {
sl.remove(s);
s.type=OrderType.SELL;
s.type = OrderType.SELL;
addOrderToBook(s);
System.out.printf("Stoploss hit %f %f\n", s.volume,s.limit);
System.out.printf("Stoploss hit %f %f\n", s.volume, s.limit);
}
}
@ -552,19 +613,14 @@ public class Exchange {
SortedSet<Order> bid = order_books.get(OrderType.BUYLIMIT);
SortedSet<Order> ask = order_books.get(OrderType.SELLLIMIT);
SortedSet<Order> ul_buy = order_books.get(OrderType.BUY);
SortedSet<Order> ul_sell = order_books.get(OrderType.SELL);
double volume_total = 0;
double money_total = 0;
while (!bid.isEmpty() && !ask.isEmpty()) {
Order b = bid.first();
Order a = ask.first();
@ -581,22 +637,24 @@ public class Exchange {
//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");
// Update volume
b.volume -= volume;
a.volume -= volume;
// a.account.update(a);
// b.account.update(b);
//System.out.printf("In %f (%f) < %f (%f)\n",b.limit,b.volume,a.limit,a.volume);
volume_total += volume;
money_total += price * volume;
num_trades++;
removeOrderIfExecuted(a);
removeOrderIfExecuted(b);
this.checkSLOrders(price);
}
@ -646,6 +704,7 @@ public class Exchange {
addOrderToBook(o);
a.orders.put(o.id, o);
a.update(o);
this.executeOrders();
@ -713,8 +772,7 @@ public class Exchange {
//KeySet ks = a.orders.keySet();
return ad;
}
*/
*/
public ArrayList<OrderData> getOpenOrders(double account_id) {
Account a = accounts.get(account_id);

View File

@ -32,7 +32,7 @@ import sesim.Exchange.Account;
*
* @author 7u83
*/
public abstract class AutoTrader implements Scheduler.TimerTask {
public abstract class OldAutoTrader implements Scheduler.TimerTask {
protected double account_id;
protected Exchange se;
@ -40,7 +40,7 @@ public abstract class AutoTrader implements Scheduler.TimerTask {
protected String name;
public AutoTrader(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) {
public OldAutoTrader(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) {
account_id = se.createAccount(money, shares);
Account a = se.getAccount(account_id);
@ -53,7 +53,7 @@ public abstract class AutoTrader implements Scheduler.TimerTask {
}
public AutoTrader(){
public OldAutoTrader(){
se=null;
id=0;
}

View File

@ -109,18 +109,14 @@ public class Scheduler extends Thread {
public long currentTimeMillis1() {
long diff = System.currentTimeMillis() - last_time_millis;
// diff = 12199999L;
last_time_millis += diff;
if (diff==0)
diff++;
if (pause) {
return (long) this.current_time_millis;
}
this.current_time_millis += diff * this.acceleration;
//System.out.printf("Current TM: %f\n", this.current_time_millis);
this.current_time_millis += ((double)diff) * this.acceleration;
return (long) this.current_time_millis;
}
public long currentTimeMillis() {
@ -214,8 +210,10 @@ public class Scheduler extends Thread {
return 0;
} else {
return 0;
//return (t - currentTimeMillis())/(long)this.acceleration;
//return 0;
long n =(t - currentTimeMillis())/(long)this.acceleration;
System.out.printf("Return wait %d\n",n);
return n;
}
}

View File

@ -27,19 +27,21 @@ package traders.ManTrader;
import gui.Globals;
import gui.OrdersList;
import javax.swing.JDialog;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfigBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
import sesim.Exchange;
import sesim.Exchange.AccountListener;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ManTrader extends AutoTraderBase {
public class ManTrader extends AutoTraderBase implements AccountListener{
public ManTrader(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) {
// super(se, id, name, money, shares, null);
@ -47,9 +49,14 @@ public class ManTrader extends AutoTraderBase {
}
public ManTrader() {
super();
}
public void init(Exchange se, long id, String name, double money, double shares, JSONObject cfg){
super.init(se, id, name, money, shares, cfg);
getAccount().setListener(this);
}
ManTraderConsoleDialog consoleDialog;
@Override
@ -68,17 +75,13 @@ public class ManTrader extends AutoTraderBase {
@Override
public long timerTask() {
OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel();
ol.updateModel();
return 1000;
}
/* @Override
public AutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares) {
return null;
}
*/
@Override
public String getDisplayName() {
@ -106,4 +109,17 @@ public class ManTrader extends AutoTraderBase {
return true;
}
@Override
public JDialog getGuiConsole() {
return this.consoleDialog;
}
@Override
public void accountUpdated(Exchange.Account a, Exchange.Order o) {
//this.consoleDialog.cons
System.out.printf("AccountListener called\n");
this.consoleDialog.getConsole().getOrderListPanel().updateModel();
}
}

View File

@ -1,79 +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 traders.ManTrader;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfigBase;
import sesim.AutoTraderGui;
import sesim.Exchange;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class ManTraderConfig extends AutoTraderBase{
@Override
public void start() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public long timerTask() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public String getDisplayName() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public AutoTraderGui getGui() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public JSONObject getConfig() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void putConfig(JSONObject cfg) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean getDevelStatus() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -19,7 +19,7 @@
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="ordersList1" max="32767" attributes="0"/>
<Component id="ordersList" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
@ -56,7 +56,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="ordersList1" min="-2" pref="148" max="-2" attributes="0"/>
<Component id="ordersList" min="-2" pref="148" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
@ -141,7 +141,7 @@
<Property name="text" type="java.lang.String" value="jLabel4"/>
</Properties>
</Component>
<Component class="gui.OrdersList" name="ordersList1">
<Component class="gui.OrdersList" name="ordersList">
</Component>
<Component class="javax.swing.JButton" name="stopLossButton">
<Properties>

View File

@ -26,9 +26,7 @@
package traders.ManTrader;
import gui.OrdersList;
import javax.swing.JTable;
import sesim.AutoTrader;
import sesim.AutoTraderInterface;
import sesim.Exchange;
/**
@ -40,7 +38,8 @@ public class ManTraderConsole extends javax.swing.JPanel {
public ManTrader trader;
public OrdersList getOrderListPanel(){
return this.ordersList1;
return this.ordersList;
}
/**
@ -48,6 +47,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
*/
public ManTraderConsole() {
initComponents();
// this.ordersList1.account=trader.getAccount();
}
@ -68,7 +68,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
sellButton = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
moneyText = new javax.swing.JLabel();
ordersList1 = new gui.OrdersList();
ordersList = new gui.OrdersList();
stopLossButton = new javax.swing.JButton();
limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 1.0d));
@ -111,7 +111,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ordersList1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(ordersList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
@ -139,7 +139,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(ordersList1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ordersList, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
@ -174,6 +174,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.BUYLIMIT, volume, limit);
System.out.printf("The retval is %d",createOrder);
this.ordersList.account=this.trader.getAccount();
this.ordersList.updateModel();
}//GEN-LAST:event_buyButtonActionPerformed
@ -205,7 +208,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
private javax.swing.JLabel jLabel3;
private javax.swing.JSpinner limitSpinner;
private javax.swing.JLabel moneyText;
private gui.OrdersList ordersList1;
private gui.OrdersList ordersList;
private javax.swing.JButton sellButton;
private javax.swing.JButton stopLossButton;
private javax.swing.JSpinner volumeSpinner;

View File

@ -34,7 +34,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="console" pref="280" max="32767" attributes="0"/>
<Component id="console" pref="328" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>

View File

@ -67,14 +67,14 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
.addComponent(console, javax.swing.GroupLayout.PREFERRED_SIZE, 383, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
.addContainerGap())
);

View File

@ -31,10 +31,11 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import javax.swing.JDialog;
import org.json.JSONArray;
import org.json.JSONObject;
//import sesim.AccountData;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
@ -178,6 +179,11 @@ public class RandomTraderA extends AutoTraderBase {
}
@Override
public JDialog getGuiConsole() {
return null;
}
protected enum Action {
BUY, SELL, RANDOM
}
@ -276,18 +282,21 @@ public class RandomTraderA extends AutoTraderBase {
// how much money we ant to invest?
double money = getRandomAmmount(ad.getMoney(), buy_volume);
money = se.roundMoney(money);
Quote q = se.getCurrentPrice();
double lp = q == null ? getStart() : q.price;
double limit;
limit = lp + getRandomAmmount(lp, buy_limit);
limit = se.roundMoney(limit);
double volume = money / limit;
volume = se.roundShares(volume);
// System.out.printf("Volume : %f", volume);
limit = se.roundMoney(limit);
volume = se.roundShares(volume);
if (volume <= 0 || money <= 0) {
return false;
}

View File

@ -25,16 +25,15 @@
*/
package traders;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import org.json.JSONArray;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderConfigBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
import sesim.Exchange;
import sesim.OldAutoTrader;
/**
*
@ -53,7 +52,7 @@ public class RandomTraderConfig extends AutoTraderConfigBase implements AutoTrad
public Long[] wait_after_buy = {10L, 30L};
@Override
public AutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares) {
public OldAutoTrader createTrader(Exchange se, JSONObject cfg, long id, String name, double money, double shares) {
if (cfg != null) {
this.putConfig(cfg);
}

View File

@ -296,28 +296,28 @@
<Component class="javax.swing.JSpinner" name="waitAfterBuyMin">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="waitAfterSellMin">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="waitAfterSellMax">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JSpinner" name="waitAfterBuyMax">
<Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Integer" stepSize="1000" type="number"/>
<SpinnerModel initial="0" minimum="0" numberType="java.lang.Long" stepSize="1000" type="number"/>
</Property>
</Properties>
</Component>

View File

@ -46,29 +46,32 @@ public class RandomTraderGuiA extends AutoTraderGui {
JDialog d;
this.initialDelayMin.setValue(cfg.initial_delay[0]);
this.initialDelayMax.setValue(cfg.initial_delay[1]);
try {
this.initialDelayMin.setValue(cfg.initial_delay[0]);
this.initialDelayMax.setValue(cfg.initial_delay[1]);
this.buyVolMin.setValue(cfg.buy_volume[0]);
this.buyVolMax.setValue(cfg.buy_volume[1]);
this.sellVolMin.setValue(cfg.sell_volume[0]);
this.sellVolMax.setValue(cfg.sell_volume[1]);
this.buyLimitMin.setValue(cfg.buy_limit[0]);
this.buyLimitMax.setValue(cfg.buy_limit[1]);
this.sellLimitMin.setValue(cfg.sell_limit[0]);
this.sellLimitMax.setValue(cfg.sell_limit[1]);
this.buyVolMin.setValue(cfg.buy_volume[0]);
this.buyVolMax.setValue(cfg.buy_volume[1]);
this.sellVolMin.setValue(cfg.sell_volume[0]);
this.sellVolMax.setValue(cfg.sell_volume[1]);
this.buyLimitMin.setValue(cfg.buy_limit[0]);
this.buyLimitMax.setValue(cfg.buy_limit[1]);
this.sellLimitMin.setValue(cfg.sell_limit[0]);
this.sellLimitMax.setValue(cfg.sell_limit[1]);
this.buyWaitMin.setValue(cfg.buy_wait[0]);
this.buyWaitMax.setValue(cfg.buy_wait[1]);
this.sellWaitMin.setValue(cfg.sell_wait[0]);
this.sellWaitMax.setValue(cfg.sell_wait[1]);
this.buyWaitMin.setValue(cfg.buy_wait[0]);
this.buyWaitMax.setValue(cfg.buy_wait[1]);
this.sellWaitMin.setValue(cfg.sell_wait[0]);
this.sellWaitMax.setValue(cfg.sell_wait[1]);
this.waitAfterBuyMin.setValue(cfg.wait_after_buy[0]);
this.waitAfterBuyMax.setValue(cfg.wait_after_buy[1]);
this.waitAfterBuyMin.setValue(cfg.wait_after_buy[0]);
this.waitAfterBuyMax.setValue(cfg.wait_after_buy[1]);
this.waitAfterSellMin.setValue(cfg.wait_after_sell[0]);
this.waitAfterSellMax.setValue(cfg.wait_after_sell[1]);
this.waitAfterSellMin.setValue(cfg.wait_after_sell[0]);
this.waitAfterSellMax.setValue(cfg.wait_after_sell[1]);
} catch (Exception e) {
}
}
@Override
@ -179,13 +182,13 @@ public class RandomTraderGuiA extends AutoTraderGui {
sellLimitMin.setModel(new javax.swing.SpinnerNumberModel(0.0f, -100.0f, null, 1.0f));
waitAfterBuyMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterBuyMin.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
waitAfterSellMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterSellMin.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
waitAfterSellMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterSellMax.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
waitAfterBuyMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1000));
waitAfterBuyMax.setModel(new javax.swing.SpinnerNumberModel(0L, 0L, null, 1000L));
buyVolMin.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(0.0f), Float.valueOf(0.0f), Float.valueOf(100.0f), Float.valueOf(1.0f)));