Included stock symbol in order creation.
This commit is contained in:
parent
0c584c6046
commit
9b86599f03
@ -1,4 +1,4 @@
|
|||||||
#Sun, 10 Dec 2017 09:32:20 +0100
|
#Sun, 10 Dec 2017 12:50:27 +0100
|
||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -58,6 +58,11 @@ public class Exchange {
|
|||||||
return getStock(DEFAULT_STOCK);
|
return getStock(DEFAULT_STOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDefaultStockSymbol(){
|
||||||
|
return DEFAULT_STOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ConcurrentLinkedQueue<Order> order_queue = new ConcurrentLinkedQueue();
|
ConcurrentLinkedQueue<Order> order_queue = new ConcurrentLinkedQueue();
|
||||||
|
|
||||||
private double money_df = 10000;
|
private double money_df = 10000;
|
||||||
@ -698,12 +703,14 @@ public class Exchange {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// long time = 0;
|
|
||||||
//double theprice = 12.9;
|
/**
|
||||||
// long orderid = 1;
|
*
|
||||||
//double lastprice = 100.0;
|
* @param stock
|
||||||
// long lastsvolume;
|
* @param type
|
||||||
// private final Locker tradelock = new Locker();
|
* @param depth
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public ArrayList<Order> getOrderBook(Stock stock, OrderType type, int depth) {
|
public ArrayList<Order> getOrderBook(Stock stock, OrderType type, int depth) {
|
||||||
|
|
||||||
SortedSet<Order> book = stock.order_books.get(type);
|
SortedSet<Order> book = stock.order_books.get(type);
|
||||||
@ -735,7 +742,10 @@ public class Exchange {
|
|||||||
return getOrderBook(getDefaultStock(),type,depth);
|
return getOrderBook(getDefaultStock(),type,depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Quote getLastQuoete() {
|
public Quote getLastQuoete() {
|
||||||
if (this.quoteHistory.isEmpty()) {
|
if (this.quoteHistory.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
@ -857,6 +867,7 @@ public class Exchange {
|
|||||||
removeOrderIfExecuted(getDefaultStock(),o);
|
removeOrderIfExecuted(getDefaultStock(),o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void checkSLOrders(Stock stock, double price) {
|
void checkSLOrders(Stock stock, double price) {
|
||||||
SortedSet<Order> sl = stock.order_books.get(OrderType.STOPLOSS);
|
SortedSet<Order> sl = stock.order_books.get(OrderType.STOPLOSS);
|
||||||
SortedSet<Order> ask = stock.order_books.get(OrderType.SELLLIMIT);
|
SortedSet<Order> ask = stock.order_books.get(OrderType.SELLLIMIT);
|
||||||
@ -1054,17 +1065,23 @@ public class Exchange {
|
|||||||
* @param limit
|
* @param limit
|
||||||
* @return order_id
|
* @return order_id
|
||||||
*/
|
*/
|
||||||
public long createOrder(double account_id, OrderType type, double volume, double limit) {
|
public long createOrder(double account_id,
|
||||||
|
String stocksymbol, OrderType type, double volume, double limit) {
|
||||||
|
|
||||||
|
|
||||||
|
Stock stock = this.getStock(stocksymbol);
|
||||||
|
|
||||||
Account a = accounts.get(account_id);
|
Account a = accounts.get(account_id);
|
||||||
if (a == null) {
|
if (a == null) {
|
||||||
System.out.printf("Order not places account\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Order o = new Order(order_id_generator.getNext(),
|
Order o = new Order(order_id_generator.getNext(),
|
||||||
timer.currentTimeMillis(),
|
timer.currentTimeMillis(),
|
||||||
a, type, roundShares(volume), roundMoney(limit));
|
a, type, roundShares(volume), roundMoney(limit));
|
||||||
|
|
||||||
|
o.stock=stock;
|
||||||
|
|
||||||
if (o.volume <= 0 || o.limit <= 0) {
|
if (o.volume <= 0 || o.limit <= 0) {
|
||||||
|
|
||||||
switch (o.type) {
|
switch (o.type) {
|
||||||
@ -1077,12 +1094,10 @@ public class Exchange {
|
|||||||
buy_failed++;
|
buy_failed++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// System.out.printf("Order ffailed %f %f \n",o.volume,o.limit);
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.printf("Getting executor in create Order\n", Thread.currentThread().getId());
|
|
||||||
synchronized (executor) {
|
synchronized (executor) {
|
||||||
|
|
||||||
//num_orders++;
|
//num_orders++;
|
||||||
|
@ -59,4 +59,6 @@ public class Stock {
|
|||||||
|
|
||||||
protected final HashMap<Order.OrderType, SortedSet<Order>> order_books;
|
protected final HashMap<Order.OrderType, SortedSet<Order>> order_books;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ public class CreateOrderDialog extends javax.swing.JDialog {
|
|||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Globals.se.createOrder(account.getID(), type, volume, limit);
|
Globals.se.createOrder(account.getID(), Globals.se.getDefaultStockSymbol(), type, volume, limit);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
|
@ -176,7 +176,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
|||||||
|
|
||||||
System.out.printf("Should buy: %f %f\n",volume,limit);
|
System.out.printf("Should buy: %f %f\n",volume,limit);
|
||||||
|
|
||||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), OrderType.BUYLIMIT, volume, limit);
|
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||||
|
trader.getSE().getDefaultStockSymbol(),
|
||||||
|
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();
|
||||||
@ -191,7 +193,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
|||||||
|
|
||||||
System.out.printf("Should sell: %f %f\n",volume,limit);
|
System.out.printf("Should sell: %f %f\n",volume,limit);
|
||||||
|
|
||||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), OrderType.SELLLIMIT, volume, limit);
|
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||||
|
trader.getSE().getDefaultStockSymbol(),
|
||||||
|
OrderType.SELLLIMIT, volume, limit);
|
||||||
System.out.printf("The retval is %d",createOrder);
|
System.out.printf("The retval is %d",createOrder);
|
||||||
}//GEN-LAST:event_sellButtonActionPerformed
|
}//GEN-LAST:event_sellButtonActionPerformed
|
||||||
|
|
||||||
@ -201,7 +205,9 @@ public class ManTraderConsole extends javax.swing.JPanel {
|
|||||||
|
|
||||||
System.out.printf("Should stoploss: %f %f\n",volume,limit);
|
System.out.printf("Should stoploss: %f %f\n",volume,limit);
|
||||||
|
|
||||||
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(), OrderType.STOPLOSS, volume, limit);
|
long createOrder = trader.getSE().createOrder(trader.getAccount().getID(),
|
||||||
|
trader.getSE().getDefaultStockSymbol(),
|
||||||
|
OrderType.STOPLOSS, volume, limit);
|
||||||
System.out.printf("The retval is %d",createOrder);
|
System.out.printf("The retval is %d",createOrder);
|
||||||
}//GEN-LAST:event_stopLossButtonActionPerformed
|
}//GEN-LAST:event_stopLossButtonActionPerformed
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
// System.out.printf("Buy Order wont work\n");
|
// System.out.printf("Buy Order wont work\n");
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
long rc = se.createOrder(account_id, type, volume, limit);
|
long rc = se.createOrder(account_id, se.getDefaultStockSymbol(),type, volume, limit);
|
||||||
|
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ public class RandomTraderA extends AutoTraderBase implements AccountListener {
|
|||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
|
// System.out.printf("Create a Sell Order %f %f!!!!\n", volume, limit);
|
||||||
long rc = se.createOrder(account_id, type, volume, limit);
|
long rc = se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||||
return rc != -1;
|
return rc != -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ public class RandomTraderB extends AutoTraderBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
se.createOrder(account_id, type, volume, limit);
|
se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ public class RandomTraderB extends AutoTraderBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
se.createOrder(account_id, type, volume, limit);
|
se.createOrder(account_id, se.getDefaultStockSymbol(), type, volume, limit);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user