From f4d4ba2c46fe1e2ce40fa44816a5bd8ab3e40139 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@maiol.ru> Date: Sun, 8 Oct 2017 19:43:43 +0200 Subject: [PATCH] Moved Order class out of Exchange class into a separate file. Use sesim.order now instead. --- nbproject/project.properties | 2 +- src/gui/AskBook.java | 4 +- src/gui/BidBook.java | 1 + src/gui/OpenOrdersList.java | 2 +- src/gui/OrderBook.java | 1 + src/gui/orderbook/OrderBook.java | 2 +- src/sesim/Exchange.java | 79 +------------------------- src/sesim/Order.java | 84 ++++++++++++++++++++++++++-- src/sesim/Stock.java | 11 ++++ src/traders/ManTrader/ManTrader.java | 3 +- src/traders/RandomTraderA.java | 3 +- 11 files changed, 105 insertions(+), 87 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index d77fc68..8fef174 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 08 Oct 2017 19:22:43 +0200 +#Sun, 08 Oct 2017 19:42:34 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/gui/AskBook.java b/src/gui/AskBook.java index c8d1c29..dcfeb2c 100644 --- a/src/gui/AskBook.java +++ b/src/gui/AskBook.java @@ -26,7 +26,9 @@ package gui; import java.util.ArrayList; -import sesim.Exchange.*; +import sesim.Exchange.OrderType; +import sesim.Order; + /** * diff --git a/src/gui/BidBook.java b/src/gui/BidBook.java index a4743f6..b012812 100644 --- a/src/gui/BidBook.java +++ b/src/gui/BidBook.java @@ -27,6 +27,7 @@ package gui; import java.util.ArrayList; import sesim.Exchange.*; +import sesim.Order; /** * diff --git a/src/gui/OpenOrdersList.java b/src/gui/OpenOrdersList.java index 8b373d5..f0a9ef2 100644 --- a/src/gui/OpenOrdersList.java +++ b/src/gui/OpenOrdersList.java @@ -35,7 +35,7 @@ import java.util.function.BiConsumer; import javax.swing.table.DefaultTableModel; import sesim.Exchange; import sesim.Exchange.Account; -import sesim.Exchange.Order; +import sesim.Order; import sesim.Exchange.OrderType; import traders.ManTrader.CreateOrderDialog; diff --git a/src/gui/OrderBook.java b/src/gui/OrderBook.java index 12b31e1..d9e6c16 100644 --- a/src/gui/OrderBook.java +++ b/src/gui/OrderBook.java @@ -36,6 +36,7 @@ import java.awt.*; import java.text.DecimalFormat; import javax.swing.*; import javax.swing.table.*; +import sesim.Order; /** * diff --git a/src/gui/orderbook/OrderBook.java b/src/gui/orderbook/OrderBook.java index 18142f9..2efe6fe 100644 --- a/src/gui/orderbook/OrderBook.java +++ b/src/gui/orderbook/OrderBook.java @@ -41,7 +41,7 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import sesim.Exchange; -import sesim.Exchange.Order; +import sesim.Order; import sesim.Exchange.OrderType; /** diff --git a/src/sesim/Exchange.java b/src/sesim/Exchange.java index d633d0c..ddff3e0 100644 --- a/src/sesim/Exchange.java +++ b/src/sesim/Exchange.java @@ -353,81 +353,6 @@ public class Exchange { IDGenerator order_id_generator = new IDGenerator(); - public class Order { - - OrderStatus status; - OrderType type; - private double limit; - private double volume; - - private final double initial_volume; - private final long id; - private final long created; - - private final Account account; - - double cost; - - Order(Account account, OrderType type, double volume, double limit) { - id = order_id_generator.getNext(); - this.account = account; - this.type = type; - this.limit = roundMoney(limit); - this.volume = roundShares(volume); - this.initial_volume = this.volume; - this.created = timer.currentTimeMillis(); - this.status = OrderStatus.OPEN; - this.cost = 0; - } - - public long getID() { - return id; - } - - public double getVolume() { - return volume; - } - - public double getLimit() { - return limit; - } - - public OrderType getType() { - return type; - } - - public double getExecuted() { - return initial_volume - volume; - } - - public double getInitialVolume() { - return initial_volume; - } - - public double getCost() { - return cost; - } - - public double getAvaragePrice() { - double e = getExecuted(); - if (e <= 0) { - return -1; - } - return cost / e; - } - - public Account getAccount() { - return account; - } - - public OrderStatus getOrderStatus() { - return status; - } - - public long getCreated() { - return created; - } - } /** * Histrory of quotes @@ -1168,7 +1093,9 @@ public class Exchange { - Order o = new Order(a, type, volume, limit); + Order o = new Order(order_id_generator.getNext(), + timer.currentTimeMillis(), + a, type, roundShares(volume), roundMoney(limit)); if (o.volume <= 0 || o.limit <= 0) { switch (o.type) { diff --git a/src/sesim/Order.java b/src/sesim/Order.java index a135b01..da9e28a 100644 --- a/src/sesim/Order.java +++ b/src/sesim/Order.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, tobias + * Copyright (c) 2017, 7u83 <7u83@mail.ru> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,8 +27,82 @@ package sesim; /** * - * @author tobias + * @author 7u83 <7u83@mail.ru> */ -public class Order { - -} + public class Order { + + Stock stock; + Exchange.OrderStatus status; + Exchange.OrderType type; + protected double limit; + protected double volume; + + protected final double initial_volume; + protected final long id; + protected final long created; + + protected final Exchange.Account account; + + double cost; + + Order(long id, long created, Exchange.Account account, Exchange.OrderType type, double volume, double limit) { + //id = order_id_generator.getNext(); + this.id=id; + this.account = account; + this.type = type; + this.limit = limit; + this.volume = volume; + this.initial_volume = this.volume; + this.created = created; + this.status = Exchange.OrderStatus.OPEN; + this.cost = 0; + } + + public long getID() { + return id; + } + + public double getVolume() { + return volume; + } + + public double getLimit() { + return limit; + } + + public Exchange.OrderType getType() { + return type; + } + + public double getExecuted() { + return initial_volume - volume; + } + + public double getInitialVolume() { + return initial_volume; + } + + public double getCost() { + return cost; + } + + public double getAvaragePrice() { + double e = getExecuted(); + if (e <= 0) { + return -1; + } + return cost / e; + } + + public Exchange.Account getAccount() { + return account; + } + + public Exchange.OrderStatus getOrderStatus() { + return status; + } + + public long getCreated() { + return created; + } + } diff --git a/src/sesim/Stock.java b/src/sesim/Stock.java index 3fd8d2f..df3ce07 100644 --- a/src/sesim/Stock.java +++ b/src/sesim/Stock.java @@ -30,5 +30,16 @@ package sesim; * @author 7u83 <7u83@mail.ru> */ public class Stock { + private String symbol; + private String name; + + String getSymbol(){ + return symbol; + } + + String getName(){ + return name; + } + } diff --git a/src/traders/ManTrader/ManTrader.java b/src/traders/ManTrader/ManTrader.java index ad8ae5c..d05b712 100644 --- a/src/traders/ManTrader/ManTrader.java +++ b/src/traders/ManTrader/ManTrader.java @@ -38,6 +38,7 @@ import sesim.AutoTraderInterface; import sesim.Exchange; import sesim.Exchange.AccountListener; import sesim.Exchange.OrderStatus; +import sesim.Order; /** * @@ -114,7 +115,7 @@ public class ManTrader extends AutoTraderBase implements AccountListener, AutoTr } @Override - public void accountUpdated(Exchange.Account a, Exchange.Order o) { + public void accountUpdated(Exchange.Account a, Order o) { //this.consoleDialog.cons //System.out.printf("AccountListener called\n"); diff --git a/src/traders/RandomTraderA.java b/src/traders/RandomTraderA.java index 19f66fe..73d1d0e 100644 --- a/src/traders/RandomTraderA.java +++ b/src/traders/RandomTraderA.java @@ -38,6 +38,7 @@ import sesim.Exchange.Account; import sesim.Exchange.AccountListener; import sesim.Exchange.OrderStatus; import sesim.Exchange.OrderType; +import sesim.Order; import sesim.Quote; /** @@ -202,7 +203,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener { sesim.Scheduler.TimerTaskDef timerTask; @Override - public void accountUpdated(Account a, Exchange.Order o) { + public void accountUpdated(Account a, Order o) { setStatus("Account update -%s ", o.getOrderStatus().toString()); setStatus("In Task: %s", Boolean.toString(this.intask)); //System.out.printf("Order updated %s %d\n", o.getOrderStatus().toString(), Thread.currentThread().getId());