Yahoo Finance

FREEMIUM
By Api Dojo | Updated 4 hours ago | Finance
Popularity

9.9 / 10

Latency

1,671ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Need help writing data to csv or excel

Rapid account: Pranav Bankerbay
pranav.bankerbay
4 years ago

HI, can somebody help me with the code for writing the data pulled from Yahoo Finance (charts) to CSV in Python. Below is the data that I get. Thank you.

{“chart”:{“result”:[{“meta”:{“currency”:“USD”,“symbol”:“AMRN”,“exchangeName”:“NGM”,“instrumentType”:“EQUITY”,“firstTradeDate”:733654800,“regularMarketTime”:1579294801,“gmtoffset”:-18000,“timezone”:“EST”,“exchangeTimezoneName”:“America/New_York”,“regularMarketPrice”:19.91,“chartPreviousClose”:20.06,“previousClose”:20.06,“scale”:3,“priceHint”:2,“currentTradingPeriod”:{“pre”:{“timezone”:“EST”,“start”:1579251600,“end”:1579271400,“gmtoffset”:-18000},“regular”:{“timezone”:“EST”,“start”:1579271400,“end”:1579294800,“gmtoffset”:-18000},“post”:{“timezone”:“EST”,“start”:1579294800,“end”:1579309200,“gmtoffset”:-18000}},“tradingPeriods”:{“pre”:[[{“timezone”:“EST”,“start”:1579251600,“end”:1579271400,“gmtoffset”:-18000}]],“post”:[[{“timezone”:“EST”,“start”:1579294800,“end”:1579309200,“gmtoffset”:-18000}]],“regular”:[[{“timezone”:“EST”,“start”:1579271400,“end”:1579294800,“gmtoffset”:-18000}]]},“dataGranularity”:“5m”,“range”:“1d”,“validRanges”:[“1d”,“5d”,“1mo”,“3mo”,“6mo”,“1y”,“2y”,“5y”,“10y”,“ytd”,“max”]},“timestamp”:[1579262400,1579266000,1579266300,1579266600,1579266900,1579267200,1579267500,1579267800,1579268100,1579268400,1579268700,1579269000,1579269300,1579269600,1579270200,1579270500,1579271100,1579271400,1579271700,1579272000,1579272300,1579272600,1579272900,1579273200,1579273500,1579273800,1579274100,1579274400,1579274700,1579275000,1579275300,1579275600,1579275900,1579276200,1579276500,1579276800,1579277100,1579277400,1579277700,1579278000,1579278300,1579278600,1579278900,1579279200,1579279500,1579279800,1579280100,1579280400,1579280700,1579281000,1579281300,1579281600,1579281900,1579282200,1579282500,1579282800,1579283100,1579283400,1579283700,1579284000,1579284300,1579284600,1579284900,1579285200,1579285500,1579285800,1579286100,1579286400,1579286700,1579287000,1579287300,1579287600,1579287900,1579288200,1579288500,1579288800,1579289100,1579289400,1579289700,1579290000,1579290300,1579290600,1579290900,1579291200,1579291500,1579291800,1579292100,1579292400,1579292700,1579293000,1579293300,1579293600,1579293900,1579294200,1579294500,1579294800,1579295100,1579295400,1579295700,1579296000,1579296900,1579297200,1579297500,1579297800,1579298100,1579298700,1579300200,1579300500,1579300800,1579301100,1579301400,1579302000,1579303200,1579303500,1579305300,1579306500,1579307100,1579308300,1579308600,1579308900],“indicators”:{“quote”:[{“open”:[20.23,20.25,20.2,20.2,20.2,20.21,20.2,20.2,20.2,20.2,20.2,20.2,20.1999,20.16,20.18,20.1999,20.16,20.079999923706055,20.09000015258789,20.129499435424805,20.1299991607666,20.170000076293945,20.15999984741211,20.094999313354492,20.149999618530273,20.100000381469727,20.104999542236328,20.100000381469727,20.104999542236328,20.079999923706055,20.010000228881836,20.09000015258789,20.059999465942383,19.924999237060547,19.905000686645508,19.8799991607666,19.920000076293945,19.950000762939453,19.90999984741211,19.964099884033203,19.890199661254883,19.905000686645508,19.989999771118164,19.954700469970703,19.934999465942383,19.915000915527344,19.920000076293945,19.860000610351562,19.8799991607666,19.864999771118164,19.8799991607666,19.895000457763672,19.87529945373535,19.890100479125977,19.870100021362305,19.885000228881836,19.864999771118164,19.875,19.889999389648438,19.860000610351562,19.858999252319336,19.850000381469727,19.850000381469727,19.861900329589844,19.915000915527344,19.958099365234375,19.934999465942383,19.950000762939453,19.94499969482422,19.899999618530273,19.91349983215332,19.860000610351562,19.90999984741211,19.9060001373291,19.88520050048828,19.87540054321289,19.885000228881836,19.860000610351562,19.864999771118164,19.850000381469727,19.829999923706055,19.84000015258789,19.764999389648438,19.790000915527344,19.799999237060547,19.790000915527344,19.769699096679688,19.795000076293945,19.78499984741211,19.815000534057617,19.829999923706055,19.860000610351562,19.864999771118164,19.905000686645508,19.93000030517578,19.91,19.9,19.9,19.9,19.95,19.9,19.91,20.0,20.0,20.0,19.95,20.0,20.0,20.0,19.91,20.04,20.0,20.0,19.95,20.0,20.0,19.99,19.99,19.98,19.99],“high”:[20.23,20.25,20.2,20.2,20.25,20.25,20.2,20.2497,20.2,20.24,20.2,20.2,20.2,20.2,20.18,20.2,20.16,20.18000030517578,20.14620018005371,20.1299991607666,20.206899642944336,20.179000854492188,20.165000915527344,20.170000076293945,20.149999618530273,20.1200008392334,20.1299991607666,20.135000228881836,20.1200008392334,20.079999923706055,20.104999542236328,20.100099563598633,20.059999465942383,19.938499450683594,19.950000762939453,19.940000534057617,19.959999084472656,20.020000457763672,19.959999084472656,19.980499267578125,19.94499969482422,19.98979949951172,19.989999771118164,19.969999313354492,19.934999465942383,19.93000030517578,19.920000076293945,19.895000457763672,19.914899826049805,19.905000686645508,19.899999618530273,19.905000686645508,19.899999618530273,19.895000457763672,19.895000457763672,19.889999389648438,19.889999389648438,19.90999984741211,19.889999389648438,19.8700008392334,19.8700008392334,19.854999542236328,19.8700008392334,19.924999237060547,19.959999084472656,19.96500015258789,19.969999313354492,19.959999084472656,19.950000762939453,19.915000915527344,19.920000076293945,19.90999984741211,19.915000915527344,19.920000076293945,19.895000457763672,19.889999389648438,19.885000228881836,19.875,19.8799991607666,19.850000381469727,19.850000381469727,19.850000381469727,19.790000915527344,19.81369972229004,19.81999969482422,19.80500030517578,19.809999465942383,19.799999237060547,19.81999969482422,19.84000015258789,19.860000610351562,19.8700008392334,19.920000076293945,19.93429946899414,19.934999465942383,19.91,19.92,19.95,19.9,20.04,20.0,19.91,20.0,20.0,20.0,19.95,20.01,20.0,20.04,19.91,20.04,20.0,20.0,19.95,20.0,20.0,19.99,19.99,19.98,19.99],“close”:[20.23,20.1999,20.2,20.2,20.25,20.25,20.2,20.2497,20.2,20.2,20.2,20.2,20.16,20.2,20.18,20.1601,20.09,20.100000381469727,20.137500762939453,20.100099563598633,20.170000076293945,20.179000854492188,20.094999313354492,20.149999618530273,20.110000610351562,20.110000610351562,20.100000381469727,20.110000610351562,20.079999923706055,20.005399703979492,20.09000015258789,20.049999237060547,19.924999237060547,19.889999389648438,19.8700008392334,19.920000076293945,19.955400466918945,19.915000915527344,19.959999084472656,19.89299964904785,19.899999618530273,19.98979949951172,19.959999084472656,19.934999465942383,19.88990020751953,19.90999984741211,19.850000381469727,19.8700008392334,19.8700008392334,19.879899978637695,19.895000457763672,19.8799991607666,19.889999389648438,19.879899978637695,19.885000228881836,19.860000610351562,19.8700008392334,19.89349937438965,19.860000610351562,19.850000381469727,19.849899291992188,19.850000381469727,19.860000610351562,19.91200065612793,19.955400466918945,19.935400009155273,19.950000762939453,19.94499969482422,19.899999618530273,19.90999984741211,19.854999542236328,19.905399322509766,19.905000686645508,19.885000228881836,19.875,19.889999389648438,19.857999801635742,19.864999771118164,19.850000381469727,19.827499389648438,19.84000015258789,19.764999389648438,19.790000915527344,19.799999237060547,19.780000686645508,19.770000457763672,19.799999237060547,19.780099868774414,19.815000534057617,19.829999923706055,19.854999542236328,19.8700008392334,19.905000686645508,19.924999237060547,19.90999984741211,19.91,19.9,19.9,19.9,20.04,20.0,19.91,19.9,20.0,19.9002,19.95,20.01,20.0,20.0,19.91,20.04,20.0,20.0,19.95,20.0,20.0,19.99,19.99,19.98,19.99],“low”:[20.23,20.14,20.2,20.2,20.2,20.21,20.2,20.2,20.2,20.2,20.2,20.2,20.16,20.16,20.18,20.16,20.09,20.020000457763672,20.09000015258789,20.049999237060547,20.1200008392334,20.139999389648438,20.049999237060547,20.09000015258789,20.09000015258789,20.06999969482422,20.100000381469727,20.09000015258789,20.079999923706055,19.979999542236328,20.010000228881836,20.030000686645508,19.90999984741211,19.8799991607666,19.8700008392334,19.8700008392334,19.91790008544922,19.889999389648438,19.90999984741211,19.8700008392334,19.890199661254883,19.905000686645508,19.924999237060547,19.920000076293945,19.8799991607666,19.8799991607666,19.84000015258789,19.850000381469727,19.860000610351562,19.864999771118164,19.875,19.860000610351562,19.8700008392334,19.860000610351562,19.8700008392334,19.860000610351562,19.84000015258789,19.871700286865234,19.850000381469727,19.850000381469727,19.84000015258789,19.81999969482422,19.84000015258789,19.860000610351562,19.915000915527344,19.935400009155273,19.93000030517578,19.93000030517578,19.899999618530273,19.899999618530273,19.854999542236328,19.860000610351562,19.8799991607666,19.8799991607666,19.860000610351562,19.8700008392334,19.84000015258789,19.850000381469727,19.84000015258789,19.825000762939453,19.820100784301758,19.760000228881836,19.739999771118164,19.760000228881836,19.780000686645508,19.760000228881836,19.764999389648438,19.770000457763672,19.770000457763672,19.809999465942383,19.81999969482422,19.84000015258789,19.864999771118164,19.889999389648438,19.8799991607666,19.91,19.9,19.9,19.89,19.9,19.9,19.91,19.9,20.0,19.9002,19.95,20.0,20.0,20.0,19.91,20.04,20.0,20.0,19.95,20.0,20.0,19.99,19.99,19.98,19.99],“volume”:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,167154,87480,100810,107242,68672,171021,133466,78771,75217,49816,40224,124762,153564,52269,55703,159027,62656,85348,64181,44642,52699,26453,75584,54495,34100,47311,33402,52062,28470,79197,53157,39027,20813,25269,54723,22461,31565,25853,60650,98440,46175,36987,8551,33552,78131,57146,40614,25700,38587,31745,42460,52739,17181,12633,18132,13444,23261,23079,27611,38475,23305,39360,32407,47705,83693,63102,67684,82157,68797,44752,56532,76521,84134,100137,38784,259803,184359,298130,159442,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}]}}],“error”:null}}

Rapid account: Ghowe 16
ghowe16 Commented 4 years ago

With any JSON return from any API, you want to map it into an object in your language of choice. Work with the object instead. So I did a quick StackOverflow search and found this:
https://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object

The JSON will be converted into an object using the naming found in the JSON! Sweet, right?

Once you have it in an object, then you can dump it to Excel:
https://stackoverflow.com/questions/13437727/writing-to-an-excel-spreadsheet#13437855

Voila!

So in general, take any API output in JSON format, import it into ONE object in your language of choice (it will usually create nested objects/types) and then just iterate through the object like you would in any program. Put it to excel, take data to a screen, whatever!

Enjoy

p.s. A quick search also found this library for you: https://github.com/python-excel/xlwt

Rapid account: Apidojo
apidojo Commented 4 years ago

I am sorry that I cannot help you with coding, you may do Google or look for solution in Stack Overflow.

Join in the discussion - add comment below:

Login / Signup to post new comments