Skip to content

Commit

Permalink
feat: review request
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjanrak committed Jul 5, 2021
1 parent c68859d commit 5754876
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions kiteconnect/connect.py
Expand Up @@ -11,7 +11,7 @@
from six.moves.urllib.parse import urljoin
import csv
import json
from dateutil.parser import parse
from dateutil.parser import datetimeparse
from dateutil.tz import tzoffset
from dateutil.utils import default_tzinfo
import hashlib
Expand Down Expand Up @@ -266,7 +266,7 @@ def generate_session(self, request_token, api_secret):
self.set_access_token(resp["access_token"])

if resp["login_time"] and self.is_timestamp(resp["login_time"]):
resp["login_time"] = self.set_tz(resp["login_time"])
resp["login_time"] = self.parseDateTime(resp["login_time"])

return resp

Expand Down Expand Up @@ -401,7 +401,7 @@ def _format_response(self, data):
# Convert date time string to datetime object
for field in ["order_timestamp", "exchange_timestamp", "created", "last_instalment", "fill_timestamp", "timestamp", "last_trade_time"]:
if item.get(field) and self.is_timestamp(item[field]):
item[field] = self.set_tz(item[field])
item[field] = self.parseDateTime(item[field])

return _list[0] if type(data) == dict else _list

Expand Down Expand Up @@ -636,7 +636,7 @@ def _format_historical(self, data):
records = []
for d in data["candles"]:
record = {
"date": self.set_tz(d[0]),
"date": self.parseDateTime(d[0]),
"open": d[1],
"high": d[2],
"low": d[3],
Expand Down Expand Up @@ -798,7 +798,7 @@ def _parse_instruments(self, data):

# Parse date
if self.is_timestamp(row["expiry"]):
row["expiry"] = self.set_tz(row["expiry"]).date()
row["expiry"] = self.parseDateTime(row["expiry"]).date()

records.append(row)

Expand All @@ -825,7 +825,7 @@ def _parse_mf_instruments(self, data):

# Parse date
if self.is_timestamp(row["last_price_date"]):
row["last_price_date"] = self.set_tz(row["last_price_date"]).date()
row["last_price_date"] = self.parseDateTime(row["last_price_date"]).date()

records.append(row)

Expand All @@ -834,16 +834,16 @@ def _parse_mf_instruments(self, data):
def is_timestamp(self, string):
"""Checks if string is timestamp"""
try:
parse(string)
datetimeparse(string)
return True
except ValueError:
return False

def set_tz(self, string):
def parseDateTime(self, string):
"""Set default timezone to IST for naive time object"""
# Default timezone for all datetime object
default_tz = tzoffset("Asia/Kolkata", 19800)
return default_tzinfo(parse(string), default_tz)
return default_tzinfo(datetimeparse(string), default_tz)

def _user_agent(self):
return (__title__ + "-python/").capitalize() + __version__
Expand Down

0 comments on commit 5754876

Please sign in to comment.