Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help me.
#3
(May-05-2023, 05:29 PM)deanhystad Wrote: Yes.

If you'd like more detail, please provide more detail about your problem. What kind of information are you sifting through? How do you identify the information you want to retrieve? What details of the information do you want to retain?

Example code, a small, not completely working example, would be a good start.

Hi. thanks for your response. I didn't include the code because it might be a bit much. But basically I am cycling through currency pairs and time frames to extract different moving averages of those currency pairs. What I want to do is use the information provided to give a score on each of the currency pairs to help me understand what might be better trades. I've managed to get exactly the data I am looking for, but I'm having difficulty figuring out how to score that data.

Here is the code:

import krakenex
import pandas as pd

api = krakenex.API()

# Define currency pairs and their corresponding names
currency_pairs = [('XETHXXBT', 'ETH/BTC'), ('XXBTZEUR', 'BTC/EUR'), ('XXBTZUSD', 'BTC/USD'), ('XXBTZGBP', 'BTC/GBP'), ('XETHZEUR', 'ETH/EUR'), ('XETHZGBP', 'ETH/GBP'), ('XETHZUSD', 'ETH/USD'), ('EURGBP', 'EURGBP'), ('ZEURZUSD', 'EUR/USD'), ('ZGBPZUSD', 'GBP/USD'), ('PAXGXBT', 'PAXG/BTC'), ('PAXGETH', 'PAXG/ETH'), ('PAXGEUR', 'PAXG/EUR'), ('PAXGUSD', 'PAXG/USD'), ('XXRPXXBT', 'XRP/BTC'), ('XRPETH', 'XRP/ETH'), ('XXRPZEUR', 'XRP/EUR'), ('XRPGBP', 'XRP/GBP'), ('XXRPZUSD', 'XRP/USD')]
time_frames = ['1', '5', '15', '30', '60', '240', '1440', '10080']

for pair, pair_name in currency_pairs:
    for tf in time_frames:
        print(f"{tf} minute m/a ({pair_name})")

        # Fetch OHLC data for the given pair and time frame
        ohlc_data = api.query_public('OHLC', {'pair': pair, 'interval': tf})

        # Convert the data to a pandas dataframe
        df = pd.DataFrame(ohlc_data['result'][pair], columns=['time', 'open', 'high', 'low', 'close', 'vwap', 'volume', 'count'])
        df['time'] = pd.to_datetime(df['time'], unit='s')
        df.set_index('time', inplace=True)

        # Calculate the moving averages
        last_20_candles = df.iloc[-21:-1]
        last_20_close_prices = last_20_candles['close'].astype(float).tolist()
        avg_last_20_close_price = sum(last_20_close_prices) / len(last_20_close_prices)
        print(f"20 period m/a: {avg_last_20_close_price}")

        last_50_candles = df.iloc[-51:-1]
        last_50_close_prices = last_50_candles['close'].astype(float).tolist()
        avg_last_50_close_price = sum(last_50_close_prices) / len(last_50_close_prices)
        print(f"50 period m/a: {avg_last_50_close_price}")

        last_200_candles = df.iloc[-201:-1]
        last_200_close_prices = last_200_candles['close'].astype(float).tolist()
        avg_last_200_close_price = sum(last_200_close_prices) / len(last_200_close_prices)
        print(f"200 period m/a: {avg_last_200_close_price}")

        print("\n")
Reply


Messages In This Thread
Please help me. - by SuchUmami - May-05-2023, 05:18 PM
RE: Please help me. - by deanhystad - May-05-2023, 05:29 PM
RE: Please help me. - by SuchUmami - May-05-2023, 05:32 PM
RE: Please help me. - by deanhystad - May-05-2023, 07:11 PM
RE: Please help me. - by SuchUmami - May-05-2023, 07:22 PM
RE: Please help me. - by SuchUmami - May-05-2023, 07:56 PM
RE: Please help me. - by deanhystad - May-05-2023, 08:34 PM
RE: Please help me. - by SuchUmami - May-06-2023, 10:27 AM
RE: Please help me. - by snippsat - May-06-2023, 05:53 PM
RE: Please help me. - by SuchUmami - May-07-2023, 01:44 PM
RE: Please help me. - by snippsat - May-07-2023, 04:24 PM
RE: Please help me. - by SuchUmami - May-08-2023, 09:19 AM
RE: Please help me. - by snippsat - May-08-2023, 01:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020