Posts: 230
Threads: 39
Joined: Mar 2020
i'm trying to download stock data from yahoo! finance....
in anyway - i'm trying to have a symbol to download by loading the symbol/tickers from a file....
i know my code is awful, but i'll be glad to receive help:
import yfinance as yf
import pandas as pd
import plotly.graph_objects as go
def symbol_tracker(symbol):
with open("/home/tal/investing/Ticker.csv", "r") as file:
for line in file:
if line != "\n":
yf.download(symbol, start='1900-01-01')
else:
print("end of data")
return line
symbol_tracker("/home/tal/investing/Ticker.csv")
def symbol_saver(df):
pass
fig = go.Figure(go.Candlestick(x=df.index,
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close']))
fig.show() Output: 1 Failed download:
- /HOME/TAL/INVESTING/TICKER.CSV: No data found for this date range, symbol may be delisted
[*********************100%***********************] 1 of 1 completed
1 Failed download:
- /HOME/TAL/INVESTING/TICKER.CSV: No data found for this date range, symbol may be delisted
Traceback (most recent call last):
File "/home/tal/PycharmProjects/pythonProject2/experiment2.py", line 16, in <module>
symbol_tracker("/home/tal/investing/Ticker.csv")
File "/home/tal/PycharmProjects/pythonProject2/experiment2.py", line 10, in symbol_tracker
yf.download(symbol, start='1900-01-01')
File "/home/tal/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/yfinance/multi.py", line 118, in download
_time.sleep(0.01)
KeyboardInterrupt
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
one additional element i need basically is saving the data onto csv files with having the name of files by their tickers...
i'll be glad for assistance with this...
thanks
Posts: 12,022
Threads: 484
Joined: Sep 2016
Dec-10-2022, 07:26 AM
(This post was last modified: Dec-10-2022, 07:27 AM by Larz60+.)
I have software that downloads end of day data (including all symbols) for the following markets:
Output: AMEX: American Stock Exchange
ASX: Australian Securities Exchange
CFE: Chicago Futures Exchange
EUREX: EUREX Futures Exchange
FOREX: Foreign Exchange
HKEX: Hong Kong Stock Exchange
INDEX: Global Indices
KCBT: Kansas City Board of Trade
LIFFE: LIFFE Futures and Options
LSE: London Stock Exchange
MGEX: Minneapolis Grain Exchange
NASDAQ: NASDAQ Stock Exchange
NYBOT: New York Board of Trade
NYSE: New York Stock Exchange
OTCBB: OTC Bulletin Board
SGX: Singapore Stock Exchange
TSX: Toronto Stock Exchange
TSXV: Toronto Venture Exchange
USMF: Mutual Funds
WCE: Winnipeg Commodity Exchang
It then processes that data and creates a json file with the following format:
data is end of day dec 9, 2022
Output: {
"AMEX": {
"AAA": {
"Name": "First Priority Clo Bond ETF",
"High": "24.33",
"Low": "24.33",
"Close": "24.33",
"Volume": "100",
"Change Amount": "-0.01",
"Change Direction": "dn",
"Pct. Change": "0.02",
"Stock Data": "https://www.eoddata.com/stockquote/AMEX/AAA.htm",
"Quote and Chart": "https://www.eoddata.com/stockquote/AMEX/AAA.htm"
},
"AAAU": {
"Name": "GS Physical Gold ETF",
"High": "17.91",
"Low": "17.78",
"Close": "17.81",
"Volume": "474,900",
"Change Amount": "0.07",
"Change Direction": "up",
"Pct. Change": "0.37",
"Stock Data": "https://www.eoddata.com/stockquote/AMEX/AAAU.htm",
"Quote and Chart": "https://www.eoddata.com/stockquote/AMEX/AAAU.htm"
},
"AAMC": {
"Name": "Altisource Asset Management Corp Com",
"High": "23.68",
"Low": "22.50",
"Close": "22.50",
"Volume": "6,400",
"Change Amount": "0.00",
"Change Direction": "nc",
"Pct. Change": "0.00",
"Stock Data": "https://www.eoddata.com/stockquote/AMEX/AAMC.htm",
"Quote and Chart": "https://www.eoddata.com/stockquote/AMEX/AAMC.htm"
},
"AAU": {
"Name": "Almaden Minerals",
"High": "0.2483",
"Low": "0.2351",
"Close": "0.2400",
"Volume": "102,900",
"Change Amount": "0.0000",
"Change Direction": "nc",
"Pct. Change": "0.00",
"Stock Data": "https://www.eoddata.com/stockquote/AMEX/AAU.htm",
"Quote and Chart": "https://www.eoddata.com/stockquote/AMEX/AAU.htm"
},
This works like a charm, and gets and processes all data each day in less than 10 minutes.
If interrupted at any point, it can be restarted and will pick up where it left off.
Any interest?
Posts: 230
Threads: 39
Joined: Mar 2020
Dec-10-2022, 11:55 AM
(This post was last modified: Dec-14-2022, 07:58 PM by astral_travel.)
well, what i need is historical data, so i can plot a chart from stock inception to present, and also work on the data to find patterns, so it has to be historical...got something for me ?
btw, i noticed that in your data - it doesn't print out Open...only High, Low, Close and Volume....
Posts: 12,022
Threads: 484
Joined: Sep 2016
you can download nasdaq historical data here (one symbol at a time, 10 years):
https://www.nasdaq.com/market-activity/q...historical
Also Kagle has this site (which I never used):
https://www.kaggle.com/datasets/tsaustin...nings-data
Posts: 230
Threads: 39
Joined: Mar 2020
okay, i mean, Yahoo! Finance gives you historical data since day of inception (i think), but surely more than 10 yrs,
but anyway - i got stuck in building a function that will take the tickers from the Ticker.csv file and load it into yf.download(symbol, start='1900-01-01') line, where 'symbol' will be changed into the given ticker...
Posts: 453
Threads: 16
Joined: Jun 2022
(Dec-09-2022, 07:50 PM)astral_travel Wrote: i'm trying to download stock data from yahoo! finance....
in anyway - i'm trying to have a symbol to download by loading the symbol/tickers from a file....
i know my code is awful, but i'll be glad to receive help:
import yfinance as yf
import pandas as pd
import plotly.graph_objects as go
def symbol_tracker(symbol):
with open("/home/tal/investing/Ticker.csv", "r") as file:
for line in file:
if line != "\n":
yf.download(symbol, start='1900-01-01')
else:
print("end of data")
return line
symbol_tracker("/home/tal/investing/Ticker.csv")
def symbol_saver(df):
pass
fig = go.Figure(go.Candlestick(x=df.index,
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close']))
fig.show() one additional element i need basically is saving the data onto csv files with having the name of files by their tickers...
i'll be glad for assistance with this...
thanks
I've spotted and error in your code...
def symbol_tracker(symbol):
with open("/home/tal/investing/Ticker.csv", "r") as file:
for line in file:
if line != "\n":
yf.download(symbol, start='1900-01-01')
else:
print("end of data")
return line
# this call is passing the path and file name to your function. Should this not be a symbol name?
symbol_tracker("/home/tal/investing/Ticker.csv") ... which may or may not fix things; untested.
I don't use Pandas, so I'm unsure about the code from this point down.
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Posts: 230
Threads: 39
Joined: Mar 2020
(Dec-10-2022, 04:59 PM)rob101 Wrote: (Dec-09-2022, 07:50 PM)astral_travel Wrote: i'm trying to download stock data from yahoo! finance....
in anyway - i'm trying to have a symbol to download by loading the symbol/tickers from a file....
i know my code is awful, but i'll be glad to receive help:
import yfinance as yf
import pandas as pd
import plotly.graph_objects as go
def symbol_tracker(symbol):
with open("/home/tal/investing/Ticker.csv", "r") as file:
for line in file:
if line != "\n":
yf.download(symbol, start='1900-01-01')
else:
print("end of data")
return line
symbol_tracker("/home/tal/investing/Ticker.csv")
def symbol_saver(df):
pass
fig = go.Figure(go.Candlestick(x=df.index,
open=df['Open'],
high=df['High'],
low=df['Low'],
close=df['Close']))
fig.show() one additional element i need basically is saving the data onto csv files with having the name of files by their tickers...
i'll be glad for assistance with this...
thanks
I've spotted and error in your code...
def symbol_tracker(symbol):
with open("/home/tal/investing/Ticker.csv", "r") as file:
for line in file:
if line != "\n":
yf.download(symbol, start='1900-01-01')
else:
print("end of data")
return line
# this call is passing the path and file name to your function. Should this not be a symbol name?
symbol_tracker("/home/tal/investing/Ticker.csv") ... which may or may not fix things; untested.
I don't use Pandas, so I'm unsure about the code from this point down.
yes, you are correct, when i write a name of a symbol as argument - it works, it downloads the file,
but what i'm trying to do - is have a function that takes the list in the Ticker.csv file and gives the tickers there as arguments for the second function, i don't know how to do that...
do you understand what i want to do ?
Posts: 230
Threads: 39
Joined: Mar 2020
sorry if (with the question at the end) it sounded demanding or something,...it's the free translation from hebrew that sounds like that, was no such intent...
|