Alpha Vantage - Isolate Stock Price












1















Using Python I can access most of the Alpha Vantage APIs and get the results either as a tuple or a dict. What I want is just the stock price at a point in time. With "global quote", for example, I get all the data but cannot parse or divide the tuple / dict into the individual items.



Has anyone done this? I'd be grateful to see the code.



The API returns the following data; it is type dict with len 1. What I need is the price (108.29) in a normal floating point variable.



 (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})









share|improve this question




















  • 1





    Have you read up on how to use tuples and dictionaries in Python? What's the specific problem you're having accessing the data you need?

    – jonrsharpe
    Nov 17 '18 at 21:22











  • I sure have. The API returns the following data; it is type 'dict' with len '1'. What I need is the price (108.29) in a normal floating point variable. (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})

    – Fred B
    Nov 19 '18 at 0:53


















1















Using Python I can access most of the Alpha Vantage APIs and get the results either as a tuple or a dict. What I want is just the stock price at a point in time. With "global quote", for example, I get all the data but cannot parse or divide the tuple / dict into the individual items.



Has anyone done this? I'd be grateful to see the code.



The API returns the following data; it is type dict with len 1. What I need is the price (108.29) in a normal floating point variable.



 (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})









share|improve this question




















  • 1





    Have you read up on how to use tuples and dictionaries in Python? What's the specific problem you're having accessing the data you need?

    – jonrsharpe
    Nov 17 '18 at 21:22











  • I sure have. The API returns the following data; it is type 'dict' with len '1'. What I need is the price (108.29) in a normal floating point variable. (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})

    – Fred B
    Nov 19 '18 at 0:53
















1












1








1








Using Python I can access most of the Alpha Vantage APIs and get the results either as a tuple or a dict. What I want is just the stock price at a point in time. With "global quote", for example, I get all the data but cannot parse or divide the tuple / dict into the individual items.



Has anyone done this? I'd be grateful to see the code.



The API returns the following data; it is type dict with len 1. What I need is the price (108.29) in a normal floating point variable.



 (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})









share|improve this question
















Using Python I can access most of the Alpha Vantage APIs and get the results either as a tuple or a dict. What I want is just the stock price at a point in time. With "global quote", for example, I get all the data but cannot parse or divide the tuple / dict into the individual items.



Has anyone done this? I'd be grateful to see the code.



The API returns the following data; it is type dict with len 1. What I need is the price (108.29) in a normal floating point variable.



 (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})






python-3.x alpha alphavantage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 22:12









Martin Evans

27.3k132953




27.3k132953










asked Nov 17 '18 at 21:09









Fred BFred B

83




83








  • 1





    Have you read up on how to use tuples and dictionaries in Python? What's the specific problem you're having accessing the data you need?

    – jonrsharpe
    Nov 17 '18 at 21:22











  • I sure have. The API returns the following data; it is type 'dict' with len '1'. What I need is the price (108.29) in a normal floating point variable. (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})

    – Fred B
    Nov 19 '18 at 0:53
















  • 1





    Have you read up on how to use tuples and dictionaries in Python? What's the specific problem you're having accessing the data you need?

    – jonrsharpe
    Nov 17 '18 at 21:22











  • I sure have. The API returns the following data; it is type 'dict' with len '1'. What I need is the price (108.29) in a normal floating point variable. (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})

    – Fred B
    Nov 19 '18 at 0:53










1




1





Have you read up on how to use tuples and dictionaries in Python? What's the specific problem you're having accessing the data you need?

– jonrsharpe
Nov 17 '18 at 21:22





Have you read up on how to use tuples and dictionaries in Python? What's the specific problem you're having accessing the data you need?

– jonrsharpe
Nov 17 '18 at 21:22













I sure have. The API returns the following data; it is type 'dict' with len '1'. What I need is the price (108.29) in a normal floating point variable. (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})

– Fred B
Nov 19 '18 at 0:53







I sure have. The API returns the following data; it is type 'dict' with len '1'. What I need is the price (108.29) in a normal floating point variable. (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16', '}})

– Fred B
Nov 19 '18 at 0:53














2 Answers
2






active

oldest

votes


















0














The data you have given appears to have a slight problem at the end (there is a trailing comma and open quote). Assuming that the actual data does not have this problem, you could extract the price into a float variable as follows:



data = (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16'}})
price = float(data[1]['Global Quote']['05. price'])
print(price)


This would display the price as:



108.29


The API appears to be returing a tuple which consists of the word data and then a dictionary holding all the values. So first use [1] to access the dictionary. The Global Quote entry itself is a dictionary.






share|improve this answer































    0














    Thanks - I hadn't considered that as a possibility, i.e., a dict within a tuple. I am new to both Linux and Python so I guess that's kind of an amateur error. Nevertheless, I really appreciate the time taken to respond. I hope to pay that back in the near future.



    Just BTW, I notice w/Python if I code something wrong I sometimes don't get an error - exactly. For example, if I issue a print statement to debug and do not reference the above item correctly, the print command doesn't execute but I do not get an error code. In fact, code following the offensive print statement might also not execute; I might simply go to EOJ. Does that make sense? NB - I haven't compiled yet; still running in interpretive mode.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355612%2falpha-vantage-isolate-stock-price%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      The data you have given appears to have a slight problem at the end (there is a trailing comma and open quote). Assuming that the actual data does not have this problem, you could extract the price into a float variable as follows:



      data = (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16'}})
      price = float(data[1]['Global Quote']['05. price'])
      print(price)


      This would display the price as:



      108.29


      The API appears to be returing a tuple which consists of the word data and then a dictionary holding all the values. So first use [1] to access the dictionary. The Global Quote entry itself is a dictionary.






      share|improve this answer




























        0














        The data you have given appears to have a slight problem at the end (there is a trailing comma and open quote). Assuming that the actual data does not have this problem, you could extract the price into a float variable as follows:



        data = (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16'}})
        price = float(data[1]['Global Quote']['05. price'])
        print(price)


        This would display the price as:



        108.29


        The API appears to be returing a tuple which consists of the word data and then a dictionary holding all the values. So first use [1] to access the dictionary. The Global Quote entry itself is a dictionary.






        share|improve this answer


























          0












          0








          0







          The data you have given appears to have a slight problem at the end (there is a trailing comma and open quote). Assuming that the actual data does not have this problem, you could extract the price into a float variable as follows:



          data = (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16'}})
          price = float(data[1]['Global Quote']['05. price'])
          print(price)


          This would display the price as:



          108.29


          The API appears to be returing a tuple which consists of the word data and then a dictionary holding all the values. So first use [1] to access the dictionary. The Global Quote entry itself is a dictionary.






          share|improve this answer













          The data you have given appears to have a slight problem at the end (there is a trailing comma and open quote). Assuming that the actual data does not have this problem, you could extract the price into a float variable as follows:



          data = (' data ', {u'Global Quote': {u'05. price': u'108.2900', u'08. previous close': u'107.2800', u'10. change percent': u'0.9415%', u'03. high': u'108.8800', u'07. latest trading day': u'2018-11-16'}})
          price = float(data[1]['Global Quote']['05. price'])
          print(price)


          This would display the price as:



          108.29


          The API appears to be returing a tuple which consists of the word data and then a dictionary holding all the values. So first use [1] to access the dictionary. The Global Quote entry itself is a dictionary.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 22:22









          Martin EvansMartin Evans

          27.3k132953




          27.3k132953

























              0














              Thanks - I hadn't considered that as a possibility, i.e., a dict within a tuple. I am new to both Linux and Python so I guess that's kind of an amateur error. Nevertheless, I really appreciate the time taken to respond. I hope to pay that back in the near future.



              Just BTW, I notice w/Python if I code something wrong I sometimes don't get an error - exactly. For example, if I issue a print statement to debug and do not reference the above item correctly, the print command doesn't execute but I do not get an error code. In fact, code following the offensive print statement might also not execute; I might simply go to EOJ. Does that make sense? NB - I haven't compiled yet; still running in interpretive mode.






              share|improve this answer




























                0














                Thanks - I hadn't considered that as a possibility, i.e., a dict within a tuple. I am new to both Linux and Python so I guess that's kind of an amateur error. Nevertheless, I really appreciate the time taken to respond. I hope to pay that back in the near future.



                Just BTW, I notice w/Python if I code something wrong I sometimes don't get an error - exactly. For example, if I issue a print statement to debug and do not reference the above item correctly, the print command doesn't execute but I do not get an error code. In fact, code following the offensive print statement might also not execute; I might simply go to EOJ. Does that make sense? NB - I haven't compiled yet; still running in interpretive mode.






                share|improve this answer


























                  0












                  0








                  0







                  Thanks - I hadn't considered that as a possibility, i.e., a dict within a tuple. I am new to both Linux and Python so I guess that's kind of an amateur error. Nevertheless, I really appreciate the time taken to respond. I hope to pay that back in the near future.



                  Just BTW, I notice w/Python if I code something wrong I sometimes don't get an error - exactly. For example, if I issue a print statement to debug and do not reference the above item correctly, the print command doesn't execute but I do not get an error code. In fact, code following the offensive print statement might also not execute; I might simply go to EOJ. Does that make sense? NB - I haven't compiled yet; still running in interpretive mode.






                  share|improve this answer













                  Thanks - I hadn't considered that as a possibility, i.e., a dict within a tuple. I am new to both Linux and Python so I guess that's kind of an amateur error. Nevertheless, I really appreciate the time taken to respond. I hope to pay that back in the near future.



                  Just BTW, I notice w/Python if I code something wrong I sometimes don't get an error - exactly. For example, if I issue a print statement to debug and do not reference the above item correctly, the print command doesn't execute but I do not get an error code. In fact, code following the offensive print statement might also not execute; I might simply go to EOJ. Does that make sense? NB - I haven't compiled yet; still running in interpretive mode.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 17:50









                  Fred BFred B

                  83




                  83






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355612%2falpha-vantage-isolate-stock-price%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith