⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tickcompressor.java

📁 网上期货交易的外挂原码,可实现自动交易功能,自动添加模块
💻 JAVA
字号:
package com.jsystemtrader.platform;

/**
 * Adds a new bar to a quote history.
 */
public class TickCompressor extends Thread {
    private static final int MILLIS_IN_SECOND = 1000;

    private final QuoteHistory qh;
    private final Strategy strategy;
    private final long barSizeInMillis;
    private long nextBarTime, timeToNextBar;

    public TickCompressor(Strategy strategy) {
        this.strategy = strategy;
        barSizeInMillis = strategy.getBarSizeInSecs() * MILLIS_IN_SECOND;
        qh = strategy.getQuoteHistory();
        start();
    }

    public void run() {

        while (true) {
            long timeNow = strategy.getCalendar().getTimeInMillis();
            if (nextBarTime == 0) {
                nextBarTime = (timeNow / barSizeInMillis + 1) * barSizeInMillis;
            } else {
                nextBarTime += barSizeInMillis;
            }
            timeToNextBar = nextBarTime - timeNow;

            try {
                sleep(timeToNextBar + 500); // extra 500ms to get on the minute
                qh.addNextBar(nextBarTime);
            } catch (InterruptedException ie) {
                throw new RuntimeException(ie);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -