Interface improved

This commit is contained in:
7u83
2017-01-13 01:55:43 +01:00
parent bcaf3a2aeb
commit 192e4ecaa8
7 changed files with 168 additions and 159 deletions

View File

@ -76,6 +76,21 @@ public class RandomTrader extends AutoTrader {
this.config = new RandomTraderConfig();
}
}
protected enum Action {
BUY,SELL,RANDOM
}
protected Action getAction() {
if (rand.nextInt(2)==0){
return Action.BUY;
}
else{
return Action.SELL;
}
}
@Override
@ -156,7 +171,8 @@ public class RandomTrader extends AutoTrader {
double money = getRandomAmmount(ad.money, myconfig.buy_volume);
Quote q = se.getCurrentPrice();
double lp = q == null ? 100.0 : q.price;
double lp = q == null ? 0.0 : q.price;
double limit;
@ -192,16 +208,16 @@ public class RandomTrader extends AutoTrader {
// double lp = 100.0; //se.getBestLimit(type);
Quote q = se.getCurrentPrice();
double lp = q == null ? 100.0 : q.price;
double lp = q == null ? 0.1 : q.price;
double limit;
limit = lp + getRandomAmmount(lp, myconfig.sell_limit);
// long volume = (long) (money / (limit * 1));
// if (volume <= 0) {
// return false;
// }
if (volume <= 0) {
return 0;
}
// System.out.print("Volume is:"+volume+"\n");
// System.out.print("My Ammount is: "+volume+" My limit si:"+limit+ "\n");
@ -219,20 +235,20 @@ public class RandomTrader extends AutoTrader {
long doTrade(){
cancelOrders();
int what = rand.nextInt(2);
if (what==0)
return doBuy();
else
return doSell();
Action a = getAction();
switch (a){
case BUY:
return doBuy();
case SELL:
return doSell();
}
return 0;
}
protected NextEvent createOrder() {
return new NextEvent(Event.CANCEL, 3000);
}
private static class TimerTaskImpl extends TimerTask {
RandomTrader trader;

View File

@ -25,6 +25,7 @@
*/
package traders;
import sesim.AutoTrader;
import sesim.AutoTraderConfig;
import sesim.Exchange;
@ -34,18 +35,18 @@ import sesim.Exchange;
*/
public class RandomTraderConfig extends AutoTraderConfig {
public float[] sell_volume = {50, 100};
public float[] sell_limit = {-15, 15};
public float[] sell_volume = {100, 100};
public float[] sell_limit = {-1, 0};
public int[] sell_order_wait = {15, 33};
public int[] wait_after_sell = {10, 30};
public float[] buy_volume = {50, 100};
public float[] buy_limit = {-15, 15};
public float[] buy_volume = {100, 100};
public float[] buy_limit = {0, 1};
public int[] buy_order_wait = {15, 33};
public int[] wait_after_buy = {10, 30};
@Override
public RandomTrader createTrader(Exchange se, double money, double shares) {
public AutoTrader createTrader(Exchange se, double money, double shares) {
return new traders.RandomTrader(se, money, shares, this);
}
}

View File

@ -25,86 +25,69 @@
*/
package traders;
import sesim.AccountData;
import sesim.Account_old;
import sesim.Exchange;
import sesim.TraderConfig_old;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class SwitchingTrader extends RandomTrader_old{
private Action mode;
public SwitchingTrader(Account_old account, TraderConfig_old config) {
super(account, config);
// System.out.print("SWTrader Created\n");
if (account.shares>0)
mode=Action.sell;
else
mode=Action.buy;
printstartus();
public class SwitchingTrader extends RandomTrader {
private int mode;
public SwitchingTrader(Exchange se, double money, double shares, RandomTraderConfig config) {
super(se, money, shares, config);
}
private void printstartus(){
// System.out.print("SWTrader:");
switch (mode){
case buy:
/* System.out.print("buy"
+account.shares
+" "
+account.money
);
*/
break;
case sell:
/*
System.out.print("sell"
+account.shares
+" "
+account.money
);
*/
break;
Action action = Action.RANDOM;
@Override
protected Action getAction() {
if (action == Action.RANDOM) {
action = super.getAction();
return action;
}
// System.out.print("\n");
AccountData ad = se.getAccountData(account_id);
if (action == Action.BUY && ad.money <= 0) {
action = Action.SELL;
}
if (action == Action.SELL && ad.shares <= 0) {
action = Action.BUY;
}
return action;
}
@Override
protected Action getAction(){
if ( (account.shares>0) && (mode==Action.sell)){
printstartus();
return mode;
long doTrade(){
cancelOrders();
Action a = getAction();
long r;
switch (a){
case BUY:
r = doBuy();
if (r==0)
action=Action.SELL;
return r;
case SELL:
r= doSell();
if (r==0)
action=Action.BUY;
return r;
}
if ( (account.shares<=0 && mode==Action.sell)){
mode=Action.buy;
printstartus();
return mode;
}
if (account.money>100.0 && mode==Action.buy){
printstartus();
return mode;
}
if (account.money<=100.0 && mode==Action.buy){
mode=Action.sell;
printstartus();
return mode;
}
printstartus();
return mode;
return 0;
}
}

View File

@ -26,6 +26,7 @@
package traders;
import sesim.Account_old;
import sesim.AutoTrader;
import sesim.AutoTrader_old;
import sesim.Exchange;
@ -33,13 +34,13 @@ import sesim.Exchange;
*
* @author 7u83 <7u83@mail.ru>
*/
public class SwitchingTraderConfig extends RandomTraderConfig_old {
public class SwitchingTraderConfig extends RandomTraderConfig {
@Override
public AutoTrader_old createTrader(Exchange se, long shares, double money) {
Account_old a = new Account_old(se, shares, money);
System.out.print("Returning a new sw trader\n");
return new SwitchingTrader(a, this);
public AutoTrader createTrader(Exchange se, double money, double shares) {
return new traders.SwitchingTrader(se, money, shares, this);
}
public SwitchingTraderConfig() {