It is currently September 8th, 2024, 1:05 am

Market Prices

RSS, ATOM and other feeds, GMail, Stocks, any information retrieved from the internet
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Market Prices

Post by Yincognito »

emp00 wrote: May 29th, 2024, 8:47 pm
WTF^1. It's quite simple, if you think about it: inverting the global flag also inverts the "meaning" of the local ones, even though the same symbols are used locally. Real life example: if you talk about an overall sunny day and you say that for one hour the weather was different than for the rest of the day, it is implied that for that hour the weather was rainy; on the other hand, if you talk about an overall rainy day and you say the exact same thing, it is implied that for that hour the weather was sunny, so the complete opposite compared to the former. See how the global context completely changes the meaning of the local one? Same with regex.

WTF^2. The (REG_MKT|PRE_MKT) didn't work because it was not followed by the <\/curmktstatus> ending tag (or even < would have been enough), and the regex didn't know where to stop with the match given that .* is volatile (i.e. it lacked some fixed place where to "anchor" the pattern at its end). Also, the correct way would have been (?:REG_MKT|PRE_MKT) aka making it a NON capture group, otherwise it would have messed the StringIndex or the \N capture references and be returned as a capture instead of the desired <last> further down the pattern. The negative lookahead works precisely because it's "negative" and chooses that branch as soon as the first character after the preceding > is not R (for performance reasons, it never bothers with the following EG_MKT since the pattern was already matched).

WTF^3. Yeah, difficulties and obstacles are normal, but naturally the satisfaction is greater if you overcome them on your own, plus it helps you the next time you have a similar situation. All children fall and cry before learning to walk, there's no other way of learning that hitting your head against the wall and see who wins, lol. Anyway, I'm glad you gave it a try and managed to get something out of it, that's the spirit! The next times you'll figure out things in a shorter and shorter time. Didn't test it now and it will remain to be seen if the pattern is indeed what you really need, but just a little observation: I don't think the .*? before the | are necessary, since, like I said earlier, there isn't a fixed character or position in the string where to "anchor" the end of the .*? in order for the greedy match to have a functional purpose. Regex is almost always just an alternation of "fixed" and "variable" points, and usually the latter require the former to enclose them - if you say "from Paris to the end of the world" the result is undefined since there's no end of the world unless you're a flat earther, but if you say "from Paris to London" then the result is precise and you can work with it.

Keep up the attitude you showed when adjusting the pattern - you're on the right path! If it's too much, take a break and relax and come back stronger and with better ideas - you don't have to exhaust yourself every time! :thumbup: :great:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
ThomasB
Posts: 3
Joined: May 31st, 2024, 1:27 pm

Re: Market Prices

Post by ThomasB »

Thanks for your effort, this was exactly what I was looking for.

I am totally new to Rainmeter since I just installed it for Market Prices. So I am struggling to adapt your configuration for my instance.

Basically I looked what you wrote here:
emp00 wrote: May 29th, 2024, 8:47 pm

Code: Select all

; Price e.g. [mIndex1_Price]
RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<last>(.*)<\/last>.*?|.*?<last>(.*)<\/last>)
; Price change e.g. [mIndex1_UpDown]
RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<change>(.*)<\/change>.*?|.*<change>(.*)<\/change>)
; Price change% e.g. [mIndex1_ChangePer]
RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<change_pct>(.*)<\/change_pct>.*?|.*<change_pct>(.*)<\/change_pct>)
And changed my RegExp line in the MetMeaTemplate.inc accordingly. But I still can't see the after hour / pre market prices in the widget after reloading it. Is there anything else I have to do? Unfortunately the market just opened so I can't fiddle around further.
emp00
Posts: 117
Joined: October 7th, 2022, 8:08 pm

Re: Market Prices

Post by emp00 »

ThomasB wrote: May 31st, 2024, 1:33 pm Thanks for your effort, this was exactly what I was looking for. And changed my RegExp line in the MetMeaTemplate.inc accordingly. But I still can't see the after hour / pre market prices in the widget after reloading it. Is there anything else I have to do? Unfortunately the market just opened so I can't fiddle around further.
You need to do this:
  • 0) Make a backup of your complete MarketPrices skin directory, e.g. by zipping it: just in case!
  • 1) First change the 3 measures in question (see above) in MarketPrices.ini by replacing the RexEx lines, make sure not to "mix them up"
  • 2) Then change the same 3 measures in MetMeaTemplate.inc (here they're named with ^1^ placeholders, don't change the measure names, just the RexEx)
  • 3) Important: Now open StockSymbols.inc and find the line NumberOfStocks=XXX ==> change the number you have e.g. from 10 to 9
  • 4) Now reload the MarketPrices skin: Due to the change of NumberOfStocks it will process StockSymbols.inc and re-generate MoreThanOne.inc (the latter is part of the main MarketPrices.ini skin)
  • 5) Repeat Step 3+4 but change back to your desired total NumberOfStocks=XXX
  • 6) As last step, I always restart Rainmeter (close it completely and start again) --> done (just reloading MarketPrices might work as well, but not always in my case, therefore my habit became "restarting" which works reliably)
This may sound complicated but it's required do the lua script mechanics responsible for re-building the skin according to the number of stocks you're displaying. You only need to do this procedure when changing the code for the individual stock measures+meters, like the RegEx expressions.

