-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Je vous propose cette modif pour que le code marche si on change la timeframe (désolé pour le code un peu dégeux et le commentaire mal posté j'ai fais ça vite, ça fait longtemps que j'ai pas codé ni utilisé github... :/)
def get_more_last_historical_async(self, symbol, timeframe, limit):
# Traduit la timeframe
timeframe_table = [int(timeframe[:-1]), timeframe[-1]]
max_threads = 4
pool_size = round(limit/100) # your "parallelness"
# define worker function before a Pool is instantiated
full_result = []
def worker(i):
try:
# Calculer le timestamp de début en fonction du timeframe
if timeframe_table[1] == "h":
start_timestamp = round(time.time() * limit) - (i * limit * 60 * 60 * timeframe_table[0])
elif timeframe_table[1] == "m":
start_timestamp = round(time.time() * limit) - (i * limit * 60 * timeframe_table[0])
else: # Cas si ni "_h" ni "_m"
raise Exception("Error on the timeframe [" + timeframe + "]. Should be _h or _m (for exemple 15m for 15 minutes)")
return self._session.fetch_ohlcv(
symbol, timeframe, start_timestamp, limit=100)
except Exception as err:
raise Exception("Error on last historical on " + symbol + ": " + str(err))
pool = Pool(max_threads)
full_result = pool.map(worker, range(limit, 0, -100))
full_result = np.array(full_result).reshape(-1, 6)
result = pd.DataFrame(data=full_result)
result = result.rename(
columns={0: 'timestamp', 1: 'open', 2: 'high', 3: 'low', 4: 'close', 5: 'volume'})
result = result.set_index(result['timestamp'])
result.index = pd.to_datetime(result.index, unit='ms')
del result['timestamp']
return result.sort_index()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels