Moved Order class out of Exchange class into a separate file.
Use sesim.order now instead.
This commit is contained in:
parent
5e6df1f3c5
commit
f4d4ba2c46
@ -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=
|
||||
|
@ -26,7 +26,9 @@
|
||||
package gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Exchange.OrderType;
|
||||
import sesim.Order;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -27,6 +27,7 @@ package gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import sesim.Exchange.*;
|
||||
import sesim.Order;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -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;
|
||||
|
||||
|
@ -36,6 +36,7 @@ import java.awt.*;
|
||||
import java.text.DecimalFormat;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import sesim.Order;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user