Dear all,
I have a small script, which should retrieve the current price of a stock, but on execution it does literally nothing. What’s my error?
Version 9.0.0 on MacOS
function getYahooFinancePrice()
{
const sheet = Api.GetActiveSheet();
const ticker = sheet.GetRange("A1").GetValue();
if (!ticker) {
Api.Ui.MessageBox("Please enter a stock ticker in cell A1.");
return;
}
const url = `https://query1.finance.yahoo.com/v7/finance/quote?symbols=${ticker}`;
ApiUrlRequest.Get(url, {}, function (response) {
try {
const data = JSON.parse(response);
const result = data.quoteResponse.result;
if (result && result.length > 0) {
const price = result[0].regularMarketPrice;
sheet.GetRange("B1").SetValue(price);
Api.Ui.MessageBox(`The current price of ${ticker} is ${price}`);
} else {
Api.Ui.MessageBox(`No data found for ticker: ${ticker}`);
}
} catch (e) {
Api.Ui.MessageBox("Failed to parse response or fetch price.");
}
} }})();
Hello @promexio
Try running the app in debug mode to get more information about the process of code execution:
Thx. Always the same error, no matter what the api link is:
sdk-all-min.js:1434 ReferenceError: ApiUrlRequest is not defined
at getStockPrice (eval at <anonymous> (eval at <anonymous> (sdk-all-min.js:1434:123)), <anonymous>:14:5)
at eval (eval at <anonymous> (eval at <anonymous> (sdk-all-min.js:1434:123)), <anonymous>:28:2)
at eval (eval at <anonymous> (sdk-all-min.js:1434:123), <anonymous>:3:8)
at k (sdk-all-min.js:1429:72)
at a.AscCommon.Qfd (sdk-all-min.js:1434:393)
at f.glg (sdk-all.js:18190:72)
at f.R0c (sdk-all.js:18189:84)
at d.R0c (sdk-all-min.js:1549:388)
at o.onRunMacros (code.js:2:272596)
at Jt (app.js:8:94698)
a.AscCommon.Qfd @ sdk-all-min.js:1434
glg @ sdk-all.js:18190
R0c @ sdk-all.js:18189
d.R0c @ sdk-all-min.js:1549
onRunMacros @ code.js:2
Jt @ app.js:8
(anonymous) @ app.js:8
(anonymous) @ app.js:8
g @ app.js:8
u @ app.js:8
c @ app.js:8
r.trigger @ app.js:8
h @ app.js:8
dispatch @ app.js:8
f.handle @ app.js:8
This error explicitly states that, whatever ApiUrlRequest
is, is not defined, i.e. it does not exist as a callable object for JavaScript.
Please check what it refers to and what the origin of this object.
Just an update:
I recently changed mind and the method. The initial idea was to load financial statements of stock exchanged tickers directly into onlyoffice via an api. I think this is sth rather for a plugin than a macro and for some real developper guys.
So I decided to bypass this. I use a python script which deploys standard yahoo finance module and I download the data via a pandas dataframe as easy json files.
Then I load the json files via macro in onlyoffice in a specific cell (get current cursor position). And afterwards, I have a second macro which parses the json files from that cell and writes the data into the defined columns.
It’s not perfect, but it works well and has a good performance also with numerous tickers.
Nevertheless a propper finance module for the investment guys would be much appreciated.
Kr
Gabriel
1 Like
I am glad to know. As for the “finance module” – you can start a new topic with detailed explanation of your idea for review. If possible, please provide any examples that allow achieving the goal of your suggestion in other processors.
I am closing this topic as solved.