Fyi: I have now been running the adjusted expressions (see above) for more than 2 days and can confirm they're working as designed. You should be seeing pre- and post-market prices when the market is in this state (in my case I only noticed this working for NASDAQ stocks, but could/might work for other markets as well). For European and Chinese stock markets I have not yet seen that CNBC delivers this data. During regular market of course the correct price is displayed, just as in Mordasius original skin.

Let us know if it works for your stocks as well, and in case not, please mention the relevant stock symbols and what exactly goes wrong. Have fun with the new functionality! :-)
emp00
Posts: 117
Joined: October 7th, 2022, 8:08 pm

Re: Market Prices

Post by emp00 »

Yincognito wrote: May 29th, 2024, 10:14 pm The (POST_MKT|PRE_MKT) didn't work because it was not followed by the <\/curmktstatus> ending tag (or even < would have been enough), and the regex didn't know where to stop with the match given that .* is volatile (i.e. it lacked some fixed place where to "anchor" the pattern at its end).
Ah, good to know! In the end, I'm happy with (?!REG_MKT) - it's shorter and works reliably so far.
Didn't test it now and it will remain to be seen if the pattern is indeed what you really need, but just a little observation: I don't think the .*? before the | are necessary, since, like I said earlier, there isn't a fixed character or position in the string where to "anchor" the end of the .*? in order for the greedy match to have a functional purpose. Regex is almost always just an alternation of "fixed" and "variable" points, and usually the latter require the former to enclose them
Just tested this, No1 my current regex and No2 removed the .*? you mentioned:

No1: (?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<last>(.*)<\/last>.*?|.*?<last>(.*)<\/last>)
No2: (?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<last>(.*)<\/last>|.*?<last>(.*)<\/last>)

Symption: No2 gives TWO matches (when curmktstatus=PRE_MKT or POST_MKT) - so it then matches both <last> prices. This works, if the first match is the correct one and in this case it probably is always the case, but I like it better if there's only one distinct match. You can surely explain the effect behind, I still cannot due this with any confidence without taking an hour of studying, probably. But I really like using regex101.com, this is really a big help.

Summary: I keep on going with these 3 working expressions. So far, so good - let's see what happens over the weekend, when all markets are closed. Well, just checked, NASDAQ just closed and the expressions are still doing their job correctly! I'm now 98% confident that I found a working solution, thanks to your strong guidance. The only open issue could be other exchanges around the globe where CNBC might deliver deviating xml potentially breaking these expressions. Anybody reading this and observing issues, please drop us a note.

Code: Select all

; Price e.g. [mIndex1_Price]
RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<last>(.*)<\/last>.*?|.*?<last>(.*)<\/last>)
; Price change e.g. [mIndex1_UpDown]
RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<change>(.*)<\/change>.*?|.*<change>(.*)<\/change>)
; Price change% e.g. [mIndex1_ChangePer]
RegExp=(?siU)^(?|.*<curmktstatus>(?!REG_MKT).*<extendedMktQuote>.*<change_pct>(.*)<\/change_pct>.*?|.*<change_pct>(.*)<\/change_pct>)
I'm happy! It's indeed rewarding when you have mastered a working regex. So simple 8-) :Whistle :)
ThomasB
Posts: 3
Joined: May 31st, 2024, 1:27 pm

Re: Market Prices

Post by ThomasB »

emp00 wrote: May 31st, 2024, 6:06 pm ...
Let us know if it works for your stocks as well, and in case not, please mention the relevant stock symbols and what exactly goes wrong. Have fun with the new functionality! :-)
Thank you very much for the detailed explanation. Unfortunately I'll have to wait until Monday before I can implement the changes. But I make sure to keep you updated then.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Market Prices

Post by Yincognito »

emp00 wrote: May 31st, 2024, 7:07 pm Ah, good to know!
[...]
I'm happy! It's indeed rewarding when you have mastered a working regex. So simple 8-) :Whistle :)
Excellent - yeah, no point altering the patterns if they work already, well done! :great:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
ThomasB
Posts: 3
Joined: May 31st, 2024, 1:27 pm

Re: Market Prices

Post by ThomasB »

emp00 wrote: May 31st, 2024, 6:06 pm [...]
Let us know if it works for your stocks as well [...]
Thanks again, works great :bow:
emp00
Posts: 117
Joined: October 7th, 2022, 8:08 pm

Re: Market Prices

Post by emp00 »

Excellent- I also confirm the above regex working (last weekend and total 3 workdays pre, regular & post market tested). Working fine both in mordasius "Market Prices" and "MyPortfolio" skins.:thumbup:
8ksmiff
Posts: 1
Joined: July 15th, 2024, 1:45 pm

Re: Market Prices

Post by 8ksmiff »

Mordasius wrote: February 14th, 2021, 6:18 am finMarketsPic.jpg
Hi Mordasius, Thank you for the wonderful skin. I have one small concern , since most of the Indian Indices are not on CNBC.COM so is it possible to change the website url and parse the data from NSE or any other Indian Stock market website? if yes, can you please help with the process.
User avatar
Mordasius
Posts: 1178
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Market Prices

Post by Mordasius »

8ksmiff wrote: July 15th, 2024, 2:02 pm is it possible to change the website url and parse the data from NSE or any other Indian Stock market website? if yes, can you please help with the process.
Well it may be and maybe not. I'm not familiar with the sites you mentioned. Please send some links and I'll take a look.