SHARE
TWEET

Untitled

a guest Jul 16th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def read_hst(filename):
  2.     from pandas import DataFrame, to_datetime
  3.     from struct import unpack, calcsize, iter_unpack
  4.     bint = open(filename, 'rb').read()
  5.     head = unpack('<i64s12siiii', bint[:96])
  6.     version = head[0]
  7.     symbol = head[2].decode("utf-8").split('\x00')[0]
  8.     start = 148
  9.     if version == 401:
  10.         fmt = '<qddddqfq'
  11.         columns = ['datetime', 'open', 'high', 'low',
  12.                    'close', 'volume', 'spread', 'real_volume']
  13.     elif version == 400:
  14.         fmt = '<iddddd'
  15.         columns = ['datetime', 'open', 'high', 'low', 'close', 'volume']
  16.     else:
  17.         print('El archivo no es una versiĆ³n conocida de hst de MetaTrader')
  18.         return
  19.     size = calcsize(fmt)
  20.     df = DataFrame.from_records([bar for bar in iter_unpack(fmt, bint[start:])],
  21.                                 columns=columns,
  22.                                 index='datetime')
  23.     df.name = symbol
  24.     df.index = to_datetime(df.index, unit='s')
  25.     return df
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top