Coder Social home page Coder Social logo

Comments (1)

xywanz avatar xywanz commented on July 23, 2024 1

spdlog本身耗时就很大,会有一两百微秒的时延,所以用spdlog测量的时间误差比较大
先保证时间能够准确测量,在tick中加入当前毫秒时间字段
struct TickData : public pubsub::Serializable {
uint64_t current_time_us; // 加入该字段
MarketDataSource source;
datetime::Datetime datetime;

uint32_t ticker_id;
double last_price = 0;
double open_price = 0;
double highest_price = 0;
double lowest_price = 0;
double pre_close_price = 0;
double upper_limit_price = 0;
double lower_limit_price = 0;
uint64_t volume = 0;
uint64_t turnover = 0;
uint64_t open_interest = 0;

double ask[kMaxMarketLevel]{0};
double bid[kMaxMarketLevel]{0};
int ask_volume[kMaxMarketLevel]{0};
int bid_volume[kMaxMarketLevel]{0};

struct {
double iopv;
} etf;

SERIALIZABLE_FIELDS(current_time_us, source, datetime, ticker_id, last_price, open_price, highest_price,
lowest_price, pre_close_price, upper_limit_price, lower_limit_price, volume,
turnover, open_interest, ask, bid, ask_volume, bid_volume, etf.iopv);
};

在收到行情时,先在tick中记录当前时间
uint64_t GetCurrentTimeUs() {
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_nsec / 1000 + ts.tv_sec * 1000000;
}

tick.current_time_us = GetCurrentTimeUs();

在策略端收到行情时
uint64_t current_us = GetCurrentTimeUs();
uint64_t delay_us = current_us - tick.current_time_us;

tick延迟大应该是由于ZeroMQ延迟大。
解决办法:开发基于共享内存的行情分发模块,可以让通信时延降低至1us以内。

from ft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.