int main ( int argc, char **argv ) { pwr_tStatus sts; pwr_tTime time; pwr_tTime now; int sec,nsec; #ifdef OS_VMS sts = lib$get_ef(&timerFlag); if (EVEN(sts)) exit(sts); #endif for (sec=0,nsec=10000000;;) { nowTime(&now); #if 0 now.tv_sec = sec; now.tv_nsec = nsec; #endif printf("%d:%d\n", now.tv_sec, now.tv_nsec); waitTime(&now); nsec += 10000000; sec += nsec / 1000000000; nsec %= 1000000000; } }
static void subbCheck ( sTimer *tp ) { sub_sBuffer *bp = (sub_sBuffer *)tp->data; if (gdbroot->db->log.b.tmon) errh_Info("subbCheck: %u", tp->clock); #if 0 if (EXCL_ON) { /* Exclusive mode is on, requeue the buffer for later transmission */ addTime(nowTime(&tp->time), msToTime(NULL, bp->dt)); insertTimer(tp); } #endif if (subsm_SendBuffer(bp)) { setTimer(tp, msToClock(NULL, bp->dt)); insertTimer(tp); } else { freeTimer(tp); } }
static void waitTime ( pwr_tTime *t ) { pwr_tStatus sts; pwr_tTime now; pwr_tTime then = *t; char tims[24]; short len; struct dsc$descriptor_s tims_desc = { sizeof(tims)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,}; #if 0 subTime(&then, nowTime(&now)); #endif if ((int)then.tv_sec > 0 || ((int)then.tv_sec == 0 && then.tv_nsec > 0)) { #if defined OS_VMS || defined OS_ELN int tv_nsec; int vmstime[2]; int multiplier = -10000000; /* Used to convert 1 s to 100 ns, delta time. */ static pwr_tTime tick = {0, 10000000}; addTime(&then, &tick); tv_nsec = -then.tv_nsec/100; /* Convert to 100 ns. */ sts = lib$emul(&then.tv_sec, &multiplier, &tv_nsec, vmstime); #if defined OS_VMS tims_desc.dsc$a_pointer = tims; sys$asctim( &len, &tims_desc, vmstime, 0); tims[len] = '\0'; printf(" %s\n", tims); #if 0 sts = sys$clref(timerFlag); sts = sys$setimr(timerFlag, vmstime, 0, 0, 0); sts = sys$waitfr(timerFlag); #endif #elif defined OS_ELN eln$time_string(tims, vmstime); tims[23] = '\0'; printf(" %s\n", tims); #if 0 ker$wait_any(&sts, NULL, vmstime); #endif #endif #elif defined OS_LYNX pwr_tTime rmt; nanosleep(&then, &rmt); #endif } }
void CStrategy::Judgement(){ data[tailOfData] = (account->pMarketData)[orderOfIns]; int currentPosition = tailOfData; while ((currentPosition % kindOfK) != 0){ ++currentPosition; data[currentPosition] = (account->pMarketData)[orderOfIns]; } double totalE = 0; for (int i = 0; i < numOfK; ++i){ double open, close, high, low; int volume2, volume1; for (int j = 0; j < kindOfK; ++j){ if (j == 0){ close = data[currentPosition].closePrice; high = data[currentPosition].highPrice; low = data[currentPosition].lowPrice; volume2 = data[currentPosition].dealVolume; } if (j == (kindOfK - 1)){ open = data[currentPosition].openPrice; volume1 = data[currentPosition].dealVolume; } if (data[currentPosition].highPrice > high) high = data[currentPosition].highPrice; if (data[currentPosition].lowPrice < low) low = data[currentPosition].lowPrice; --currentPosition; } double e = 0; if (high == low) e = 0; else e = ((open - close) / (high - low)) * (volume2 - volume1); totalE += e; } if (direction == -1){ lastTime = COleDateTime::GetCurrentTime(); if (totalE > 0){ int rest = maxPosition; direction = BUY; for (int stage = 0; stage < 4; ++stage){ int ID = MakeOrder(USTP_FTDC_D_Buy, USTP_FTDC_OF_Open, stage, rest); (account->traderHandler)->regStrategy(1, ID); Sleep(10000); rest = (account->traderHandler)->getStrategy(1); } } else {//totalE < 0) int rest = maxPosition; direction = SELL; for (int stage = 0; stage < 4; ++stage){ int ID = MakeOrder(USTP_FTDC_D_Sell, USTP_FTDC_OF_Open, stage, rest); (account->traderHandler)->regStrategy(1, ID); Sleep(10000); rest = (account->traderHandler)->getStrategy(1); } } } else{ COleDateTime nowTime(COleDateTime::GetCurrentTime()); int totalSecond = 0; totalSecond += (nowTime.GetHour() - lastTime.GetHour()) * 3600; totalSecond += (nowTime.GetMinute() - lastTime.GetMinute()) * 60; totalSecond += (nowTime.GetSecond() - lastTime.GetSecond()); if (totalSecond < 60 * minuteGap) return; if (totalE > 0){ if (direction == BUY) return; direction = BUY; int rest1 = maxPosition; int rest2 = maxPosition; for (int stage = 0; stage < 4; ++stage){ if (rest1 != 0){ int ID1 = MakeOrder(USTP_FTDC_D_Buy, USTP_FTDC_OF_Close, stage, rest1); (account->traderHandler)->regStrategy(1, ID1); } if (rest2 != 0){ int ID2 = MakeOrder(USTP_FTDC_D_Buy, USTP_FTDC_OF_Open, stage, rest2); (account->traderHandler)->regStrategy(2, ID2); } Sleep(10000); if (rest1 != 0) rest1 = (account->traderHandler)->getStrategy(1); if (rest2 != 0) rest2 = (account->traderHandler)->getStrategy(2); } } else{ if (direction == SELL) return; direction = SELL; int rest1 = maxPosition; int rest2 = maxPosition; for (int stage = 0; stage < 4; ++stage){ if (rest1 != 0){ int ID1 = MakeOrder(USTP_FTDC_D_Sell, USTP_FTDC_OF_Close, stage, rest1); (account->traderHandler)->regStrategy(1, ID1); } if (rest2 != 0){ int ID2 = MakeOrder(USTP_FTDC_D_Sell, USTP_FTDC_OF_Open, stage, rest2); (account->traderHandler)->regStrategy(2, ID2); } Sleep(10000); if (rest1 != 0) rest1 = (account->traderHandler)->getStrategy(1); if (rest2 != 0) rest2 = (account->traderHandler)->getStrategy(2); } } } }