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

@ -50,11 +50,10 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
private void realTimeAdd(long time, float price, float volume) {
/*System.out.print("Diff:"
/*System.out.print("Diff:"
+(ntime-time)
+"\n"
);*/
if (time > ntime) {
// System.out.print("new raster ----------------------------------\n");
@ -100,74 +99,78 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
int phight = 40;
this.setPreferredSize(new Dimension(pwidth, phight));
Dimension dim = this.getSize();
// System.out.print("Diemension "+dim.width+" "+dim.height+"\n");
g.setColor(Color.RED);
g.drawLine(0,0,100,100);
Dimension dim = this.getSize();
// System.out.print("Diemension "+dim.width+" "+dim.height+"\n");
g.setColor(Color.RED);
g.drawLine(0, 0, 100, 100);
for (int i = 0; i < items; i++) {
int x = i * this.item_width;
g.drawLine(x, 0, x, 50);
}
// if (this.current == null) {
// return;
// }
ArrayList<OHLCDataItem> od = data.data;
System.out.print("OD S: " + od.size() + "\n");
g.setColor(Color.BLUE);
g.setStroke(new BasicStroke(3));
Iterator<OHLCDataItem> it = od.iterator();
int myi = 0;
int lastx=0;
int lasty=0;
// if (this.current == null) {
// return;
// }
ArrayList <OHLCDataItem> od = data.data;
System.out.print("OD S: "+od.size()+"\n");
g.setColor(Color.BLUE);
Iterator <OHLCDataItem> it = od.iterator();
int myi=0;
while (it.hasNext()){
while (it.hasNext()) {
OHLCDataItem di = it.next();
float val = di.close;
float max = data.max;
float min = data.min;
if (min==max){
min = val/2;
max = val*2;
}
float y = di.close;
float max = data.max;
float min = data.min;
max = max/10.0f+max;
min = min-min/10.0f;
System.out.print("Fval: "+val+" "+min+"\n");
val -= min;
System.out.print("VAL New"+val+"\n");
//val/ ((data.max-data.min)/dim.height);
if (min == max) {
min = y / 2;
max = y * 2;
}
System.out.print("MINMAX "+min+" "+max+"\n");
val = dim.height*val/(data.max-data.min);
int x = myi * this.item_width;
myi++;
g.drawLine(x, 0, x, (int)val);
// max = 5;
// min = 0;
System.out.print("Fval: " + y + " " + min + "\n");
y -= min;
System.out.print("VAL New" + y + "\n");
//val/ ((data.max-data.min)/dim.height);
System.out.print("MINMAX " + min + " " + max + " " + dim.height + "\n");
y = dim.height-(dim.height * y / (max - min));
int x = myi * this.item_width;
myi++;
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
@ -182,7 +185,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
// g.get
Rectangle bounds = g.getDeviceConfiguration().getBounds();
// System.out.print(bounds.width + "\n");
// System.out.print(bounds.width + "\n");
//g.fillRect(0, 0, 100, 100);
Dimension d = this.getSize();
@ -221,11 +224,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
@Override
public void UpdateQuote(Quote q) {
// System.out.print("Quote Received\n");
// System.out.print("Quote Received\n");
// this.realTimeAdd(q.time, (float) q.price, (float)q.volume);
data.realTimeAdd(q.time, (float)q.price, (float)q.volume);
// this.invalidate();
data.realTimeAdd(q.time, (float) q.price, (float) q.volume);
// this.invalidate();
this.repaint();
}

View File

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

View File

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

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() {