hootnot / oanda-api-v20

OANDA REST-V20 API wrapper. Easy access to OANDA's REST v20 API with oandapyV20 package. Checkout the Jupyter notebooks!
MIT License
398 stars 107 forks source link

Wrong bar values? #210

Closed Azuriye closed 5 months ago

Azuriye commented 5 months ago

I'm struggling to get the correct OHLC values from the most recent bar.

from oandapyV20 import API
from oandapyV20.endpoints.instruments import InstrumentsCandles

accountID = ""
access_token = ""

api = API(access_token=access_token, environment="practice")

instrument = "EUR_JPY"
granularity = "M15" 

params = {
    "count": 1,
    "granularity": granularity,
}

candles_request = InstrumentsCandles(instrument=instrument, params=params)
try:    
    response = api.request(candles_request)
    historical_data = response.get("candles", [])

    for candle in historical_data:
        print(f"Time: {candle['time']}, Open: {candle['mid']['o']}, High: {candle['mid']['h']}, Low: {candle['mid']['l']}, Close: {candle['mid']['c']}")
except Exception as e:
    print(f"Error: {e}")

This is the print statement: Time: 2024-01-26T21:45:00.000000000Z, Open: 160.778, High: 160.829, Low: 160.733, Close: 160.813

But on my MT4 M15 EURJPY Chart, it shows image

Am I doing something wrong from my side?