Comments (4)
So yeah you're on the right track. The stock quote data is pulled from the response of a POST request to /ajax/quotebox.aspx (see constants.py)
Here's an example response when I lookup GOOG:
<table class="table3 panel">
<tbody>
<tr>
<td class="txt moststock-name-td">
<h3 class="pill ok">GOOG</h3>
</td>
<td class="txt">
<div style="overflow: hidden;">
<h3 class="companyname">ALPHABET INC. CLASS C</h3>
<div class="marketname">(NASDAQ)</div>
</div>
</td>
<td class="num">
<h3 class="up inline">294.62</h3>
</td>
</tr>
</tbody>
</table>
<table class="table2 order" id="Table2" runat="server">
<tbody>
<tr>
<th>Last</th>
<td class="num">1,827.0100</td>
</tr>
<tr>
<th>Change</th>
<td class="num up">294.62</td>
</tr>
<tr>
<th>% Change</th>
<td class="num up">19.23</td>
</tr>
<tr>
<th>Volume</th>
<td class="num">807,349</td>
</tr>
<tr>
<th>Day's High</th>
<td class="num">1,835.0300</td>
</tr>
<tr>
<th>Day's Low</th>
<td class="num">1,789.4700</td>
</tr>
</tbody>
</table>
The data returned is limited - I'm not seeing anything for Open but it looks like you could easily scrape the Day's High and Day's Low by adding these xpath expressions to xpath_map
in parsers.py:
'days_high': '//table[@id="Table2"]/tbody/tr[5]/th[contains(text(),"Day\'s High")]/following-sibling::td/text()',
'days_low': '//table[@id="Table2"]/tbody/tr[6]/th[contains(text(),"Day\'s High")]/following-sibling::td/text()'
And yes, you're correct, you'd also have to modify the StockQuote
class in api_models.py to handle the additional information:
class StockQuote(object):
@coerce_method_params
def __init__(
self: object,
symbol: str,
name: str,
exchange: str,
last: Decimal,
change: Decimal,
change_percent: Decimal,
volume: int,
days_high: Decimal,
days_low: Decimal
):
self.symbol = symbol
self.name = name
self.last = last
self.exchange = exchange
self.change = change
self.change_percent = change_percent
self.volume = volume
self.days_high = days_high
self.days_low = days_low
These changes are actually pretty easy so I'm going to test and commit them to master.
As for getting the open price, I'll look into seeing if I can maybe scrape an additional resource on Investopedia's end that offers a bit more information than what's available when making a request to /ajax/quotebox.aspx
from investopedia_simulator_api.
actually, now that I think about it, the open price could be calculated by subtracting change
from last
.
self.open = self.last - self.change
I'll add that into the commit as well.
from investopedia_simulator_api.
All looks great! Thanks! I wasn't sure what was available and the syntax
from investopedia_simulator_api.
Merged in the changes. Here's how to get the open, high, and low:
quote = client.get_stock_quote('GOOG')
print(quote.days_high)
print(quote.days_low)
print(quote.open)
from investopedia_simulator_api.
Related Issues (20)
- Add support for asynchronous trading HOT 2
- write unit tests
- Publish to pip
- Add documentation
- Implement concurrent synchronous task queue for trades HOT 1
- Add additional error handling for trades
- Get Investopedia Login Cookie HOT 2
- KeyError: 'account_cookie' HOT 1
- Investopedia appears to not use UI4 cookie anymore HOT 6
- Cancelling an order HOT 3
- Stock quote limit? HOT 3
- Add better error handling for unquotable stocks. HOT 2
- line 213 in parsers.py not correctly indented (suppress one tabulation to fix it)
- How to fix 'open_orders' method
- Investopedia site change
- Refactor Portfolio class
- Cannot login? HOT 2
- Refactor Position class
- Method decorator to coerce HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from investopedia_simulator_api.