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

@ -54,7 +54,6 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
+(ntime-time) +(ntime-time)
+"\n" +"\n"
);*/ );*/
if (time > ntime) { if (time > ntime) {
// System.out.print("new raster ----------------------------------\n"); // System.out.print("new raster ----------------------------------\n");
@ -105,7 +104,8 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
// System.out.print("Diemension "+dim.width+" "+dim.height+"\n"); // System.out.print("Diemension "+dim.width+" "+dim.height+"\n");
g.setColor(Color.RED); g.setColor(Color.RED);
g.drawLine(0,0,100,100);
g.drawLine(0, 0, 100, 100);
for (int i = 0; i < items; i++) { for (int i = 0; i < items; i++) {
int x = i * this.item_width; int x = i * this.item_width;
@ -113,61 +113,64 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
} }
// if (this.current == null) { // if (this.current == null) {
// return; // return;
// } // }
ArrayList<OHLCDataItem> od = data.data;
ArrayList <OHLCDataItem> od = data.data; System.out.print("OD S: " + od.size() + "\n");
System.out.print("OD S: "+od.size()+"\n");
g.setColor(Color.BLUE); g.setColor(Color.BLUE);
g.setStroke(new BasicStroke(3));
Iterator<OHLCDataItem> it = od.iterator();
int myi = 0;
Iterator <OHLCDataItem> it = od.iterator(); int lastx=0;
int myi=0; int lasty=0;
while (it.hasNext()){
while (it.hasNext()) {
OHLCDataItem di = it.next(); OHLCDataItem di = it.next();
float val = di.close; float y = di.close;
float max = data.max; float max = data.max;
float min = data.min; float min = data.min;
if (min==max){ max = max/10.0f+max;
min = val/2; min = min-min/10.0f;
max = val*2;
if (min == max) {
min = y / 2;
max = y * 2;
} }
// max = 5;
// min = 0;
System.out.print("Fval: " + y + " " + min + "\n");
System.out.print("Fval: "+val+" "+min+"\n"); y -= min;
val -= min; System.out.print("VAL New" + y + "\n");
System.out.print("VAL New"+val+"\n");
//val/ ((data.max-data.min)/dim.height); //val/ ((data.max-data.min)/dim.height);
System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n");
y = dim.height-(dim.height * y / (max - min));
System.out.print("MINMAX "+min+" "+max+"\n");
val = dim.height*val/(data.max-data.min);
int x = myi * this.item_width; int x = myi * this.item_width;
myi++; myi++;
g.drawLine(x, 0, x, (int)val);
System.out.print("Draw Line: "+x+" "+val+"\n"); g.drawLine(lastx, lasty, x, (int) y);
lastx=x;
lasty=(int)y;
System.out.print("Draw Line: " + x + " " + y + "\n");
} }
// g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0)); // g.drawLine(0, 0, 100, (int) ((this.current.close-80.0)*80.0));
} }
@Override @Override
@ -224,7 +227,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
// System.out.print("Quote Received\n"); // System.out.print("Quote Received\n");
// this.realTimeAdd(q.time, (float) q.price, (float)q.volume); // this.realTimeAdd(q.time, (float) q.price, (float)q.volume);
data.realTimeAdd(q.time, (float)q.price, (float)q.volume); data.realTimeAdd(q.time, (float) q.price, (float) q.volume);
// this.invalidate(); // this.invalidate();
this.repaint(); this.repaint();
} }

View File

@ -36,6 +36,9 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
float max=0; float max=0;
float min=0; float min=0;
int ras=20000;
long time_start; long time_start;
long time_step; long time_step;
@ -47,8 +50,8 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
long rasterTime(long time) { long rasterTime(long time) {
long rt = time / 5000; long rt = time / ras;
return rt * 5000; return rt * ras;
} }
@ -78,7 +81,7 @@ public class OHLCData { //extends ArrayList <OHLCDataItem> {
this.max=price; this.max=price;
} }
ntime = rasterTime(time) + 5000; ntime = rasterTime(time) + ras;
data.add(new OHLCDataItem(price, price, price, price, volume)); data.add(new OHLCDataItem(price, price, price, price, volume));
this.updateMinMax(price); this.updateMinMax(price);
return true; return true;

View File

@ -25,9 +25,11 @@
*/ */
package gui; package gui;
import sesim.AutoTrader;
import sesim.Exchange; import sesim.Exchange;
import traders.RandomTrader; import traders.RandomTrader;
import traders.RandomTraderConfig; import traders.RandomTraderConfig;
import traders.*;
/** /**
@ -185,14 +187,14 @@ public class MainWin extends javax.swing.JFrame {
//RandomTrader rt = rcfg.createTrader(se, 1000, 100); //RandomTrader rt = rcfg.createTrader(se, 1000, 100);
//rt.start(); //rt.start();
RandomTraderConfig rcfg1 = new RandomTraderConfig(); SwitchingTraderConfig rcfg1 = new SwitchingTraderConfig();
RandomTrader rt1 = rcfg1.createTrader(se, 1000000000, 0); AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 0);
rt1.start(); rt1.start();
RandomTraderConfig cfg = new RandomTraderConfig(); RandomTraderConfig cfg = new RandomTraderConfig();
for (int i=0; i<5000; i++){ for (int i=0; i<1000; i++){
RandomTrader randt = cfg.createTrader(se, 100, 100); AutoTrader randt = cfg.createTrader(se, 100, 100);
randt.start(); randt.start();
} }

View File

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

View File

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

View File

@ -25,86 +25,69 @@
*/ */
package traders; package traders;
import sesim.AccountData;
import sesim.Account_old; import sesim.Account_old;
import sesim.Exchange;
import sesim.TraderConfig_old; import sesim.TraderConfig_old;
/** /**
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class SwitchingTrader extends RandomTrader_old{ public class SwitchingTrader extends RandomTrader {
private int mode;
private Action mode; public SwitchingTrader(Exchange se, double money, double shares, RandomTraderConfig config) {
super(se, money, shares, config);
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();
} }
Action action = Action.RANDOM;
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;
}
// System.out.print("\n");
}
@Override @Override
protected Action getAction(){ protected Action getAction() {
if (action == Action.RANDOM) {
action = super.getAction();
return action;
}
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
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)){
printstartus();
return mode;
} }
if ( (account.shares<=0 && mode==Action.sell)){ return 0;
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;
} }
} }

View File

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