diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index 7f10a69..adf208d 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -42,7 +42,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver, Scrollab public final void initChart(){ // data = new OHLCData(60000*30); - data = new OHLCData(60000); + data = new OHLCData(60000*1); } /** diff --git a/src/main/java/gui/AskBook.java b/src/main/java/gui/AskBook.java index c86ffe8..c8d1c29 100644 --- a/src/main/java/gui/AskBook.java +++ b/src/main/java/gui/AskBook.java @@ -36,7 +36,7 @@ public class AskBook extends OrderBook { @Override ArrayList getOrderBook() { - return Globals.se.getOrderBook(OrderType.ASK,40); + return Globals.se.getOrderBook(OrderType.SELLLIMIT,40); } @Override @@ -48,7 +48,7 @@ public class AskBook extends OrderBook { if (Globals.se == null) { return; } - Globals.se.addBookReceiver(OrderType.ASK, this); + Globals.se.addBookReceiver(OrderType.SELLLIMIT, this); } diff --git a/src/main/java/gui/BidBook.java b/src/main/java/gui/BidBook.java index fde7e35..a4743f6 100644 --- a/src/main/java/gui/BidBook.java +++ b/src/main/java/gui/BidBook.java @@ -36,13 +36,13 @@ public class BidBook extends OrderBook { @Override ArrayList getOrderBook() { - return Globals.se.getOrderBook(OrderType.BID, 40); + return Globals.se.getOrderBook(OrderType.BUYLIMIT, 40); } public BidBook() { if (Globals.se == null) { return; } - Globals.se.addBookReceiver(OrderType.BID, this); + Globals.se.addBookReceiver(OrderType.BUYLIMIT, this); } } diff --git a/src/main/java/gui/OrdersList.form b/src/main/java/gui/OrdersList.form new file mode 100644 index 0000000..5fc287f --- /dev/null +++ b/src/main/java/gui/OrdersList.form @@ -0,0 +1,54 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
diff --git a/src/main/java/gui/OrdersList.java b/src/main/java/gui/OrdersList.java new file mode 100644 index 0000000..91d95aa --- /dev/null +++ b/src/main/java/gui/OrdersList.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2017, tobias + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package gui; + +import java.util.function.BiConsumer; +import javax.swing.table.DefaultTableModel; +import sesim.Exchange.Account; + +/** + * + * @author tobias + */ +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); + + } + }); + + + + + } + + /** + * Creates new form OrdersList + */ + public OrdersList() { + initComponents(); + model = (DefaultTableModel) order_table.getModel(); + updateModel(); + } + + /** + * 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + order_table = new javax.swing.JTable(); + + 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} + }, + new String [] { + "ID", "Type", "Price", "Volume" + } + ) { + Class[] types = new Class [] { + java.lang.Long.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + }); + jScrollPane1.setViewportView(order_table); + + 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, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTable order_table; + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/sesim/Exchange.java b/src/main/java/sesim/Exchange.java index d2c850d..1705dc4 100644 --- a/src/main/java/sesim/Exchange.java +++ b/src/main/java/sesim/Exchange.java @@ -50,7 +50,7 @@ public class Exchange { * Definition of order types */ public enum OrderType { - BID, ASK + BUYLIMIT, SELLLIMIT, STOPLOSS, STOPBUY } IDGenerator account_id = new IDGenerator(); @@ -96,11 +96,15 @@ public class Exchange { public double getMoney() { return money; } - - public AutoTrader getOwner(){ + + public AutoTrader getOwner() { return owner; } + public Map getOrders() { + return orders; + } + } public void createTraders(JSONArray traderdefs) { @@ -136,10 +140,10 @@ public class Exchange { public int compare(Order left, Order right) { double d; switch (this.type) { - case BID: + case BUYLIMIT: d = right.limit - left.limit; break; - case ASK: + case SELLLIMIT: d = left.limit - right.limit; break; default: @@ -164,7 +168,6 @@ public class Exchange { return 0; -// return left.id < right.id ? -1 : 1; } } @@ -181,7 +184,7 @@ public class Exchange { private final double initial_volume; private long id; long created; - private Account account; + private final Account account; Order(Account account, OrderType type, double volume, double limit) { id = order_id.getNext(); @@ -317,8 +320,8 @@ public class Exchange { public Quote getCurrentPrice() { - SortedSet bid = order_books.get(OrderType.BID); - SortedSet ask = order_books.get(OrderType.ASK); + SortedSet bid = order_books.get(OrderType.BUYLIMIT); + SortedSet ask = order_books.get(OrderType.SELLLIMIT); Quote q = null; @@ -366,9 +369,9 @@ public class Exchange { private ArrayList selectBookReceiver(OrderType t) { switch (t) { - case ASK: + case SELLLIMIT: return ask_bookreceivers; - case BID: + case BUYLIMIT: return bid_bookreceivers; } return null; @@ -411,8 +414,8 @@ public class Exchange { } // long time = 0; - double theprice = 12.9; - long orderid = 1; + //double theprice = 12.9; +// long orderid = 1; double lastprice = 100.0; long lastsvolume; @@ -476,7 +479,7 @@ public class Exchange { } tradelock.unlock(); - this.updateBookReceivers(OrderType.BID); + this.updateBookReceivers(OrderType.BUYLIMIT); return ret; } @@ -525,8 +528,8 @@ public class Exchange { */ public void executeOrders() { - SortedSet bid = order_books.get(OrderType.BID); - SortedSet ask = order_books.get(OrderType.ASK); + SortedSet bid = order_books.get(OrderType.BUYLIMIT); + SortedSet ask = order_books.get(OrderType.SELLLIMIT); double volume_total = 0; double money_total = 0; @@ -593,8 +596,7 @@ public class Exchange { * @return */ public long createOrder(double account_id, OrderType type, double volume, double limit) { - - + Account a = accounts.get(account_id); if (a == null) { return -1; @@ -614,8 +616,8 @@ public class Exchange { this.executeOrders(); tradelock.unlock(); - this.updateBookReceivers(OrderType.ASK); - this.updateBookReceivers(OrderType.BID); + this.updateBookReceivers(OrderType.SELLLIMIT); + this.updateBookReceivers(OrderType.BUYLIMIT); return o.id; } diff --git a/src/main/java/sesim/Order.java b/src/main/java/sesim/Order.java new file mode 100644 index 0000000..a135b01 --- /dev/null +++ b/src/main/java/sesim/Order.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, tobias + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package sesim; + +/** + * + * @author tobias + */ +public class Order { + +} diff --git a/src/main/java/traders/ManTrader/ManTrader.java b/src/main/java/traders/ManTrader/ManTrader.java index ffce76c..3bf4908 100644 --- a/src/main/java/traders/ManTrader/ManTrader.java +++ b/src/main/java/traders/ManTrader/ManTrader.java @@ -26,6 +26,7 @@ package traders.ManTrader; import gui.Globals; +import gui.OrdersList; import org.json.JSONObject; import sesim.AutoTrader; import sesim.AutoTraderBase; @@ -55,9 +56,12 @@ public class ManTrader extends AutoTraderBase implements AutoTraderConfig { public void start() { se.timer.startTimerEvent(this, 0); consoleDialog = new ManTraderConsoleDialog(Globals.frame, false); + + // consoleDialog. rdersList1.account=trader.getAccount(); consoleDialog.getConsole().trader=this; + consoleDialog.setVisible(true); } @@ -65,6 +69,8 @@ public class ManTrader extends AutoTraderBase implements AutoTraderConfig { @Override public long timerTask() { System.out.printf("TimerTask\n"); + OrdersList ol = this.consoleDialog.getConsole().getOrderListPanel(); + ol.updateModel(); return 1000; } diff --git a/src/main/java/traders/ManTrader/ManTraderConsole.form b/src/main/java/traders/ManTrader/ManTraderConsole.form index bca620b..9f7a7b8 100644 --- a/src/main/java/traders/ManTrader/ManTraderConsole.form +++ b/src/main/java/traders/ManTrader/ManTraderConsole.form @@ -16,16 +16,16 @@ - + - - + + - + @@ -43,7 +43,7 @@ - + @@ -54,13 +54,13 @@ - + - + @@ -81,27 +81,6 @@ - - - - - - - - - - - - - - - -
-
-
-
-
-
@@ -152,5 +131,7 @@ + +
diff --git a/src/main/java/traders/ManTrader/ManTraderConsole.java b/src/main/java/traders/ManTrader/ManTraderConsole.java index 4f59abb..5865f6a 100644 --- a/src/main/java/traders/ManTrader/ManTraderConsole.java +++ b/src/main/java/traders/ManTrader/ManTraderConsole.java @@ -25,6 +25,8 @@ */ package traders.ManTrader; +import gui.OrdersList; +import javax.swing.JTable; import sesim.AutoTrader; import sesim.Exchange; @@ -35,13 +37,17 @@ import sesim.Exchange; public class ManTraderConsole extends javax.swing.JPanel { public AutoTrader trader; - + + public OrdersList getOrderListPanel(){ + return this.ordersList1; + } /** * Creates new form ManTraderConsole */ public ManTraderConsole() { initComponents(); + // this.ordersList1.account=trader.getAccount(); } /** @@ -53,8 +59,6 @@ public class ManTraderConsole extends javax.swing.JPanel { // //GEN-BEGIN:initComponents private void initComponents() { - jScrollPane1 = new javax.swing.JScrollPane(); - jTable1 = new javax.swing.JTable(); limitSpinner = new javax.swing.JSpinner(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); @@ -63,19 +67,7 @@ public class ManTraderConsole extends javax.swing.JPanel { sellButton = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); moneyText = new javax.swing.JLabel(); - - jTable1.setModel(new javax.swing.table.DefaultTableModel( - new Object [][] { - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null}, - {null, null, null, null} - }, - new String [] { - "Title 1", "Title 2", "Title 3", "Title 4" - } - )); - jScrollPane1.setViewportView(jTable1); + ordersList1 = new gui.OrdersList(); limitSpinner.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, null, 1.0d)); @@ -107,15 +99,15 @@ public class ManTraderConsole extends javax.swing.JPanel { this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(ordersList1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(buyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(sellButton, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2) @@ -129,19 +121,19 @@ public class ManTraderConsole extends javax.swing.JPanel { .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(moneyText, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addGap(0, 8, Short.MAX_VALUE))) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(ordersList1, 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) .addComponent(moneyText)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(limitSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -163,7 +155,7 @@ public class ManTraderConsole extends javax.swing.JPanel { System.out.printf("Should buy: %f %f\n",volume,limit); - long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.BID, volume, limit); + long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.BUYLIMIT, volume, limit); System.out.printf("The retval is %d",createOrder); @@ -175,7 +167,7 @@ public class ManTraderConsole extends javax.swing.JPanel { System.out.printf("Should buy: %f %f\n",volume,limit); - long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.ASK, volume, limit); + long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), Exchange.OrderType.SELLLIMIT, volume, limit); System.out.printf("The retval is %d",createOrder); }//GEN-LAST:event_sellButtonActionPerformed @@ -185,10 +177,9 @@ public class ManTraderConsole extends javax.swing.JPanel { private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JTable jTable1; private javax.swing.JSpinner limitSpinner; private javax.swing.JLabel moneyText; + private gui.OrdersList ordersList1; private javax.swing.JButton sellButton; private javax.swing.JSpinner volumeSpinner; // End of variables declaration//GEN-END:variables diff --git a/src/main/java/traders/ManTrader/ManTraderConsoleDialog.java b/src/main/java/traders/ManTrader/ManTraderConsoleDialog.java index 9a18f0d..6fb5e7b 100644 --- a/src/main/java/traders/ManTrader/ManTraderConsoleDialog.java +++ b/src/main/java/traders/ManTrader/ManTraderConsoleDialog.java @@ -39,7 +39,10 @@ public class ManTraderConsoleDialog extends javax.swing.JDialog { public ManTraderConsoleDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); + } + + public ManTraderConsole getConsole(){ return this.console; diff --git a/src/main/java/traders/RandomTrader.java b/src/main/java/traders/RandomTrader.java index 428b28f..66b35de 100644 --- a/src/main/java/traders/RandomTrader.java +++ b/src/main/java/traders/RandomTrader.java @@ -166,7 +166,7 @@ public class RandomTrader extends AutoTrader { RandomTraderConfig myconfig = (RandomTraderConfig) this.config; AccountData ad = this.se.getAccountData(account_id); - OrderType type = OrderType.BID; + OrderType type = OrderType.BUYLIMIT; if (ad == null || myconfig == null) { //System.out.printf("%s: myconf = 0 \n", this.getName()); @@ -226,7 +226,7 @@ public class RandomTrader extends AutoTrader { RandomTraderConfig myconfig = (RandomTraderConfig) this.config; AccountData ad = this.se.getAccountData(account_id); - OrderType type = OrderType.ASK; + OrderType type = OrderType.SELLLIMIT; //System.out.printf("%s: calling rand for volume\n", this.getName()); // how much money we ant to envest?