A function that corrects the "ActionDay"fields from market quotes which is delivered by CTP.
It belongs to one of my personal projects which may go opensource in the future.
In my work, I find it usefull to put this function into my company’s project.
SO, I extract this function and some related functions, put it here and claim the MIT license for the following lines to avoid copyright issue in the future.
//sepcial functions that used in ctp quotes.
//use the revised date to indicate which file the quote belongs to.
// return a revised tdfdate(actionday)
// on error:
// return -1 if tdftime_action is in the market close time.
// return 0 if tdftime_action is not valid for the current time(overdue).
inline int fix_actionday(string &exchange, int tdfdate_action, int tdftime_action, int mimic_clock = -1)
{
using namespace boost::posix_time;
using namespace boost::gregorian;
ptime now = microsec_clock::local_time();
date today = now.date();
auto tod = now.time_of_day();
int msec_actiontime = tdftime_to_msec(tdftime_action);
int msec_10min_period= 1000 * 60 * 10;
int msec_current_time = tod.total_milliseconds();
if (mimic_clock >= 0)
msec_current_time = tdftime_to_msec(mimic_clock);
// try to get close and settelment price for CF
// 16 - 17 , for CF
if ((msec_current_time > tdftime_to_msec(160000000))
&& (msec_current_time < tdftime_to_msec(170000000))
&& tdfdate_action == get_local_tdfdate())
return tdfdate_action;
//20 - 21 // for DCE SHFE CZFE
if ((msec_current_time > tdftime_to_msec(200000000))
&& (msec_current_time < tdftime_to_msec(210000000))
&& tdfdate_action == get_local_tdfdate())
return tdfdate_action;
//drop all the playback garbage.
// 18 - 21 , no need to be processed
if (msec_current_time > tdftime_to_msec(180000000) && msec_current_time < tdftime_to_msec(205000000))
return -1;
// 7 - 9 , no need to be processed
if (msec_current_time > tdftime_to_msec(70000000) && msec_current_time < tdftime_to_msec(85000000))
return -1;
//if (machine time >= 0:00 and machine time < 0:10) and quotes time > 23:50, use machine date -1
//if (machine time > 23:50 and machine time <= 23:59:59) and (quotes time > 0:00 and quotes time < 0:10), use machine date + 1
//otherwise use machine date
//night market
if ((msec_current_time <= msec_10min_period) &&
msec_actiontime >= tdftime_to_msec( 235000000 ) )
{
//today - 1
date yesterday = today - days(1);
return yesterday.year() * 10000 + yesterday.month() * 100 + yesterday.day();
}
else if ((msec_current_time >= tdftime_to_msec(235000000)) &&
(msec_actiontime <= msec_10min_period))
{
date tommorrow = today + days(1);
return tommorrow.year() * 10000 + tommorrow.month() * 100 + tommorrow.day();
}
//ctp will always deliver the last few previous-day-snapshots before the market opening.
//this behavior will mess up the recording.
//we shall discard the expired quotes..
//in a normal way, tdftime should be always early than the machine_time.
//give it 10minute margin in case of inaccurate local machine time or latency.
if ((msec_actiontime - msec_current_time) > msec_10min_period ||
(msec_actiontime - msec_current_time) < -msec_10min_period)
return 0;
return today.year() * 10000 + today.month() * 100 + today.day();
}
void break_splited_cstime(char* cstime, int* _HH, int* _mm, int* _ss)
{
*_HH = atoi(&cstime[0]);
*_mm = atoi(&cstime[3]);
*_ss = atoi(&cstime[6]);
}
void break_cstime(char* cstime, int* _HH, int* _mm, int* _ss)
{
int HHmmss = atoi(cstime);
*_HH = HHmmss / 10000;
*_mm = HHmmss % 10000 / 100;
*_ss = HHmmss % 100;
}
int csdate_to_tdfdate(char* csdate)
{
int yyymmdd = atoi(csdate);
return yyymmdd;
}
int cstime_to_tdftime(char* cstime)
{
int HH = 0;
int mm = 0;
int ss = 0;
if (strlen(cstime) <= 6)
{
break_cstime(cstime, &HH, &mm, &ss);
}
else
{
break_splited_cstime(cstime, &HH, &mm, &ss);
}
return (HH * 10000 + mm * 100 + ss) * 1000;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
개발일지3.학습한 내용. 리뷰 4,5 (복습) ====버튼 누르기 (console) 버튼 모두 누르기 100보다 큰 버튼만 누르기 (리로딩(새로고침)해줘야 반영) 100보다 크고 200보다 작은 버튼만 누르기 (if안에 if...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.