Work on manual trading, orderbook etc...
This commit is contained in:
parent
25a4a3461e
commit
e8b1c63768
@ -8,15 +8,29 @@
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuCreateOrder">
|
||||
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuCreateBuyOrder">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Create Order"/>
|
||||
<Property name="text" type="java.lang.String" value="Create Buy Order"/>
|
||||
</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 class="javax.swing.JMenuItem" name="ctxMenuCancelOrder">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Cancel Order"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ctxMenuCancelOrderActionPerformed"/>
|
||||
</Events>
|
||||
</MenuItem>
|
||||
<MenuItem class="javax.swing.JMenuItem" name="ctxMenuModifyOder">
|
||||
<Properties>
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package gui;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.util.Iterator;
|
||||
@ -32,8 +33,11 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import sesim.Exchange;
|
||||
import sesim.Exchange.Account;
|
||||
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 Account account;
|
||||
private Account account;
|
||||
DefaultTableModel model;
|
||||
|
||||
public final void updateModel() {
|
||||
System.out.printf("Update Model\n");
|
||||
if (null == account) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.printf("Now updateing\n");
|
||||
|
||||
int row = 0;
|
||||
|
||||
Iterator<Map.Entry<Long, Order>> it = account.getOrders().entrySet().iterator();
|
||||
@ -78,8 +86,13 @@ public class OrdersList extends javax.swing.JPanel {
|
||||
initComponents();
|
||||
model = (DefaultTableModel) table.getModel();
|
||||
model.setRowCount(0);
|
||||
updateModel();
|
||||
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() {
|
||||
|
||||
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();
|
||||
ctxMenuModifyOder = new javax.swing.JMenuItem();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
table = new javax.swing.JTable();
|
||||
|
||||
ctxMenuCreateOrder.setText("Create Order");
|
||||
ctxMenu.add(ctxMenuCreateOrder);
|
||||
ctxMenuCreateBuyOrder.setText("Create Buy Order");
|
||||
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.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
ctxMenuCancelOrderActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
ctxMenu.add(ctxMenuCancelOrder);
|
||||
|
||||
ctxMenuModifyOder.setText("Modify Oder");
|
||||
@ -158,10 +190,9 @@ public class OrdersList extends javax.swing.JPanel {
|
||||
|
||||
Point point = evt.getPoint();
|
||||
int currentRow = table.rowAtPoint(point);
|
||||
if (currentRow==-1){
|
||||
if (currentRow == -1) {
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
table.setRowSelectionInterval(currentRow, currentRow);
|
||||
}
|
||||
@ -178,11 +209,38 @@ public class OrdersList extends javax.swing.JPanel {
|
||||
|
||||
}//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
|
||||
private javax.swing.JPopupMenu ctxMenu;
|
||||
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.JScrollPane jScrollPane1;
|
||||
private javax.swing.JTable table;
|
||||
|
@ -58,7 +58,6 @@ public class TraderListPanel extends javax.swing.JPanel {
|
||||
sesim.Quote q = Globals.se.getLastQuoete();
|
||||
double price = q == null ? 0 : q.price;
|
||||
|
||||
System.out.printf("Price?: %f\n", price);
|
||||
|
||||
int size = Globals.se.traders.size();
|
||||
model.setRowCount(size);
|
||||
|
@ -227,7 +227,7 @@ public class Exchange {
|
||||
this.volume = roundShares(volume);
|
||||
this.initial_volume = this.volume;
|
||||
this.created = timer.currentTimeMillis();
|
||||
this.status=OrderStatus.OPEN;
|
||||
this.status = OrderStatus.OPEN;
|
||||
}
|
||||
|
||||
public long getID() {
|
||||
@ -258,11 +258,10 @@ public class Exchange {
|
||||
return account;
|
||||
}
|
||||
|
||||
public OrderStatus getOrderStatus(){
|
||||
public OrderStatus getOrderStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -361,11 +360,10 @@ public class Exchange {
|
||||
public final String CFG_SHARES_DECIMALS = "shares_decimals";
|
||||
|
||||
public void putConfig(JSONObject cfg) {
|
||||
try{
|
||||
try {
|
||||
this.setMoneyDecimals(cfg.getInt(CFG_MONEY_DECIMALS));
|
||||
this.setSharesDecimals(cfg.getInt(CFG_SHARES_DECIMALS));
|
||||
}
|
||||
catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
@ -373,42 +371,57 @@ public class Exchange {
|
||||
|
||||
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);
|
||||
|
||||
Quote q = null;
|
||||
|
||||
tradelock.lock();
|
||||
if (!bid.isEmpty() && !ask.isEmpty()) {
|
||||
q = new Quote();
|
||||
q.price = (bid.first().limit + ask.first().limit) / 2.0;
|
||||
|
||||
Quote lq = this.getLastQuoete();
|
||||
Order b = null, a = null;
|
||||
if (!bid.isEmpty()) {
|
||||
b = bid.first();
|
||||
}
|
||||
if (!ask.isEmpty()) {
|
||||
a = ask.first();
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
q = this.quoteHistory.last();
|
||||
|
||||
return q;
|
||||
|
||||
}
|
||||
|
||||
// Class to describe an executed order
|
||||
// QuoteReceiver has to be implemented by objects that wants
|
||||
// to receive quote updates
|
||||
@ -440,16 +453,15 @@ public class Exchange {
|
||||
|
||||
public void addBookReceiver(OrderType t, BookReceiver br) {
|
||||
|
||||
if (br==null){
|
||||
if (br == null) {
|
||||
System.out.printf("Br is null\n");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
System.out.printf("Br is not Nukk\n");
|
||||
}
|
||||
|
||||
ArrayList<BookReceiver> bookreceivers;
|
||||
bookreceivers = selectBookReceiver(t);
|
||||
if (bookreceivers == null){
|
||||
if (bookreceivers == null) {
|
||||
System.out.printf("null in bookreceivers\n");
|
||||
}
|
||||
bookreceivers.add(br);
|
||||
@ -521,7 +533,7 @@ public class Exchange {
|
||||
if (this.quoteHistory.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
System.out.printf("qhSize: %d\n",this.quoteHistory.size());
|
||||
|
||||
return this.quoteHistory.last();
|
||||
}
|
||||
|
||||
@ -551,6 +563,7 @@ public class Exchange {
|
||||
boolean rc = ob.remove(o);
|
||||
|
||||
a.orders.remove(o.id);
|
||||
a.update(o);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
@ -587,19 +600,32 @@ public class Exchange {
|
||||
public double fairValue = 0;
|
||||
|
||||
private void removeOrderIfExecuted(Order o) {
|
||||
if (o.getAccount().getOwner().getName().equals("Tobias0")) {
|
||||
System.out.printf("Tobias 0 test\n");
|
||||
}
|
||||
|
||||
if (o.volume != 0) {
|
||||
o.status=OrderStatus.PARTIALLY_EXECUTED;
|
||||
|
||||
if (o.getAccount().getOwner().getName().equals("Tobias0")) {
|
||||
System.out.printf("Patially remove tobias\n");
|
||||
}
|
||||
|
||||
o.status = OrderStatus.PARTIALLY_EXECUTED;
|
||||
o.account.update(o);
|
||||
return;
|
||||
}
|
||||
|
||||
if (o.getAccount().getOwner().getName().equals("Tobias0")) {
|
||||
System.out.printf("Fully remove tobias\n");
|
||||
}
|
||||
|
||||
o.account.orders.remove(o.id);
|
||||
|
||||
SortedSet book = order_books.get(o.type);
|
||||
|
||||
book.remove(book.first());
|
||||
|
||||
o.status=OrderStatus.CLOSED;
|
||||
o.status = OrderStatus.CLOSED;
|
||||
o.account.update(o);
|
||||
|
||||
}
|
||||
@ -655,14 +681,12 @@ public class Exchange {
|
||||
// Transfer money and shares
|
||||
transferMoneyAndShares(b.account, a.account, volume * price, -volume);
|
||||
|
||||
|
||||
// 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;
|
||||
|
69
src/main/java/traders/ManTrader/AccountBalance.form
Normal file
69
src/main/java/traders/ManTrader/AccountBalance.form
Normal 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>
|
105
src/main/java/traders/ManTrader/AccountBalance.java
Normal file
105
src/main/java/traders/ManTrader/AccountBalance.java
Normal 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
|
||||
}
|
@ -33,15 +33,15 @@
|
||||
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<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"/>
|
||||
<Component id="jLabel2" min="-2" 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"/>
|
||||
<Component id="jLabel1" min="-2" 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>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -53,9 +53,9 @@
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jSpinner1" 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="typeComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="limitSpinner" 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="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -75,21 +75,25 @@
|
||||
<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="jButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton2">
|
||||
<Properties>
|
||||
<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="jButton2ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="jComboBox1">
|
||||
<Component class="javax.swing.JComboBox" name="typeComboBox">
|
||||
<Properties>
|
||||
<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="1" value="Sell"/>
|
||||
<StringItem index="2" value="Stop Loss"/>
|
||||
<StringItem index="3" value=" "/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
@ -97,14 +101,14 @@
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSpinner" name="jSpinner1">
|
||||
<Component class="javax.swing.JSpinner" name="limitSpinner">
|
||||
<Properties>
|
||||
<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"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSpinner" name="jSpinner2">
|
||||
<Component class="javax.swing.JSpinner" name="volumeSpinner">
|
||||
<Properties>
|
||||
<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"/>
|
||||
|
@ -25,6 +25,13 @@
|
||||
*/
|
||||
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>
|
||||
@ -37,6 +44,47 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
public CreateOrderDialog(java.awt.Frame parent, boolean modal) {
|
||||
super(parent, modal);
|
||||
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();
|
||||
jButton2 = new javax.swing.JButton();
|
||||
jComboBox1 = new javax.swing.JComboBox<>();
|
||||
jSpinner1 = new javax.swing.JSpinner();
|
||||
jSpinner2 = new javax.swing.JSpinner();
|
||||
typeComboBox = new javax.swing.JComboBox<>();
|
||||
limitSpinner = new javax.swing.JSpinner();
|
||||
volumeSpinner = new javax.swing.JSpinner();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
|
||||
@ -61,15 +109,25 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
|
||||
jButton1.setMnemonic('o');
|
||||
jButton1.setText("Ok");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jButton2.setMnemonic('c');
|
||||
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:");
|
||||
|
||||
@ -87,15 +145,15 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
.addGap(1, 1, 1)
|
||||
.addComponent(jButton2))
|
||||
.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)
|
||||
.addComponent(jLabel2)
|
||||
.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)
|
||||
.addComponent(jLabel1)
|
||||
.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())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
@ -103,9 +161,9 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.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(jSpinner1, 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(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(limitSpinner, 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(jLabel2))
|
||||
.addGap(18, 18, 18)
|
||||
@ -118,6 +176,22 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
||||
pack();
|
||||
}// </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
|
||||
*/
|
||||
@ -163,10 +237,10 @@ public class CreateOrderDialog 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.JComboBox<String> jComboBox1;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JSpinner jSpinner1;
|
||||
private javax.swing.JSpinner jSpinner2;
|
||||
private javax.swing.JSpinner limitSpinner;
|
||||
private javax.swing.JComboBox<String> typeComboBox;
|
||||
private javax.swing.JSpinner volumeSpinner;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
@ -36,12 +36,13 @@ import sesim.AutoTraderConfig;
|
||||
import sesim.AutoTraderGui;
|
||||
import sesim.Exchange;
|
||||
import sesim.Exchange.AccountListener;
|
||||
import sesim.Exchange.OrderStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class ManTrader extends AutoTraderBase implements AccountListener{
|
||||
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);
|
||||
@ -53,7 +54,7 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
super.init(se, id, name, money, shares, cfg);
|
||||
getAccount().setListener(this);
|
||||
}
|
||||
@ -62,13 +63,11 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
|
||||
@Override
|
||||
public void start() {
|
||||
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.getConsole().trader=this;
|
||||
|
||||
|
||||
// consoleDialog.getConsole().trader=this;
|
||||
consoleDialog.setVisible(true);
|
||||
|
||||
}
|
||||
@ -76,13 +75,11 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
|
||||
@Override
|
||||
public long timerTask() {
|
||||
|
||||
OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel();
|
||||
ol.updateModel();
|
||||
// OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel();
|
||||
// ol.updateModel();
|
||||
return 1000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return null;
|
||||
@ -119,7 +116,13 @@ public class ManTrader extends AutoTraderBase implements AccountListener{
|
||||
//this.consoleDialog.cons
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
||||
public ManTraderConsole() {
|
||||
initComponents();
|
||||
|
||||
|
||||
// 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);
|
||||
System.out.printf("The retval is %d",createOrder);
|
||||
|
||||
this.ordersList.account=this.trader.getAccount();
|
||||
this.ordersList.updateModel();
|
||||
// this.ordersList.account=this.trader.getAccount();
|
||||
// this.ordersList.updateModel();
|
||||
|
||||
|
||||
}//GEN-LAST:event_buyButtonActionPerformed
|
||||
|
@ -23,20 +23,48 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="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>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="console" pref="334" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" 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>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<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>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -26,6 +26,7 @@
|
||||
package traders.ManTrader;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import sesim.Exchange.Account;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -36,17 +37,26 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
|
||||
/**
|
||||
* 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);
|
||||
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(){
|
||||
return this.console;
|
||||
}
|
||||
// public ManTraderConsole getConsole(){
|
||||
// return this.console;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 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
|
||||
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);
|
||||
|
||||
jTabbedPane1.addTab("Open Orders", ordersList);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(console, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.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();
|
||||
@ -108,7 +132,7 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog {
|
||||
/* Create and display the dialog */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
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() {
|
||||
@Override
|
||||
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
|
||||
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
|
||||
}
|
||||
|
@ -284,6 +284,7 @@ public class RandomTraderA extends AutoTraderBase {
|
||||
double money = getRandomAmmount(ad.getMoney(), buy_volume);
|
||||
|
||||
Quote q = se.getCurrentPrice();
|
||||
//q=se.getLastQuoete();
|
||||
double lp = q == null ? getStart() : q.price;
|
||||
|
||||
double limit;
|
||||
@ -323,8 +324,13 @@ public class RandomTraderA extends AutoTraderBase {
|
||||
|
||||
// double lp = 100.0; //se.getBestLimit(type);
|
||||
Quote q = se.getCurrentPrice();
|
||||
// q=se.getLastQuoete();
|
||||
double lp = q == null ? getStart() : q.price;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
double limit;
|
||||
limit = lp + getRandomAmmount(lp, sell_limit);
|
||||
se.roundMoney(limit);
|
||||
|
Loading…
Reference in New Issue
Block a user