Skip to content

Commit

Permalink
tradier slight request delay
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonDane committed Oct 28, 2023
1 parent 1ac1920 commit c1774fd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tradierAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import requests
from dotenv import load_dotenv
from time import sleep

from helperAPI import Brokerage, printAndDiscord, printHoldings, stockOrder


def make_request(endpoint, BEARER_TOKEN, data=None, params=None, method="GET"):
def make_request(endpoint, BEARER_TOKEN, data=None, params=None, method="GET") -> dict | None:
try:
if method == "GET":
response = requests.get(
Expand Down Expand Up @@ -40,11 +41,13 @@ def make_request(endpoint, BEARER_TOKEN, data=None, params=None, method="GET"):
json_response = response.json()
if json_response.get("fault") and json_response["fault"].get("faultstring"):
raise Exception(json_response["fault"]["faultstring"])
sleep(0.1)
return json_response
except Exception as e:
print(f"Error making request to Tradier API {endpoint}: {e}")
print(f"Response: {response}")
print(traceback.format_exc())
sleep(1)
return None


Expand Down Expand Up @@ -133,7 +136,7 @@ def tradier_holdings(tradier_o: Brokerage, loop=None):
obj,
params={"symbols": sym, "greeks": "false"},
)
if price_response is None:
if price_response is None or price_response.get("quotes").get("quote").get("last") is None:
current_price.append(0)
current_price.append(price_response["quotes"]["quote"]["last"])
# Print and send them
Expand Down Expand Up @@ -191,8 +194,7 @@ def tradier_transaction(tradier_o: Brokerage, orderObj: stockOrder, loop=None):
)
continue
if (
json_response.get("order") is not None
and json_response["order"].get("status") is not None
json_response.get("order").get("status") is not None
):
printAndDiscord(
f"Tradier account {account}: {orderObj.get_action()} {orderObj.get_amount()} of {s}: {json_response['order']['status']}",
Expand Down

0 comments on commit c1774fd

Please sign in to comment.