             }
             file.synchronizeFile()
         }
-        println("(sleep for 10 secs)...")
-        NSThread.sleepForTimeInterval(NSTimeInterval(10.0))
+        println("(sleep for \(sleepInterval) secs)...")
+        NSThread.sleepUntilDate(NSDate(timeIntervalSinceReferenceDate: begin + sleepInterval))
     }
     if lf != nil {
         lf?.closeFile()

var barsize = "5 mins"
var unixts = 1
var duration = "10800 S" // 3 hours
var outputDir: String = NSFileManager.defaultManager().currentDirectoryPath

let now = NSDate(timeIntervalSinceNow: 0)

                if arr != nil {
                    for sym in arr! { tickers.append(sym) }
                }
            }
        }
        argValue[index+1] = true
    case "--sleep":
        if index+1<Process.arguments.count {
            let sd = NSString(string: Process.arguments[index+1]).doubleValue
            if sd != 0 {
                sleepInterval = sd
            }
        }
        argValue[index+1] = true
