text stringlengths 1 93.6k |
|---|
return bar
|
class HST574(Output):
|
def __init__(self, path, path_suffix, output_dir, timeframe, symbol):
|
# Initialize variables in parent constructor
|
super().__init__(timeframe, path_suffix, symbol, output_dir)
|
# Build header (148 Bytes in total)
|
header = bytearray()
|
header += pack("<i", 401) # Version
|
header += bytearray(
|
"(C)opyright 2003, MetaQuotes Software Corp.".ljust(
|
64, "\x00" # Copyright
|
),
|
"latin1",
|
"ignore",
|
)
|
header += bytearray(symbol.ljust(12, "\x00"), "latin1", "ignore") # Symbol
|
header += pack("<i", timeframe) # Period
|
header += pack("<i", 5) # Digits, using the default value of HST format
|
header += pack("<i", int(time.time())) # Time of sign (database creation)
|
header += pack("<i", 0) # Time of last synchronization
|
header += bytearray(13 * 4) # Space for future use
|
self.path.write(header)
|
def pack_ticks(self, ticks):
|
# Transform universal bar list to binary bar data (60 Bytes per bar)
|
ticksAggregated = {
|
"barTimestamp": ticks[0]["timestamp"],
|
"tickTimestamp": ticks[0]["timestamp"],
|
"open": ticks[0]["bidPrice"],
|
"low": ticks[0]["bidPrice"],
|
"high": ticks[0]["bidPrice"],
|
"close": ticks[0]["bidPrice"],
|
"volume": 0,
|
}
|
for tick in ticks:
|
ticksAggregated["low"] = min(ticksAggregated["low"], tick["bidPrice"])
|
ticksAggregated["high"] = max(ticksAggregated["high"], tick["bidPrice"])
|
ticksAggregated["volume"] += tick["bidVolume"] + tick["askVolume"]
|
ticksAggregated["close"] = tick["bidPrice"]
|
self.path.write(self._packUniBar(ticksAggregated))
|
def _packUniBar(self, uniBar):
|
bar = bytearray()
|
bar += pack("<i", uniBar["barTimestamp"]) # Time
|
bar += bytearray(4) # Add 4 bytes of padding.
|
# OHLCV values.
|
bar += pack("<d", uniBar["open"]) # Open
|
bar += pack("<d", uniBar["high"]) # High
|
bar += pack("<d", uniBar["low"]) # Low
|
bar += pack("<d", uniBar["close"]) # Close
|
bar += pack("<Q", max(int(uniBar["volume"]), 1)) # Volume
|
bar += pack("<i", 0) # Spread
|
bar += pack("<Q", 0) # Real volume
|
return bar
|
class FXT(Output):
|
def __init__(
|
self, path, path_suffix, output_dir, timeframe, symbol, server, spread, model
|
):
|
# Initialize variables in parent constructor
|
super().__init__(timeframe, path_suffix, symbol, output_dir)
|
self._priv = (timeframe, server, symbol, spread, model)
|
self._firstUniBar = self._lastUniBar = None
|
# Build header (728 Bytes in total).
|
header = bytearray()
|
header += pack("<I", 405) # FXT header version: 405
|
header += bytearray(
|
"Copyright 2001-2015, MetaQuotes Software Corp.".ljust(
|
64, "\x00" # Copyright text.
|
),
|
"latin1",
|
"ignore",
|
)
|
header += bytearray(
|
server.ljust(128, "\x00"), "latin1", "ignore"
|
) # Account server name.
|
header += bytearray(
|
symbol.ljust(12, "\x00"), "latin1", "ignore"
|
) # Symbol pair.
|
header += pack(
|
"<I", timeframe
|
) # Period of data aggregation in minutes (timeframe).
|
header += pack(
|
"<I", model
|
) # Model type: 0 - every tick, 1 - control points, 2 - bar open.
|
header += pack("<I", 0) # Bars - amount of bars in history.
|
header += pack("<I", 0) # Modelling start date - date of the first tick.
|
header += pack("<I", 0) # Modelling end date - date of the last tick.
|
header += bytearray(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.