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=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
|
@ -32,11 +32,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
*/
|
*/
|
||||||
public class Account implements Comparable {
|
public class Account implements Comparable {
|
||||||
|
|
||||||
|
static String default_symbold = "DFLT";
|
||||||
|
|
||||||
private Exchange.AccountListener listener = null;
|
private Exchange.AccountListener listener = null;
|
||||||
|
|
||||||
protected final double id;
|
protected final double id;
|
||||||
protected double shares;
|
private double shares;
|
||||||
protected double money;
|
private double money;
|
||||||
protected AutoTraderInterface owner;
|
protected AutoTraderInterface owner;
|
||||||
|
|
||||||
protected final ConcurrentHashMap<Long , Order> orders;
|
protected final ConcurrentHashMap<Long , Order> orders;
|
||||||
@ -64,6 +66,31 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
return shares;
|
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){
|
public double getShares(String symbol){
|
||||||
return sharesm.get(symbol);
|
return sharesm.get(symbol);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,8 @@ public class Exchange {
|
|||||||
@Override
|
@Override
|
||||||
public void accept(Object t, Object u) {
|
public void accept(Object t, Object u) {
|
||||||
Account a = (Account) 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
|
@Override
|
||||||
public void accept(Object t, Object u) {
|
public void accept(Object t, Object u) {
|
||||||
Account a = (Account) 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) {
|
private void transferMoneyAndShares(Account src, Account dst, double money, double shares) {
|
||||||
src.money -= money;
|
// src.money -= money;
|
||||||
dst.money += money;
|
src.addMoney(-money);
|
||||||
src.shares -= shares;
|
|
||||||
dst.shares += shares;
|
// 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