From 76316bde25d5e41bd6aedb8bb957130f71b6d7d4 Mon Sep 17 00:00:00 2001 From: cryptographic-sphinx <72975337+cryptographic-sphinx@users.noreply.github.com> Date: Wed, 30 Dec 2020 22:42:28 +0200 Subject: [PATCH] New feature for robot.py Grab a quote for any symbol on the market --- pyrobot/robot.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pyrobot/robot.py b/pyrobot/robot.py index 2a147c3..c6ba002 100644 --- a/pyrobot/robot.py +++ b/pyrobot/robot.py @@ -362,7 +362,45 @@ def delete_trade(self, index: int) -> None: if index in self.trades: del self.trades[index] + + + def grab_any_live_quote(self, symbol: str) -> dict: + """Grabs the current quote for any symbol. + Makes a call to the TD Ameritrade Get Quotes endpoint with the + symbol you send as an argument. Returns a dictionary. + + Usage: + ---- + >>> trading_robot = PyRobot( + client_id=CLIENT_ID, + redirect_uri=REDIRECT_URI, + credentials_path=CREDENTIALS_PATH + ) + + >>> current_quote = trading_robot.grab_any_live_quote(symbol = 'MSFT') + >>> current_quote + { + "MSFT": { + "assetType": "EQUITY", + "assetMainType": "EQUITY", + "cusip": "594918104", + ... + "regularMarketPercentChangeInDouble": 0, + "delayed": true + } + } + + Returns: + ---- + dict -- A dictionary containing the quote for the symbol provided. + + """ + + # Grab the quote. + quote = self.session.get_quotes(symbol) + + def grab_current_quotes(self) -> dict: """Grabs the current quotes for all positions in the portfolio.