Skip to content

BitGet get_more_last_historical_async with any timeframe #21

@AlexisDew

Description

@AlexisDew

https://github.com/CryptoRobotFr/live_tools/blame/ec13c7ab66f8afad0f542d8e8d3d2524931887ef/utilities/perp_bitget.py#L45-L69

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions