text
stringlengths
1
93.6k
timeframe,
symbol,
server,
spread,
int(m),
)
elif outputFormat == "hcc":
yield HCC(".hcc", args.outputDir, timeframe, symbol)
else:
print("[ERROR] Unknown output file format: {}!".format(outputFormat))
sys.exit(1)
def process_queue(queue):
"""Process the queue, process all the timeframes at the same time to amortize the cost of the parsing."""
queue = list(queue)
try:
for obj in queue:
ticks = CSV(args.inputFile)
startTimestamp = None
# We will retrieve all ticks in the timeframe into following array and update their LowBid/HighBid
ticksToJoin = []
ticksToAggregate = []
for (tick, isLastRow) in ticks:
# Beginning of the bar's timeline.
tick["barTimestamp"] = (
int(tick["timestamp"]) - int(tick["timestamp"]) % obj.deltaTimestamp
)
# Tick's timestamp will be rounded to 1 for M1 and 60 for other.
tick["timestamp"] = int(
tick["timestamp"]
) # - int(tick['timestamp']) % (1 if obj.deltaTimestamp == 60 else 60)
if not startTimestamp:
startTimestamp = tick["barTimestamp"]
# Tick after this time won't be used for LowBid/HighBid aggregation.
endTimestampAggregate = startTimestamp + 60
# Determines the end of the current bar.
endTimestampTimeline = startTimestamp + obj.deltaTimestamp
if tick["timestamp"] < endTimestampTimeline:
# Tick is within the current bar's timeline, queuing for
# aggregation.
ticksToAggregate.append(tick)
else:
# Tick is beyond current bar's timeline, aggregating unaggregated
# ticks:
if len(ticksToAggregate) > 0:
obj.pack_ticks(ticksToAggregate)
# Next bar's timeline will begin from this new tick's bar
# timestamp.
startTimestamp = tick["barTimestamp"]
# Tick beyond delta timeframe will be aggregated in the next
# timeframe
ticksToAggregate = [tick]
spinner.spin()
# Writting the last tick if not yet written.
if len(ticksToAggregate) > 0:
obj.pack_ticks(ticksToAggregate)
if args.verbose:
print("[INFO] Finalizing...")
for obj in queue:
obj.finalize()
if args.verbose:
print("[INFO] Done.")
except KeyboardInterrupt as e:
print("\n[INFO] Exiting by user request...")
sys.exit()
if __name__ == "__main__":
# Parse the arguments.
arg_parser = config_argparser()
args = arg_parser.parse_args()
# Checking input file argument.
if args.verbose:
print("[INFO] Input file: %s" % args.inputFile)
# Checking symbol pair argument.
if args.pair and len(args.pair) > 12:
print("[WARNING] Symbol is more than 12 characters, cutting its end off!")
symbol = args.pair[0:12]
else:
symbol = args.pair
if args.verbose: