Some refactoring
This commit is contained in:
parent
90acb02a90
commit
f6879c36fe
@ -1,4 +1,4 @@
|
||||
#Tue, 10 Oct 2017 11:01:16 +0200
|
||||
#Sat, 14 Oct 2017 08:11:09 +0200
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -31,12 +31,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* Implements a trading account
|
||||
*/
|
||||
public class Account implements Comparable {
|
||||
|
||||
static String default_symbold = "DFLT";
|
||||
|
||||
private Exchange.AccountListener listener = null;
|
||||
|
||||
protected final double id;
|
||||
protected double shares;
|
||||
protected double money;
|
||||
private double shares;
|
||||
private double money;
|
||||
protected AutoTraderInterface owner;
|
||||
|
||||
protected final ConcurrentHashMap<Long , Order> orders;
|
||||
@ -64,6 +66,31 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
return shares;
|
||||
}
|
||||
|
||||
protected void setShares(double shares){
|
||||
this.shares = shares;
|
||||
}
|
||||
|
||||
protected void addShares(double shares){
|
||||
this.shares = this.shares+shares;
|
||||
}
|
||||
|
||||
protected void addShares(String symbol, double shares){
|
||||
Double d = this.sharesm.get(symbol);
|
||||
d+=shares;
|
||||
this.sharesm.put(symbol, d);
|
||||
// (this.sharesm.get(symbol))+=shares;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void addMoney(double money){
|
||||
this.money+=money;
|
||||
}
|
||||
|
||||
protected void setMoney(double money){
|
||||
this.money=money;
|
||||
}
|
||||
|
||||
public double getShares(String symbol){
|
||||
return sharesm.get(symbol);
|
||||
}
|
||||
|
@ -159,7 +159,8 @@ public class Exchange {
|
||||
@Override
|
||||
public void accept(Object t, Object u) {
|
||||
Account a = (Account) u;
|
||||
a.money += 20000.0;
|
||||
// a.money += 20000.0;
|
||||
a.addMoney(20000.0);
|
||||
|
||||
}
|
||||
|
||||
@ -172,7 +173,8 @@ public class Exchange {
|
||||
@Override
|
||||
public void accept(Object t, Object u) {
|
||||
Account a = (Account) u;
|
||||
a.money = 20000.0;
|
||||
// a.money = 20000.0;
|
||||
a.setMoney(20000.0);
|
||||
|
||||
}
|
||||
|
||||
@ -719,10 +721,16 @@ public class Exchange {
|
||||
}
|
||||
|
||||
private void transferMoneyAndShares(Account src, Account dst, double money, double shares) {
|
||||
src.money -= money;
|
||||
dst.money += money;
|
||||
src.shares -= shares;
|
||||
dst.shares += shares;
|
||||
// src.money -= money;
|
||||
src.addMoney(-money);
|
||||
|
||||
// dst.money += money;
|
||||
dst.addMoney(money);
|
||||
// src.shares -= shares;
|
||||
src.addShares(-shares);
|
||||
// dst.shares += shares;
|
||||
|
||||
src.addShares(shares);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user