Skip to content

Commit

Permalink
Merge pull request #165 from justvisiting/hitech-custom-changes
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
timkpaine committed Jun 13, 2023
2 parents cc4bd48 + 6b1f9bc commit 95bc792
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
50 changes: 26 additions & 24 deletions tdameritrade/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,30 +451,32 @@ def optionsDF(
expMonth=expMonth,
optionType=optionType,
)
for date in dat["callExpDateMap"]:
for strike in dat["callExpDateMap"][date]:
ret.extend(dat["callExpDateMap"][date][strike])
for date in dat["putExpDateMap"]:
for strike in dat["putExpDateMap"][date]:
ret.extend(dat["putExpDateMap"][date][strike])

df = pd.DataFrame(ret)
for col in (
"tradeTimeInLong",
"quoteTimeInLong",
"expirationDate",
"lastTradingDay",
):
df[col] = pd.to_datetime(df[col], unit="ms")

for col in (
"interestRate",
"underlyingPrice",
):
if col in dat:
df[col] = dat[col]

return df
if dat["status"] == "SUCCESS":
for date in dat["callExpDateMap"]:
for strike in dat["callExpDateMap"][date]:
ret.extend(dat["callExpDateMap"][date][strike])
for date in dat["putExpDateMap"]:
for strike in dat["putExpDateMap"][date]:
ret.extend(dat["putExpDateMap"][date][strike])

df = pd.DataFrame(ret)
for col in (
"tradeTimeInLong",
"quoteTimeInLong",
"expirationDate",
"lastTradingDay",
):
df[col] = pd.to_datetime(df[col], unit="ms")

for col in (
"interestRate",
"underlyingPrice",
):
if col in dat:
df[col] = dat[col]
return df
raise (Exception(dat))

def movers(self, index, direction="up", change="percent"):
"""request market movers
Expand Down Expand Up @@ -551,7 +553,7 @@ def placeOrder(self, accountId, order):
order (JSON): order instance to place
"""
return self._request(
PLACE_ORDER.format(accountId=accountId), method="POST", json=order
PLACE_ORDER.format(accountId=accountId), method="POST", data=order
)

def replaceOrder(self, accountId, orderId, order):
Expand Down
2 changes: 1 addition & 1 deletion tdameritrade/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def handle_error_response(resp):
data = json.loads(body)
message = data.get("error", body)
except Exception:
raise codes[resp.status_code]()
raise codes[resp.status_code](resp)
raise codes[resp.status_code](
message=message, code=resp.status_code, data=data, response=resp
)
Expand Down

0 comments on commit 95bc792

Please sign in to comment.