Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

avatar image
REFINITIV
Question by jaredd.matutina01 · Jul 20, 2021 at 01:17 PM · eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikontime-zone

How to convert the timezone of the API data result from UTC to IST?

For an external client, she is using the below code to get historical data using Phyton from EIkon

ek.set_app_key('***')

data=ek.get_timeseries('SBI.NS', interval='tick')

data.tail(10)


output

SBI.NS VALUE VOLUME

Date

2021-07-09 10:20:09.000 423.75 6

2021-07-09 10:20:21.000 423.75 10

2021-07-09 10:20:24.000 423.75 15

2021-07-09 10:20:37.000 423.75 1

2021-07-09 10:20:44.000 423.75 300

2021-07-09 10:21:39.000 423.75 1

2021-07-09 10:26:15.000 423.75 1


The timestamp is in UTC. She would like to know if there is a way she can get the timestamp of the results in IST.

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

5 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Alex Putkov.1 · Jul 26, 2021 at 01:06 PM

@jonathan.legrand

The pythonic way is to utilize vectorized methods wherever possible instead of your own loops. The main reason is that vectorized methods are optimized for runtime and typically run faster than your own loops (sometimes by an order of magnitude faster). Vectorized methods also improve readability of the code by making the code more compact.

@jaredd.matutina01

Please see an example of of converting the timezone in the dataframe index from UTC to the timezone of your choice on this thread.

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
jonathan.legrand ♦♦ · Jul 26, 2021 at 01:40 PM 0
Share

This is a very good point, maybe this is better for you @jaredd.matutina01 then:


import pytz

data.index = data.index.tz_localize(pytz.utc).tz_convert('Asia/Kolkata')
avatar image
REFINITIV
Answer by jonathan.legrand · Jul 26, 2021 at 11:56 AM

Hi @jaredd.matutina01 ,


I would suggest looking this up on StackOverflow:

https://stackoverflow.com/questions/4770297/convert-utc-datetime-string-to-local-datetime


Does this provide the answer you're looking for?


E.g.:


import datetime
from pytz import timezone
ist = []
for i in data.index:
    try:
        _ist = datetime.datetime.strptime(str(i), '%Y-%m-%d %H:%M:%S.%f')
        _ist = _ist.astimezone(timezone('Asia/Kolkata'))
        _ist = _ist.strftime("%Y-%m-%d %H:%M:%S.%f")
    except:
        _ist = datetime.datetime.strptime(str(i), '%Y-%m-%d %H:%M:%S')
        _ist = _ist.astimezone(timezone('Asia/Kolkata'))
        _ist = _ist.strftime("%Y-%m-%d %H:%M:%S")
    ist.append(_ist)
data.index = ist
Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
akshmita · Jul 30, 2021 at 09:21 AM 0
Share

@jonathan.legrand @jaredd.matutina01

I ran the above code but the data index remained the same. This is what I ran:

ist = []

for i in data.index:

try:

_ist = datetime.datetime.strptime(str(i), '%Y-%m-%d %H:%M:%S.%f')

_ist = _ist.astimezone(timezone('Asia/Kolkata'))

_ist = _ist.strftime("%Y-%m-%d %H:%M:%S.%f")

except:

_ist = datetime.datetime.strptime(str(i), '%Y-%m-%d %H:%M:%S')

_ist = _ist.astimezone(timezone('Asia/Kolkata'))

_ist = _ist.strftime("%Y-%m-%d %H:%M:%S")

ist.append(_ist)

data.index = ist

data.tail()

but the index remained utc

avatar image
REFINITIV
Answer by jaredd.matutina01 · Jul 27, 2021 at 08:23 AM

Thank you guys for these inputs!


Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
Answer by akshmita · Jul 30, 2021 at 09:16 AM

@jaredd.matutina01 @Alex Putkov. @jonathan.legrand

Hi, I tried this code but got the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-bcd1c96da781> in <module>
      1 import pytz
      2 ----> 3 data.index = data.index.tz_localize(pytz.utc).tz_convert('Asia/Kolkata')

AttributeError: 'Index' object has no attribute 'tz_localize
Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
jonathan.legrand ♦♦ · Jul 30, 2021 at 09:33 AM 0
Share

Hi @akshmita ,


That will be because the Python objects used as indices in your pandas data-frame (if indeed 'data ' is a pandas data-frame in your code) are not of type 'pandas.core.indexes.datetimes.DatetimeIndex'. Would you mind either (i) showing us more of your code that leads to your 'data ' object or (ii) the object type of your index? Without this information, we will not be able to help.

avatar image
Answer by akshmita · Jul 30, 2021 at 12:35 PM

@jonathan.legrand here's the full code

import eikon as ek

import datetime as dt

from datetime import time

import pytz


ek.set_app_key('.....')

data=ek.get_timeseries('SBI.NS', interval='tick')

data.index = data.index.tz_localize(pytz.utc).tz_convert('Asia/Kolkata')

data.tail()

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
Alex Putkov.1 ♦♦ · Jul 30, 2021 at 02:38 PM 0
Share

@akshmita

I have no problem running this code on my end. Could you check whether you get any values in the dataframe? I'm thinking that perhaps for some reason get_timeseries method does not return any timeseries for you. Comment out the line that converts the timezone for the index and run the code to see what's returned into the dataframe. If the dataframe looks ok to you, check the type for the index. Run

type(data.index)

The expected results is pandas.core.indexes.datetimes.DatetimeIndex. What do you get?

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
11 People are following this question.

Related Questions

Trying to fetch Close Bid Price for CMO tranche from Python

data_from or data_to parameter, which timezone?

How to get all investors for a list of stocks, historically with the python API

Time Zone problem in python API function get_timeseries

Time zones for overnight deposits in time series data

  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Intelligent Tagging
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open Calais
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • RDMS
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • Workspace SDK
    • Element Framework
    • Grid
  • World-Check Data File
  • 中文论坛
  • Explore
  • Tags
  • Questions
  • Badges