Work on manual trading, orderbook etc...

This commit is contained in:
7u83 2017-02-14 09:08:35 +01:00
parent 25a4a3461e
commit e8b1c63768
13 changed files with 531 additions and 120 deletions

View File

@ -8,15 +8,29 @@
<Property name="useNullLayout" type="boolean" value="true"/> <Property name="useNullLayout" type="boolean" value="true"/>
</Layout> </Layout>
<SubComponents> <SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuCreateOrder"> <MenuItem class="javax.swing.JMenuItem" name="ctxMenuCreateBuyOrder">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Create Order"/> <Property name="text" type="java.lang.String" value="Create Buy Order"/>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuCreateBuyOrderActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuCreateSellOrder">
<Properties>
<Property name="text" type="java.lang.String" value="Create Sell Order"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuCreateSellOrderActionPerformed"/>
</Events>
</MenuItem> </MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuCancelOrder"> <MenuItem class="javax.swing.JMenuItem" name="ctxMenuCancelOrder">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Cancel Order"/> <Property name="text" type="java.lang.String" value="Cancel Order"/>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuCancelOrderActionPerformed"/>
</Events>
</MenuItem> </MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuModifyOder"> <MenuItem class="javax.swing.JMenuItem" name="ctxMenuModifyOder">
<Properties> <Properties>

View File

