diff --git a/nbactions.xml b/nbactions.xml new file mode 100644 index 0000000..6abef33 --- /dev/null +++ b/nbactions.xml @@ -0,0 +1,17 @@ + + + + run + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath gui.MainWin + java + + + diff --git a/pom.xml b/pom.xml index b659378..b859032 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - com.mycompany + com.cauwersin SeSim 1.0-SNAPSHOT jar diff --git a/src/main/java/gui/AskBook.java b/src/main/java/gui/AskBook.java index c0b5fa2..4d2a6a8 100644 --- a/src/main/java/gui/AskBook.java +++ b/src/main/java/gui/AskBook.java @@ -25,7 +25,6 @@ */ package gui; -import sesim.Exchange.*; import sesim.Order.*; import java.util.ArrayList; diff --git a/src/main/java/gui/CandlestickDemo.java b/src/main/java/gui/CandlestickDemo.java index 17e59b7..d9b6980 100644 --- a/src/main/java/gui/CandlestickDemo.java +++ b/src/main/java/gui/CandlestickDemo.java @@ -34,10 +34,10 @@ public class CandlestickDemo extends JFrame { //Now create the chart and chart panel JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false); - ChartPanel chartPanel = new ChartPanel(chart); - chartPanel.setPreferredSize(new Dimension(600, 300)); + // ChartPanel chartPanel = new ChartPanel(chart); + // chartPanel.setPreferredSize(new Dimension(600, 300)); - this.add(chartPanel); + // this.add(chartPanel); this.pack(); } protected AbstractXYDataset getDataSet(String stockSymbol) { diff --git a/src/main/java/gui/Chart.java b/src/main/java/gui/Chart.java index f7d6f57..31e24e7 100644 --- a/src/main/java/gui/Chart.java +++ b/src/main/java/gui/Chart.java @@ -74,7 +74,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); + CandlestickRenderer renderer = new CandlestickRenderer(); + XYDataset dataset = getDataSet(stockSymbol); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); @@ -87,8 +89,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { //Now create the chart and chart panel JFreeChart chart = new JFreeChart(stockSymbol, null, mainPlot, false); + ChartPanel chartPanel = new ChartPanel(chart); - + chartPanel.setPreferredSize(new Dimension(500, 270)); add(chartPanel); @@ -129,12 +132,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { double high = 0; double low = 0; double close = 0; - double volume=0; + double volume = 0; Iterator it = l.iterator(); Quote q; - if (it.hasNext()) { q = it.next(); @@ -142,11 +144,9 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { high = q.price; low = q.price; volume = q.volume; - } - else { + } else { q = new Quote(); } - while (it.hasNext() && q.time < last) { q = it.next(); @@ -178,13 +178,13 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { SortedSet h = MainWin.se.getQuoteHistory(ct - 60); - for (long i = (ct - 60)*1000; i < (ct + 10)*1000; i += 10*1000) { - OHLCDataItem d = getOhlcData(i, i + 10*1000, h); + for (long i = (ct - 60) * 1000; i < (ct + 10) * 1000; i += 10 * 1000) { + OHLCDataItem d = getOhlcData(i, i + 10 * 1000, h); data.add(d); } System.out.print(data.size() + "\n"); - // System.exit(0); + // System.exit(0); return data.toArray(new OHLCDataItem[data.size()]); @@ -255,8 +255,16 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { @Override public void UpdateQuote(Quote q) { - return; - //q.print(); + + // q.print(); + long ct; + ct = Exchange.getCurrentTimeSeconds(5); + SortedSet h = MainWin.se.getQuoteHistory(ct - 15); + + System.out.print("Number of quotes" + ct + "\n"); + + System.out.print("Number of quotes:" + h.size() + "\n"); + /* SortedSet h = MainWin.se.getQuoteHistory(60); System.out.print( "SortedSet size:" diff --git a/src/main/java/gui/ChartPanel.form b/src/main/java/gui/ChartPanel.form new file mode 100644 index 0000000..c638b68 --- /dev/null +++ b/src/main/java/gui/ChartPanel.form @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/gui/ChartPanel.java b/src/main/java/gui/ChartPanel.java new file mode 100644 index 0000000..a533576 --- /dev/null +++ b/src/main/java/gui/ChartPanel.java @@ -0,0 +1,46 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package gui; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class ChartPanel extends javax.swing.JPanel { + + /** + * Creates new form ChartPanel + */ + public ChartPanel() { + initComponents(); + + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/src/main/java/gui/DTSCTest.java b/src/main/java/gui/DTSCTest.java new file mode 100644 index 0000000..39ddb28 --- /dev/null +++ b/src/main/java/gui/DTSCTest.java @@ -0,0 +1,130 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package gui; + +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JPanel; +import javax.swing.Timer; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.XYPlot; +import org.jfree.data.time.DynamicTimeSeriesCollection; +import org.jfree.data.time.Second; +import org.jfree.data.xy.XYDataset; +import org.jfree.ui.ApplicationFrame; +import org.jfree.ui.RefineryUtilities; + +/** + * @see http://stackoverflow.com/questions/5048852 + */ +public class DTSCTest extends ApplicationFrame { + + private static final String TITLE = "Dynamic Series"; + private static final String START = "Start"; + private static final String STOP = "Stop"; + private static final float MINMAX = 300; + private static final int COUNT = 2 * 60; + private static final int FAST = 100; + private static final int SLOW = FAST * 5; + private static final Random RANDOM = new Random(); + private Timer timer; + + public DTSCTest(final String title) { + super(title); + final DynamicTimeSeriesCollection dataset + = new DynamicTimeSeriesCollection(1, COUNT, new Second()); + dataset.setTimeBase(new Second(0, 0, 0, 1, 1, 2011)); + dataset.addSeries(gaussianData(), 0, "Gaussian data"); + JFreeChart chart = createChart(dataset); + + final JButton run = new JButton(STOP); + run.addActionListener((ActionEvent e) -> { + String cmd = e.getActionCommand(); + if (STOP.equals(cmd)) { + timer.stop(); + run.setText(START); + } else { + timer.start(); + run.setText(STOP); + } + }); + + final JComboBox combo = new JComboBox(); + combo.addItem("Fast"); + combo.addItem("Slow"); + combo.addActionListener((ActionEvent e) -> { + if ("Fast".equals(combo.getSelectedItem())) { + timer.setDelay(FAST); + } else { + timer.setDelay(SLOW); + } + }); + + this.add(new ChartPanel(chart), BorderLayout.CENTER); + JPanel btnPanel = new JPanel(new FlowLayout()); + // btnPanel.add(run); + // btnPanel.add(combo); + this.add(btnPanel, BorderLayout.SOUTH); + + timer = new Timer(FAST, new ActionListener() { + + float[] newData = new float[1]; + + @Override + public void actionPerformed(ActionEvent e) { + newData[0] = randomValue(); + dataset.advanceTime(); + dataset.appendData(newData); + } + }); + } + + private float randomValue() { + return (float) (RANDOM.nextGaussian() * MINMAX / 3); + } + + private float[] gaussianData() { + float[] a = new float[COUNT]; + for (int i = 0; i < a.length; i++) { + a[i] = randomValue(); + } + return a; + } + + private JFreeChart createChart(final XYDataset dataset) { + final JFreeChart result = ChartFactory.createTimeSeriesChart( + TITLE, "hh:mm:ss", "milliVolts", dataset, true, true, false); + final XYPlot plot = result.getXYPlot(); + ValueAxis domain = plot.getDomainAxis(); + domain.setAutoRange(true); + ValueAxis range = plot.getRangeAxis(); + range.setRange(-MINMAX, MINMAX); + return result; + } + + public void start() { + timer.start(); + } + + public static void main(final String[] args) { + EventQueue.invokeLater(() -> { + DTSCTest demo = new DTSCTest(TITLE); + demo.pack(); + RefineryUtilities.centerFrameOnScreen(demo); + demo.setVisible(true); + demo.start(); + }); + } +} diff --git a/src/main/java/gui/OrderBook.java b/src/main/java/gui/OrderBook.java index cf7e198..6bae44c 100644 --- a/src/main/java/gui/OrderBook.java +++ b/src/main/java/gui/OrderBook.java @@ -97,7 +97,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B protected class OrderBookListModel extends AbstractTableModel { private ArrayList list; - private boolean desc = false; + //private final boolean desc = false; public OrderBookListModel() { // System.out.print("CREATING A NEW MODEL\n"); diff --git a/src/main/java/gui/test.java b/src/main/java/gui/test.java index 4d604c4..16a3861 100644 --- a/src/main/java/gui/test.java +++ b/src/main/java/gui/test.java @@ -105,11 +105,48 @@ public class test { return ts.tailSet(iter.next()); } + + + static abstract interface Rc { + public abstract int inc(int x); + // public abstract int dec(int x); + + + + } + + public static void main(String args[]) { - NoProblem p = new NoProblem(); - p.run(); +// NoProblem p = new NoProblem(); +// p.run(); + + Rc a = new Rc(){ + @Override + public int inc(int x) { + return x+1; + } + + /* @Override + public int dec(int x) { + return x+1; + } +*/ + + }; + + Rc l = (x) -> x+1; + + + System.out.print("A:" + +a.inc(17) + +" " + +l.inc(4) + + ); + + } } diff --git a/src/main/java/sesim/AutoTrader.java b/src/main/java/sesim/AutoTrader.java index d98e667..f5b2f7d 100644 --- a/src/main/java/sesim/AutoTrader.java +++ b/src/main/java/sesim/AutoTrader.java @@ -39,25 +39,26 @@ public abstract class AutoTrader extends Trader implements Runnable { protected void doSleep(int seconds) { try { - sleep(seconds*1000); + sleep(seconds * 1000); } catch (InterruptedException e) { } } - - public void start(){ + + public void start() { System.out.print("Starting AutoTrader\n"); - class Runner extends Thread{ + class Runner extends Thread { + AutoTrader trader; + @Override - public void run(){ + public void run() { trader.run(); } } Runner r = new Runner(); - r.trader=this; + r.trader = this; r.start(); - + } - - + } diff --git a/src/main/java/sesim/Exchange.java b/src/main/java/sesim/Exchange.java index 305d125..681808f 100644 --- a/src/main/java/sesim/Exchange.java +++ b/src/main/java/sesim/Exchange.java @@ -28,20 +28,19 @@ public class Exchange extends Thread { } public static long getCurrentTimeSeconds(long div) { - long ct = System.currentTimeMillis() / 1000*div; + long ct = System.currentTimeMillis() / (1000 * div) * div; return ct * div; } - - public static long getCurrentTimeSeconds(){ + + public static long getCurrentTimeSeconds() { return getCurrentTimeSeconds(1); } public SortedSet getQuoteHistory(long start) { Quote s = new Quote(); - s.time = start; - s.time = 2; - s.id = 2; + s.time = start*1000; + s.id = 0; TreeSet result = new TreeSet<>(); result.addAll(this.quoteHistory.tailSet(s)); @@ -50,12 +49,11 @@ public class Exchange extends Thread { } - /* public SortedSet getQuoteHistory(int seconds) { + /* public SortedSet getQuoteHistory(int seconds) { Quote last = quoteHistory.last(); return this.getQuoteHistory(seconds, last.time); } - */ - + */ // Class to describe an executed order // QuoteReceiver has to be implemented by objects that wants // to receive quote updates diff --git a/src/main/java/traders/SwitchingTrader.java b/src/main/java/traders/SwitchingTrader.java index 2417734..cbe8bb4 100644 --- a/src/main/java/traders/SwitchingTrader.java +++ b/src/main/java/traders/SwitchingTrader.java @@ -40,7 +40,7 @@ public class SwitchingTrader extends RandomTrader{ public SwitchingTrader(Account account, TraderConfig config) { super(account, config); - System.out.print("SWTrader Created\n"); + // System.out.print("SWTrader Created\n"); if (account.shares>0) mode=Action.sell; @@ -53,26 +53,29 @@ public class SwitchingTrader extends RandomTrader{ private void printstartus(){ - System.out.print("SWTrader:"); + // System.out.print("SWTrader:"); switch (mode){ case buy: - System.out.print("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"); +// System.out.print("\n"); }