Some improvements

This commit is contained in:
2017-02-02 18:39:55 +01:00
parent 3620fbcb04
commit df6c10ed59
28 changed files with 573 additions and 143 deletions

View File

@ -25,6 +25,7 @@
*/
package traders;
import gui.Globals;
import java.util.*;
import java.util.Random;
//import java.util.TimerTask;
@ -46,7 +47,7 @@ public class RandomTrader extends AutoTrader {
sesim.Exchange.Account a = se.getAccount(account_id);
long rc = this.doTrade();
return rc/80 ;
return rc ;
}
@ -66,7 +67,7 @@ public class RandomTrader extends AutoTrader {
public long timerTask() {
sesim.Exchange.Account a = se.getAccount(account_id);
long rc = this.doTrade();
return rc /100;
return rc / 1;
// return this.event();
}
@ -76,7 +77,7 @@ public class RandomTrader extends AutoTrader {
}
protected Action getAction() {
if (rand.nextInt(2) == 0) {
if (se.randNextInt(2) == 0) {
return Action.BUY;
} else {
return Action.SELL;
@ -84,7 +85,10 @@ public class RandomTrader extends AutoTrader {
}
double start = 0.1;
double getStart (){
return Globals.se.fairValue;
}
//Timer timer = new Timer();
@Override
@ -99,7 +103,7 @@ public class RandomTrader extends AutoTrader {
// config for this trader
//final private RandomTraderConfig_old myconfig;
// object to generate random numbers
final private Random rand = new Random();
//final private Random rand = new Random();
/**
* Get a (long) random number between min an max
@ -109,7 +113,8 @@ public class RandomTrader extends AutoTrader {
* @return the number
*/
protected double getRandom(double min, double max) {
double r = rand.nextDouble();
double r = se.randNextDouble();
return (max - min) * r + min;
}
@ -117,6 +122,7 @@ public class RandomTrader extends AutoTrader {
return (int) Math.round(getRandom(minmax[0], minmax[1]));
}
/**
*
* @param val
@ -124,6 +130,8 @@ public class RandomTrader extends AutoTrader {
* @return
*/
protected double getRandomAmmount(double val, Float[] minmax) {
//System.out.printf("RandomAmmount: %f (%f,%f)\n",val, minmax[0], minmax[1]);
double min = val * minmax[0] / 100.0;
double max = val * minmax[1] / 100.0;
return getRandom(min, max);
@ -163,11 +171,13 @@ public class RandomTrader extends AutoTrader {
double money = getRandomAmmount(ad.money, myconfig.buy_volume);
Quote q = se.getCurrentPrice();
double lp = q == null ? start : q.price;
double lp = q == null ? getStart() : q.price;
double limit;
limit = lp + getRandomAmmount(lp, myconfig.buy_limit);
// System.out.printf("MyLimit: %f\n",limit);
long volume = (long) (money / (limit * 1));
if (volume <= 0) {
@ -196,7 +206,7 @@ public class RandomTrader extends AutoTrader {
// double lp = 100.0; //se.getBestLimit(type);
Quote q = se.getCurrentPrice();
double lp = q == null ? start : q.price;
double lp = q == null ? getStart() : q.price;
double limit;
limit = lp + getRandomAmmount(lp, myconfig.sell_limit);

View File

@ -31,6 +31,7 @@ import javax.swing.JPanel;
import org.json.JSONArray;
import org.json.JSONObject;
import sesim.AutoTrader;
import sesim.AutoTraderBase;
import sesim.AutoTraderConfig;
import sesim.AutoTraderGui;
import sesim.Exchange;
@ -39,7 +40,7 @@ import sesim.Exchange;
*
* @author 7u83
*/
public class RandomTraderConfig implements AutoTraderConfig {
public class RandomTraderConfig extends AutoTraderBase implements AutoTraderConfig {
public Float[] sell_volume = {100f, 100f};
public Float[] sell_limit = {-0.1f, 0.10101f};
@ -154,4 +155,10 @@ public class RandomTraderConfig implements AutoTraderConfig {
wait_after_buy = to_integer(cfg.getJSONArray(WAIT_AFTER_BUY));
}
@Override
public boolean getDevelStatus() {
return false;
}
}

View File

@ -67,5 +67,10 @@ public class SuperTraderConfig implements AutoTraderConfig{
public void putConfig(JSONObject cfg) {
}
@Override
public boolean getDevelStatus() {
return true;
}
}

View File

@ -34,13 +34,13 @@ import sesim.Exchange;
*
* @author 7u83 <7u83@mail.ru>
*/
public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTraderConfig{
public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTraderConfig {
@Override
public AutoTrader createTrader(Exchange se, JSONObject cfg, double money, double shares) {
return new traders.SwitchingTrader(se, money, shares, this);
}
public SwitchingTraderConfig() {
@ -55,9 +55,15 @@ public class SwitchingTraderConfig extends RandomTraderConfig implements AutoTra
buy_wait = new Integer[]{1, 5};
wait_after_buy = new Integer[]{1, 5};
}
@Override
public String getDisplayName(){
public String getDisplayName() {
return "SwitchingTrader";
}
@Override
public boolean getDevelStatus() {
return true;
}
}