Giter VIP home page Giter VIP logo

Comments (4)

dchrostowski avatar dchrostowski commented on May 29, 2024

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.

dchrostowski avatar dchrostowski commented on May 29, 2024

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.

jcdocka avatar jcdocka commented on May 29, 2024

All looks great! Thanks! I wasn't sure what was available and the syntax

from investopedia_simulator_api.

dchrostowski avatar dchrostowski commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.