@ -25,6 +25,7 @@
*/ */
package gui; package gui;
import java.awt.Frame;
import java.awt.MouseInfo; import java.awt.MouseInfo;
import java.awt.Point; import java.awt.Point;
import java.util.Iterator; import java.util.Iterator;
@ -32,8 +33,11 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import sesim.Exchange;
import sesim.Exchange.Account; import sesim.Exchange.Account;
import sesim.Exchange.Order; import sesim.Exchange.Order;
import sesim.Exchange.OrderType;
import traders.ManTrader.CreateOrderDialog;
/** /**
* *
@ -41,14 +45,18 @@ import sesim.Exchange.Order;
*/ */
public class OrdersList extends javax.swing.JPanel { public class OrdersList extends javax.swing.JPanel {
public Account account; private Account account;
DefaultTableModel model; DefaultTableModel model;
public final void updateModel() { public final void updateModel() {
System.out.printf("Update Model\n");
if (null == account) { if (null == account) {
return; return;
} }
System.out.printf("Now updateing\n");
int row = 0; int row = 0;
Iterator<Map.Entry<Long, Order>> it = account.getOrders().entrySet().iterator(); Iterator<Map.Entry<Long, Order>> it = account.getOrders().entrySet().iterator();
@ -78,8 +86,13 @@ public class OrdersList extends javax.swing.JPanel {
initComponents(); initComponents();
model = (DefaultTableModel) table.getModel(); model = (DefaultTableModel) table.getModel();
model.setRowCount(0); model.setRowCount(0);
updateModel();
table.setFillsViewportHeight(true); table.setFillsViewportHeight(true);
updateModel();
}
public void initOrderList(Account account) {
this.account = account;
updateModel();
} }
/** /**
@ -92,16 +105,35 @@ public class OrdersList extends javax.swing.JPanel {
private void initComponents() { private void initComponents() {
ctxMenu = new javax.swing.JPopupMenu(); ctxMenu = new javax.swing.JPopupMenu();
ctxMenuCreateOrder = new javax.swing.JMenuItem(); ctxMenuCreateBuyOrder = new javax.swing.JMenuItem();
ctxMenuCreateSellOrder = new javax.swing.JMenuItem();
ctxMenuCancelOrder = new javax.swing.JMenuItem(); ctxMenuCancelOrder = new javax.swing.JMenuItem();
ctxMenuModifyOder = new javax.swing.JMenuItem(); ctxMenuModifyOder = new javax.swing.JMenuItem();
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
table = new javax.swing.JTable(); table = new javax.swing.JTable();
ctxMenuCreateOrder.setText("Create Order"); ctxMenuCreateBuyOrder.setText("Create Buy Order");
ctxMenu.add(ctxMenuCreateOrder); ctxMenuCreateBuyOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuCreateBuyOrderActionPerformed(evt);
}
});
ctxMenu.add(ctxMenuCreateBuyOrder);
ctxMenuCreateSellOrder.setText("Create Sell Order");
ctxMenuCreateSellOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuCreateSellOrderActionPerformed(evt);
}
});
ctxMenu.add(ctxMenuCreateSellOrder);
ctxMenuCancelOrder.setText("Cancel Order"); ctxMenuCancelOrder.setText("Cancel Order");
ctxMenuCancelOrder.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ctxMenuCancelOrderActionPerformed(evt);
}
});
ctxMenu.add(ctxMenuCancelOrder); ctxMenu.add(ctxMenuCancelOrder);
ctxMenuModifyOder.setText("Modify Oder"); ctxMenuModifyOder.setText("Modify Oder");
@ -160,8 +192,7 @@ public class OrdersList extends javax.swing.JPanel {
int currentRow = table.rowAtPoint(point); int currentRow = table.rowAtPoint(point);
if (currentRow == -1) { if (currentRow == -1) {
} } else {
else {
table.setRowSelectionInterval(currentRow, currentRow); table.setRowSelectionInterval(currentRow, currentRow);
} }
@ -178,11 +209,38 @@ public class OrdersList extends javax.swing.JPanel {
}//GEN-LAST:event_tableMousePressed }//GEN-LAST:event_tableMousePressed
private void createOrder(OrderType t) {
CreateOrderDialog cd = new CreateOrderDialog(Globals.frame, true, account, t);
//cd.initDialog(account);
cd.setVisible(true);
}
private void ctxMenuCreateSellOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuCreateSellOrderActionPerformed
createOrder(OrderType.SELLLIMIT);
}//GEN-LAST:event_ctxMenuCreateSellOrderActionPerformed
private void ctxMenuCreateBuyOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuCreateBuyOrderActionPerformed
createOrder(OrderType.BUYLIMIT);
}//GEN-LAST:event_ctxMenuCreateBuyOrderActionPerformed
private void ctxMenuCancelOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctxMenuCancelOrderActionPerformed
int r = table.getSelectedRow();
Long id = (Long) model.getValueAt(r, 0);
System.out.printf("Should cancel %d\n", id);
Globals.se.cancelOrder(account.getID(), id);
}//GEN-LAST:event_ctxMenuCancelOrderActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPopupMenu ctxMenu; private javax.swing.JPopupMenu ctxMenu;
private javax.swing.JMenuItem ctxMenuCancelOrder; private javax.swing.JMenuItem ctxMenuCancelOrder;
private javax.swing.JMenuItem ctxMenuCreateOrder; private javax.swing.JMenuItem ctxMenuCreateBuyOrder;
private javax.swing.JMenuItem ctxMenuCreateSellOrder;
private javax.swing.JMenuItem ctxMenuModifyOder; private javax.swing.JMenuItem ctxMenuModifyOder;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table; private javax.swing.JTable table;

View File

@ -58,7 +58,6 @@ public class TraderListPanel extends javax.swing.JPanel {
sesim.Quote q = Globals.se.getLastQuoete(); sesim.Quote q = Globals.se.getLastQuoete();
double price = q == null ? 0 : q.price; double price = q == null ? 0 : q.price;
System.out.printf("Price?: %f\n", price);
int size = Globals.se.traders.size(); int size = Globals.se.traders.size();
model.setRowCount(size); model.setRowCount(size);

View File

@ -262,7 +262,6 @@ public class Exchange {
return status; return status;
} }
} }
/** /**
@ -364,8 +363,7 @@ public class Exchange {
try { try {
this.setMoneyDecimals(cfg.getInt(CFG_MONEY_DECIMALS)); this.setMoneyDecimals(cfg.getInt(CFG_MONEY_DECIMALS));
this.setSharesDecimals(cfg.getInt(CFG_SHARES_DECIMALS)); this.setSharesDecimals(cfg.getInt(CFG_SHARES_DECIMALS));
} } catch (Exception e) {
catch (Exception e){
} }
@ -373,42 +371,57 @@ public class Exchange {
public Quote getCurrentPrice() { 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> bid = order_books.get(OrderType.BUYLIMIT);
SortedSet<Order> ask = order_books.get(OrderType.SELLLIMIT); SortedSet<Order> ask = order_books.get(OrderType.SELLLIMIT);
Quote q = null;
tradelock.lock(); tradelock.lock();
if (!bid.isEmpty() && !ask.isEmpty()) { Quote lq = this.getLastQuoete();
q = new Quote(); Order b = null, a = null;
q.price = (bid.first().limit + ask.first().limit) / 2.0; if (!bid.isEmpty()) {
b = bid.first();
}
if (!ask.isEmpty()) {
a = ask.first();
} }
tradelock.unlock(); tradelock.unlock();
if (q != null) { if (a != null && b != null) {
Quote q = new Quote();
if (lq == null) {
q.price = (bid.first().limit + ask.first().limit) / 2.0;
return q; return q;
} }
if (lq.price < b.limit) {
q.price = b.limit;
return q;
}
if (lq.price > a.limit) {
q.price = a.limit;
return q;
}
}
if (this.quoteHistory.isEmpty()) { if (a != null) {
Quote q = new Quote();
if (lq == null) {
q.price = a.limit;
return q;
}
return lq;
}
if (b != null) {
Quote q = new Quote();
if (lq == null) {
q.price = b.limit;
return q;
}
return lq;
}
return null; return null;
} }
q = this.quoteHistory.last();
return q;
}
// Class to describe an executed order // Class to describe an executed order
// QuoteReceiver has to be implemented by objects that wants // QuoteReceiver has to be implemented by objects that wants
// to receive quote updates // to receive quote updates
@ -442,8 +455,7 @@ public class Exchange {
if (br == null) { if (br == null) {
System.out.printf("Br is null\n"); System.out.printf("Br is null\n");
} } else {
else{
System.out.printf("Br is not Nukk\n"); System.out.printf("Br is not Nukk\n");
} }
@ -521,7 +533,7 @@ public class Exchange {
if (this.quoteHistory.isEmpty()) { if (this.quoteHistory.isEmpty()) {
return null; return null;
} }
System.out.printf("qhSize: %d\n",this.quoteHistory.size());
return this.quoteHistory.last(); return this.quoteHistory.last();
} }
@ -551,6 +563,7 @@ public class Exchange {
boolean rc = ob.remove(o); boolean rc = ob.remove(o);
a.orders.remove(o.id); a.orders.remove(o.id);
a.update(o);
ret = true; ret = true;
} }
@ -587,12 +600,25 @@ public class Exchange {
public double fairValue = 0; public double fairValue = 0;
private void removeOrderIfExecuted(Order o) { private void removeOrderIfExecuted(Order o) {
if (o.getAccount().getOwner().getName().equals("Tobias0")) {
System.out.printf("Tobias 0 test\n");
}
if (o.volume != 0) { if (o.volume != 0) {
if (o.getAccount().getOwner().getName().equals("Tobias0")) {
System.out.printf("Patially remove tobias\n");
}
o.status = OrderStatus.PARTIALLY_EXECUTED; o.status = OrderStatus.PARTIALLY_EXECUTED;
o.account.update(o); o.account.update(o);
return; return;
} }
if (o.getAccount().getOwner().getName().equals("Tobias0")) {
System.out.printf("Fully remove tobias\n");
}
o.account.orders.remove(o.id); o.account.orders.remove(o.id);
SortedSet book = order_books.get(o.type); SortedSet book = order_books.get(o.type);
@ -655,14 +681,12 @@ public class Exchange {
// Transfer money and shares // Transfer money and shares
transferMoneyAndShares(b.account, a.account, volume * price, -volume); transferMoneyAndShares(b.account, a.account, volume * price, -volume);
// Update volume // Update volume
b.volume -= volume; b.volume -= volume;
a.volume -= volume; a.volume -= volume;
// a.account.update(a); // a.account.update(a);
// b.account.update(b); // b.account.update(b);
//System.out.printf("In %f (%f) < %f (%f)\n",b.limit,b.volume,a.limit,a.volume); //System.out.printf("In %f (%f) < %f (%f)\n",b.limit,b.volume,a.limit,a.volume);
volume_total += volume; volume_total += volume;
money_total += price * volume; money_total += price * volume;

View File

@ -0,0 +1,69 @@
<?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">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="moneyLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="sharesLabelText" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="sharesLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="moneyLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="sharesLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="sharesLabelText" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Money:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="moneyLabel">
<Properties>
<Property name="text" type="java.lang.String" value="0.0000"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="sharesLabel">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel3"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="sharesLabelText">
<Properties>
<Property name="text" type="java.lang.String" value="Shares:"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,105 @@
/*
* 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 sesim.Exchange.Account;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class AccountBalance extends javax.swing.JPanel {
/**
* Creates new form AccountBalance
*/
public AccountBalance() {
initComponents();
}
public void updateBalance (Account account){
this.moneyLabel.setText(Double.toString(account.getMoney()));
this.sharesLabel.setText(Double.toString(account.getShares()));
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
moneyLabel = new javax.swing.JLabel();
sharesLabel = new javax.swing.JLabel();
sharesLabelText = new javax.swing.JLabel();
jLabel1.setText("Money:");
moneyLabel.setText("0.0000");
sharesLabel.setText("jLabel3");
sharesLabelText.setText("Shares:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(moneyLabel)
.addGap(18, 18, 18)
.addComponent(sharesLabelText)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sharesLabel)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(moneyLabel)
.addComponent(sharesLabel)
.addComponent(sharesLabelText))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel moneyLabel;
private javax.swing.JLabel sharesLabel;
private javax.swing.JLabel sharesLabelText;
// End of variables declaration//GEN-END:variables
}

View File

@ -33,15 +33,15 @@
<Component id="jButton2" min="-2" max="-2" attributes="0"/> <Component id="jButton2" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="jComboBox1" min="-2" pref="126" max="-2" attributes="0"/> <Component id="typeComboBox" min="-2" pref="126" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/> <Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jSpinner1" min="-2" pref="100" max="-2" attributes="0"/> <Component id="limitSpinner" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jSpinner2" min="-2" pref="100" max="-2" attributes="0"/> <Component id="volumeSpinner" min="-2" pref="100" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -53,9 +53,9 @@
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="typeComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jSpinner1" alignment="3" min="-2" pref="28" max="-2" attributes="0"/> <Component id="limitSpinner" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
<Component id="jSpinner2" alignment="3" min="-2" pref="28" max="-2" attributes="0"/> <Component id="volumeSpinner" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
@ -75,21 +75,25 @@
<Property name="mnemonic" type="int" value="111"/> <Property name="mnemonic" type="int" value="111"/>
<Property name="text" type="java.lang.String" value="Ok"/> <Property name="text" type="java.lang.String" value="Ok"/>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="jButton2"> <Component class="javax.swing.JButton" name="jButton2">
<Properties> <Properties>
<Property name="mnemonic" type="int" value="99"/> <Property name="mnemonic" type="int" value="99"/>
<Property name="text" type="java.lang.String" value="Cancel"/> <Property name="text" type="java.lang.String" value="Cancel"/>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JComboBox" name="jComboBox1"> <Component class="javax.swing.JComboBox" name="typeComboBox">
<Properties> <Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor"> <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4"> <StringArray count="2">
<StringItem index="0" value="Buy "/> <StringItem index="0" value="Buy "/>
<StringItem index="1" value="Sell"/> <StringItem index="1" value="Sell"/>
<StringItem index="2" value="Stop Loss"/>
<StringItem index="3" value=" "/>
</StringArray> </StringArray>
</Property> </Property>
</Properties> </Properties>
@ -97,14 +101,14 @@
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/> <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues> </AuxValues>
</Component> </Component>
<Component class="javax.swing.JSpinner" name="jSpinner1"> <Component class="javax.swing.JSpinner" name="limitSpinner">
<Properties> <Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor"> <Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/> <SpinnerModel initial="0.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/>
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JSpinner" name="jSpinner2"> <Component class="javax.swing.JSpinner" name="volumeSpinner">
<Properties> <Properties>
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor"> <Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
<SpinnerModel initial="0.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/> <SpinnerModel initial="0.0" minimum="0.0" numberType="java.lang.Double" stepSize="0.1" type="number"/>

View File

@ -25,6 +25,13 @@
*/ */
package traders.ManTrader; package traders.ManTrader;
import gui.Globals;
import java.util.ArrayList;
import sesim.Exchange;
import sesim.Exchange.Account;
import sesim.Exchange.OrderType;
import sesim.Quote;
/** /**
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
@ -37,6 +44,47 @@ public class CreateOrderDialog extends javax.swing.JDialog {
public CreateOrderDialog(java.awt.Frame parent, boolean modal) { public CreateOrderDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal); super(parent, modal);
initComponents(); initComponents();
this.setLocationRelativeTo(this.getParent());
}
OrderType typeList[];
public CreateOrderDialog(java.awt.Frame parent, boolean modal, Account account, OrderType type) {
this(parent, modal);
this.account = account;
typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Buy ", "Sell"}));
typeList = new OrderType[]{OrderType.BUYLIMIT, OrderType.SELLLIMIT};
for (int i = 0; i < typeList.length; i++) {
if (typeList[i] == type) {
this.typeComboBox.setSelectedIndex(i);
}
}
initDialog();
}
private OrderType getOrderType() {
int i = this.typeComboBox.getSelectedIndex();
return typeList[i];
}
Account account;
public void initDialog() {
OrderType t = getOrderType();
Quote q = Globals.se.getCurrentPrice();
Double price = q == null ? 0.0 : q.price;
if (t == OrderType.BUYLIMIT) {
this.limitSpinner.setValue(Globals.se.roundMoney(price));
this.volumeSpinner.setValue(Globals.se.roundShares(account.getMoney()/price));
}
if (t == OrderType.SELLLIMIT) {
this.limitSpinner.setValue(Globals.se.roundMoney(price));
this.volumeSpinner.setValue(Globals.se.roundShares(account.getShares()));
}
} }
/** /**
@ -50,9 +98,9 @@ public class CreateOrderDialog extends javax.swing.JDialog {
jButton1 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox<>(); typeComboBox = new javax.swing.JComboBox<>();
jSpinner1 = new javax.swing.JSpinner(); limitSpinner = new javax.swing.JSpinner();
jSpinner2 = new javax.swing.JSpinner(); volumeSpinner = new javax.swing.JSpinner();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel();
@ -61,15 +109,25 @@ public class CreateOrderDialog extends javax.swing.JDialog {
jButton1.setMnemonic('o'); jButton1.setMnemonic('o');
jButton1.setText("Ok"); jButton1.setText("Ok");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setMnemonic('c'); jButton2.setMnemonic('c');
jButton2.setText("Cancel"); jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Buy ", "Sell", "Stop Loss", " " })); typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Buy ", "Sell" }));
jSpinner1.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 0.1d)); limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 0.1d));
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 0.1d)); volumeSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 0.1d));
jLabel1.setText("Volume:"); jLabel1.setText("Volume:");
@ -87,15 +145,15 @@ public class CreateOrderDialog extends javax.swing.JDialog {
.addGap(1, 1, 1) .addGap(1, 1, 1)
.addComponent(jButton2)) .addComponent(jButton2))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2) .addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(limitSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1) .addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(volumeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
@ -103,9 +161,9 @@ public class CreateOrderDialog extends javax.swing.JDialog {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(limitSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(volumeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1) .addComponent(jLabel1)
.addComponent(jLabel2)) .addComponent(jLabel2))
.addGap(18, 18, 18) .addGap(18, 18, 18)
@ -118,6 +176,22 @@ public class CreateOrderDialog extends javax.swing.JDialog {
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
dispose();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
double volume = (double) volumeSpinner.getValue();
double limit = (double) limitSpinner.getValue();
if (account == null) {
System.out.printf("Account is null\n");
}
OrderType type = this.getOrderType();
Globals.se.createOrder(account.getID(), type, volume, limit);
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
@ -163,10 +237,10 @@ public class CreateOrderDialog extends javax.swing.JDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1; private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2; private javax.swing.JButton jButton2;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel2;
private javax.swing.JSpinner jSpinner1; private javax.swing.JSpinner limitSpinner;
private javax.swing.JSpinner jSpinner2; private javax.swing.JComboBox<String> typeComboBox;
private javax.swing.JSpinner volumeSpinner;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@ -36,6 +36,7 @@ import sesim.AutoTraderConfig;
import sesim.AutoTraderGui; import sesim.AutoTraderGui;
import sesim.Exchange; import sesim.Exchange;
import sesim.Exchange.AccountListener; import sesim.Exchange.AccountListener;
import sesim.Exchange.OrderStatus;
/** /**
* *
@ -62,13 +63,11 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
@Override @Override
public void start() { public void start() {
se.timer.startTimerEvent(this, 0); se.timer.startTimerEvent(this, 0);
consoleDialog = new ManTraderConsoleDialog(Globals.frame, false); consoleDialog = new ManTraderConsoleDialog(Globals.frame, false, this.getAccount());
this.consoleDialog.getBalancePanel().updateBalance(this.getAccount());
// consoleDialog. rdersList1.account=trader.getAccount(); // consoleDialog. rdersList1.account=trader.getAccount();
consoleDialog.getConsole().trader=this; // consoleDialog.getConsole().trader=this;
consoleDialog.setVisible(true); consoleDialog.setVisible(true);
} }
@ -76,13 +75,11 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
@Override @Override
public long timerTask() { public long timerTask() {
OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel(); // OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel();
ol.updateModel(); // ol.updateModel();
return 1000; return 1000;
} }
@Override @Override
public String getDisplayName() { public String getDisplayName() {
return null; return null;
@ -119,7 +116,13 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
//this.consoleDialog.cons //this.consoleDialog.cons
System.out.printf("AccountListener called\n"); System.out.printf("AccountListener called\n");
this.consoleDialog.getConsole().getOrderListPanel().updateModel(); System.out.printf("%d %s\n", o.getID(), o.getOrderStatus().toString());
if (o.getOrderStatus()==OrderStatus.CLOSED){
o.getAccount().getOrders().put(o.getID(), o);
}
this.consoleDialog.getOrderList().updateModel();
this.consoleDialog.getBalancePanel().updateBalance(o.getAccount());
} }
} }

View File

@ -48,6 +48,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
public ManTraderConsole() { public ManTraderConsole() {
initComponents(); initComponents();
// this.ordersList1.account=trader.getAccount(); // this.ordersList1.account=trader.getAccount();
} }
@ -177,8 +178,8 @@ public class ManTraderConsole extends javax.swing.JPanel {
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.BUYLIMIT, volume, limit); long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.BUYLIMIT, volume, limit);
System.out.printf("The retval is %d",createOrder); System.out.printf("The retval is %d",createOrder);
this.ordersList.account=this.trader.getAccount(); // this.ordersList.account=this.trader.getAccount();
this.ordersList.updateModel(); // this.ordersList.updateModel();
}//GEN-LAST:event_buyButtonActionPerformed }//GEN-LAST:event_buyButtonActionPerformed

View File

@ -23,20 +23,48 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="console" alignment="0" pref="450" max="32767" attributes="0"/> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jTabbedPane1" pref="438" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="accountBalance1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="console" pref="334" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jTabbedPane1" min="-2" pref="246" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="accountBalance1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="79" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="traders.ManTrader.ManTraderConsole" name="console"> <Container class="javax.swing.JTabbedPane" name="jTabbedPane1">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents>
<Component class="gui.OrdersList" name="ordersList">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Open Orders">
<Property name="tabTitle" type="java.lang.String" value="Open Orders"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
<Component class="traders.ManTrader.AccountBalance" name="accountBalance1">
</Component> </Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -26,6 +26,7 @@
package traders.ManTrader; package traders.ManTrader;
import javax.swing.JPanel; import javax.swing.JPanel;
import sesim.Exchange.Account;
/** /**
* *
@ -36,17 +37,26 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
/** /**
* Creates new form ManTraderConsole * Creates new form ManTraderConsole
*/ */
public ManTraderConsoleDialog(java.awt.Frame parent, boolean modal) { public ManTraderConsoleDialog(java.awt.Frame parent, boolean modal, Account account) {
super(parent, modal); super(parent, modal);
initComponents(); initComponents();
this.ordersList.initOrderList(account);
this.setTitle(account.getOwner().getName()+" - Trading Console");
}
public gui.OrdersList getOrderList(){
return this.ordersList;
}
public AccountBalance getBalancePanel(){
return this.accountBalance1;
} }
// public ManTraderConsole getConsole(){
public ManTraderConsole getConsole(){ // return this.console;
return this.console; // }
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
@ -57,21 +67,35 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
console = new traders.ManTrader.ManTraderConsole(); jTabbedPane1 = new javax.swing.JTabbedPane();
ordersList = new gui.OrdersList();
accountBalance1 = new traders.ManTrader.AccountBalance();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jTabbedPane1.addTab("Open Orders", ordersList);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(accountBalance1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE) .addContainerGap()
.addContainerGap()) .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(accountBalance1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(79, Short.MAX_VALUE))
); );
pack(); pack();
@ -108,7 +132,7 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
/* Create and display the dialog */ /* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
ManTraderConsoleDialog dialog = new ManTraderConsoleDialog(new javax.swing.JFrame(), true); ManTraderConsoleDialog dialog = new ManTraderConsoleDialog(new javax.swing.JFrame(), true, null);
dialog.addWindowListener(new java.awt.event.WindowAdapter() { dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override @Override
public void windowClosing(java.awt.event.WindowEvent e) { public void windowClosing(java.awt.event.WindowEvent e) {
@ -121,6 +145,8 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private traders.ManTrader.ManTraderConsole console; private traders.ManTrader.AccountBalance accountBalance1;
private javax.swing.JTabbedPane jTabbedPane1;
private gui.OrdersList ordersList;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@ -284,6 +284,7 @@ public class RandomTraderA extends AutoTraderBase {
double money = getRandomAmmount(ad.getMoney(), buy_volume); double money = getRandomAmmount(ad.getMoney(), buy_volume);
Quote q = se.getCurrentPrice(); Quote q = se.getCurrentPrice();
//q=se.getLastQuoete();
double lp = q == null ? getStart() : q.price; double lp = q == null ? getStart() : q.price;
double limit; double limit;
@ -323,8 +324,13 @@ public class RandomTraderA extends AutoTraderBase {
// double lp = 100.0; //se.getBestLimit(type); // double lp = 100.0; //se.getBestLimit(type);
Quote q = se.getCurrentPrice(); Quote q = se.getCurrentPrice();
// q=se.getLastQuoete();
double lp = q == null ? getStart() : q.price; double lp = q == null ? getStart() : q.price;
double limit; double limit;
limit = lp + getRandomAmmount(lp, sell_limit); limit = lp + getRandomAmmount(lp, sell_limit);
se.roundMoney(limit); se.roundMoney(limit);