text stringlengths 1 93.6k |
|---|
self.path.write(header)
|
def write_unibar(self, tick):
|
# We're getting an array
|
uniBar = {
|
"barTimestamp": tick["barTimestamp"],
|
"tickTimestamp": tick["timestamp"],
|
"open": tick["bidPrice"],
|
"high": tick["bidPrice"],
|
"low": tick["bidPrice"],
|
"close": tick["bidPrice"],
|
"volume": tick["bidVolume"],
|
}
|
if not self._firstUniBar:
|
self._firstUniBar = uniBar # Store first and ...
|
self._lastUniBar = uniBar # ... last bar data for header.
|
self.path.write(
|
pack(
|
"<iiddddQii",
|
int(uniBar["barTimestamp"]), # Bar datetime.
|
0, # Add 4 bytes of padding.
|
uniBar["open"],
|
uniBar["high"],
|
uniBar["low"],
|
uniBar["close"], # OHLCV values.
|
max(
|
int(uniBar["volume"]), 1
|
), # Volume (documentation says it's a double, though it's stored as a long int).
|
int(uniBar["tickTimestamp"]), # The current time within a bar.
|
4,
|
)
|
) # Flag to launch an expert (0 - bar will be modified, but the expert will not be launched).
|
def pack_ticks(self, ticks):
|
# Transform universal bar list to binary bar data (56 Bytes per bar)
|
model = self._priv[4]
|
# Every tick model
|
if model == 0:
|
for tick in ticks:
|
self.write_unibar(tick)
|
# Control points model
|
elif model == 1:
|
startTimestamp = None
|
self.write_unibar(ticks[0])
|
lowPrice = highPrice = ticks[0]["bidPrice"]
|
for tick in ticks[1:]:
|
# Beginning of the M1 bar's timeline.
|
tick["barTimestamp"] = (
|
int(tick["timestamp"]) - int(tick["timestamp"]) % 60
|
)
|
if not startTimestamp:
|
startTimestamp = tick["barTimestamp"]
|
# Determines the end of the M1 bar.
|
endTimestampTimeline = startTimestamp + 60
|
if tick["bidPrice"] < lowPrice:
|
lowPrice = tick["bidPrice"]
|
self.write_unibar(tick)
|
elif tick["bidPrice"] > highPrice:
|
highPrice = tick["bidPrice"]
|
self.write_unibar(tick)
|
elif tick["timestamp"] >= endTimestampTimeline:
|
startTimestamp = tick["barTimestamp"]
|
self.write_unibar(tick)
|
# Open price model
|
elif model == 2:
|
self.write_unibar(ticks[0])
|
def finalize(self):
|
# Fixup the header.
|
self.path.seek(216)
|
fix = bytearray()
|
fix += pack(
|
"<III",
|
self.barCount,
|
int(
|
self._firstUniBar["barTimestamp"]
|
), # Modelling start date - date of the first tick.
|
int(self._lastUniBar["barTimestamp"]),
|
) # Modelling end date - date of the last tick.
|
self.path.write(fix)
|
self.path.seek(472)
|
fix = bytearray()
|
fix += pack(
|
"<II",
|
int(
|
self._firstUniBar["barTimestamp"]
|
), # Tester start date - date of the first tick.
|
int(self._lastUniBar["barTimestamp"]),
|
) # Tester end date - date of the last tick.
|
self.path.write(fix)
|
class HCC(Output):
|
"""Output ticks in HCC file format."""
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.