egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

stock exchange script for Australia

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
rainman
Voice


Joined: 21 Apr 2021
Posts: 9

PostPosted: Fri Jan 13, 2023 2:35 am    Post subject: stock exchange script for Australia Reply with quote

Gday all, how's everyone doing?

I'm looking for a simple stock exchange script for Australia if someone can help make a simple one for me please

like say !asx Code-here and it shows some basic info

eg: !asx CBA etc

such as Current Price, Last Price, etc

https://www.marketindex.com.au/asx/cba <--example if you go down to snapshot if that info can be displayed in channel if possible please

Thanks
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 809
Location: Tennessee, USA

PostPosted: Fri Jan 13, 2023 9:26 am    Post subject: Reply with quote

There is a pile of info in the "Snapshot", way too much to present in a channel post.

Maybe pick a few key entries to present?
Better yet, type out an example of what a channel post would look like:)
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
rainman
Voice


Joined: 21 Apr 2021
Posts: 9

PostPosted: Fri Jan 13, 2023 9:54 am    Post subject: Reply with quote

SpiKe^^ wrote:
There is a pile of info in the "Snapshot", way too much to present in a channel post.

Maybe pick a few key entries to present?
Better yet, type out an example of what a channel post would look like:)


Oh right sorry Smile

How about just the following

Open Price:
Last Price:
Bid / Ask:
Day Range:
Prev Close:
Last Trade:
Market Cap:
Change:

Is that more reasonable Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 809
Location: Tennessee, USA

PostPosted: Sun Jan 22, 2023 12:12 am    Post subject: Reply with quote

Looking over the html source file much closer, shows they hide their quote data very well.
Quote:
<td>Last (Price)</td>
<td class="text-right">
<span data-quoteapi="price"></span>
</td>
</tr>
<tr>
<td>Change</td>
<td class="text-right" data-quoteapi="changeSignCSS">
<span data-quoteapi="change showNegativeSign=false">0.00</span>
(<span data-quoteapi="pctChange showNegativeSign=true">0.00</span>)
</td>
</tr>


The headers are there but none of the data.
I do not know how to get any quote data from this site.

Maybe you know a usable source site for this stock quote data, or a way to force any data from this site?
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
rainman
Voice


Joined: 21 Apr 2021
Posts: 9

PostPosted: Sun Jan 22, 2023 12:44 am    Post subject: Reply with quote

SpiKe^^ wrote:
Looking over the html source file much closer, shows they hide their quote data very well.
Quote:
<td>Last (Price)</td>
<td class="text-right">
<span data-quoteapi="price"></span>
</td>
</tr>
<tr>
<td>Change</td>
<td class="text-right" data-quoteapi="changeSignCSS">
<span data-quoteapi="change showNegativeSign=false">0.00</span>
(<span data-quoteapi="pctChange showNegativeSign=true">0.00</span>)
</td>
</tr>


The headers are there but none of the data.
I do not know how to get any quote data from this site.

Maybe you know a usable source site for this stock quote data, or a way to force any data from this site?


Hello Spike,

How about directly from the source

https://www2.asx.com.au/markets/company/cba

Is that more usable ?

https://www2.asx.com.au/

If that's a bust only other one i found would be

https://au.finance.yahoo.com/

https://au.finance.yahoo.com/quote/CBA.AX?p=CBA.AX&.tsrc=fin-srch

I really do appreciate your efforts into this, thank you so much
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 809
Location: Tennessee, USA

PostPosted: Sun Jan 22, 2023 2:49 am    Post subject: maybe au.finance.yahoo.com/quote/ Reply with quote

Looks to me like the source code from here is user friendly:)
https://au.finance.yahoo.com/quote/CBA.AX?p=CBA.AX

With that being all the data available, what fields would you include in the channel post?
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
rainman
Voice


Joined: 21 Apr 2021
Posts: 9

PostPosted: Sun Jan 22, 2023 3:10 am    Post subject: Re: maybe au.finance.yahoo.com/quote/ Reply with quote

SpiKe^^ wrote:
Looks to me like the source code from here is user friendly:)
https://au.finance.yahoo.com/quote/CBA.AX?p=CBA.AX

With that being all the data available, what fields would you include in the channel post?


Market Cap:
Open:
Prev Close:
Bid:
Ask:
Day's Range:

Just those please spike Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 809
Location: Tennessee, USA

PostPosted: Wed Jan 25, 2023 6:32 pm    Post subject: ausStocks.tcl version 0.1 24Jan2023 Reply with quote

Tested some, give it a shot:)

Code:

## ausStocks.tcl version 0.1  24Jan2023 ##

# public command syntax:  !asx <symbol>
# example:  !asx csl

package require http
package require tls

http::register https 443 {tls::socket -autoservername true}

bind pub - !asx asx:bindpub

proc asx:bindpub {nk uh hn ch tx} {
  set symbol [string toupper [lindex [split [string trim $tx]] 0]]

  if {[string length $symbol] < 3 || [string length $symbol] > 6} { return 0 }

  set address "https://au.finance.yahoo.com/quote/${symbol}.AX?p=${symbol}.AX"
  set token [::http::geturl $address -timeout 7500]
  set html [::http::data $token]  ;   ::http::cleanup $token
  set html [join [lrange [split $html "\n"] 4 6] {}]

  set ils {company xinfo lastprice change percent notice prevclose open bid ask}
  foreach vname [lappend ils dayrange 52weeks volume avgvolume marketcap] {
    set $vname "N/A"
  }

  set qmap [list %k $nk %h $ch]


  regexp {<h1 class=\"D\(ib\) Fz\(18px\)\">(.*?)</h1>(.*)$} $html - company html
  regexp {^</div>[^>]+><span>(.*?)</span>(.*)$} $html - xinfo html
  regexp {regularMarketPrice[^>]+>(.*?)</fin-str(.*)$} $html - lastprice html
  regexp {regularMarketChange[^>]+><[^>]+>(.*?)</span(.*)$} $html - change html
  regexp {MarketChangePercent[^>]+><[^>]+>(.*?)</span(.*)$} $html - percent html
  regexp {quote-market-notice[^>]+><span>(.*?)</span>(.*)$} $html - notice html

  if {[matchstr "-*" $change]} {
    set change "\00304$change\003"  ;  set percent "\00304$percent\003"
  } elseif {[matchstr "+*" $change]} {
    set change "\00303$change\003"  ;  set percent "\00303$percent\003"
  }
  lappend qmap %y $company %x $xinfo %l $lastprice %c $change %p $percent

  regexp {PREV_CLOSE-value\">(.*?)</td></tr>(.*)$} $html - prevclose html
  regexp {\"OPEN-value\">(.*?)</td></tr>(.*)$} $html - open html
  regexp {\"BID-value\">(.*?)</td></tr>(.*)$} $html - bid html
  regexp {\"ASK-value\">(.*?)</td></tr>(.*)$} $html - ask html

  lappend qmap %n $notice %r $prevclose %o $open %b $bid %a $ask

  regexp {DAYS_RANGE-value\">(.*?)</td></tr>(.*)$} $html - dayrange html
  regexp {FIFTY_TWO_WK_RANGE-value\">(.*?)</td>(.*)$} $html - 52weeks html
  regexp {regularMarketVolume[^>]+>(.*?)</fin-streamer(.*)$} $html - volume html
  regexp {AVERAGE_VOLUME_3MONTH-value\">(.*?)</td>(.*)$} $html - avgvolume html
  regexp {\"MARKET_CAP-value\">(.*?)</td></tr>(.*)$} $html - marketcap html

  lappend qmap %d $dayrange %w $52weeks %v $volume %g $avgvolume %m $marketcap


  set hmap [list "'" "'" "&amp;" "&" "&quot;" "\""]

  #### e f i j q s t u z ####

  #  %y  = company name      ex.  Apollo Minerals Limited (AON.AX)
  #  %x  = asx info  ??      ex.  ASX - ASX Delayed price. Currency in AUD
  #  %l  = last price        ex.  108.66
  #  %c  = price change      ex.  -0.08
  #  %p  = change percent    ex.  (-0.07%)
  #  %n  = market notice     ex.  As of  10:17AM AEDT. Market open.

  #  %r  = previous close    ex.  108.74
  #  %o  = open              ex.  108.74
  #  %b  = bid               ex.  108.66 x 36400
  #  %a  = ask               ex.  108.69 x 7100
  #  %d  = day's range       ex.  108.38 - 109.15
  #  %w  = 52-week range     ex.  86.98 - 109.20
  #  %v  = volume            ex.  3,747,153
  #  %g  = avg. volume       ex.  2,190,023
  #  %m  = market cap        ex.  183.463B

  #  %k  = nick              ex.  SpiKe^^
  #  %h  = channel           ex.  #pc-mirc-help


  set say [list "\00306<ASX>\003 %y  \002%l AUD\002  Change: \002%c %p\002  %n"]

  set s "Previous close: \002%r\002  Open: \002%o\002  Bid: \002%b\002  "
  append s "Ask: \002%a\002  Day's range: \002%d\002  Market cap: \002%m\002"
  lappend say $s


  foreach ln $say {
    set ln [string map $qmap $ln]  ;   set ln [string map $hmap $ln]
    puthelp "PRIVMSG $ch :$ln"
  }
  return 0
}

putlog "Loaded ausStocks.tcl version 0.1  24Jan2023"



_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1057
Location: France

PostPosted: Wed Jan 25, 2023 7:07 pm    Post subject: Reply with quote

short advice: don't register globaly https but register it when needed (before query) and unregister when cleaning the connection.
If another script globaly unregister https, yours will not work anymore.

Keep in mind that your script is not the only one running on the eggdrop.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 809
Location: Tennessee, USA

PostPosted: Wed Jan 25, 2023 7:46 pm    Post subject: Reply with quote

thommey said put it there, and stop using ::http::unregister https:)
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
rainman
Voice


Joined: 21 Apr 2021
Posts: 9

PostPosted: Wed Jan 25, 2023 8:14 pm    Post subject: Re: ausStocks.tcl version 0.1 24Jan2023 Reply with quote

Thank you so much spike, you are the man sir Very Happy

i'll def give it a better whirl tomorrow when markets open up xD

So far it's working as expected Very Happy
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 809
Location: Tennessee, USA

PostPosted: Sat Jan 28, 2023 9:16 am    Post subject: ausStocks.tcl version 0.2 27Jan2023 Reply with quote

Version 0.2 adds some bare minimum sanity/error checks w/ reporting:
1) restricts user input to 3 - 6 alphanumeric characters.
2) adds some error checking on the http connection & get.
3) put the entire script code in the namespace ausStocks.

Code:

## ausStocks.tcl version 0.2  27Jan2023 ##

## Version 0.2 adds some bare minimum sanity checks w/ reporting:
# 1) restricts user input to 3 - 6 alphanumeric characters.
# 2) adds some error checking on the http connection & get.
# 3) put the entire script code in the namespace ausStocks.


# public command syntax:  !asx <symbol>
# example:  !asx csl

##########################################
namespace eval ausStocks {

package require http
package require tls

::http::register https 443 {::tls::socket -autoservername true}
#::http::register https 443 [list ::tls::socket -servername au.finance.yahoo.com]

bind pub - !asx [namespace current]::asx:bindpub

proc asx:bindpub {nk uh hn ch tx} {
  set sym [string toupper [lindex [split [string trim $tx]] 0]]

  if {[string length $sym] ni {3 4 5 6} || [regexp {[^0-9A-Z]} $sym]} {
    puthelp "PRIVMSG $ch :\00306<ASX>\003 Command syntax:  \002!asx <symbol>\002"
    return 0
  }

  set address "https://au.finance.yahoo.com/quote/${sym}.AX?p=${sym}.AX"
  ::http::config -useragent "Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
  #::http::register https 443 {::tls::socket -autoservername true}
  #::http::register https 443 [list ::tls::socket -servername au.finance.yahoo.com]

  # Thanks thommey #
  if {[catch {::http::geturl $address -timeout 7500} tok]} {  error $tok  }
  if {[::http::status $tok] ne "ok"} {
    error "TCP error: [::http::status $tok][::http::cleanup $tok]"
  } elseif {[::http::ncode $tok] != 200} {
    error "HTTP error: [::http::code $tok][::http::cleanup $tok]"
  }

  set html [::http::data $tok]  ;   ::http::cleanup $tok
  set html [join [lrange [split $html "\n"] 4 6] {}]

  set company ""  ;   set xinfo ""  ;   set lastprice ""

  regexp {<h1 class=\"D\(ib\) Fz\(18px\)\">(.*?)</h1>(.*)$} $html - company html
  regexp {^</div>[^>]+><span>(.*?)</span>(.*)$} $html - xinfo html
  regexp {regularMarketPrice[^>]+>(.*?)</fin-str(.*)$} $html - lastprice html

  if {$company eq "" || $xinfo eq "" || $lastprice eq ""} {
    puthelp "PRIVMSG $ch :\00306<ASX>\003 Invalid Company Symbol:  \002$sym\002"
    return 0
  }

  set qmap [list %k $nk %h $ch %y $company %x $xinfo %l $lastprice]


  set ils {change percent notice prevclose open bid ask dayrange}
  foreach vname [lappend ils 52weeks volume avgvolume marketcap] {
    set $vname "N/A"
  }

  regexp {regularMarketChange[^>]+><[^>]+>(.*?)</span(.*)$} $html - change html
  regexp {MarketChangePercent[^>]+><[^>]+>(.*?)</span(.*)$} $html - percent html
  regexp {quote-market-notice[^>]+><span>(.*?)</span>(.*)$} $html - notice html

  if {[matchstr "-*" $change]} {
    set change "\00304$change\003"  ;  set percent "\00304$percent\003"
  } elseif {[matchstr "+*" $change]} {
    set change "\00303$change\003"  ;  set percent "\00303$percent\003"
  }
  lappend qmap %c $change %p $percent %n $notice

  regexp {PREV_CLOSE-value\">(.*?)</td></tr>(.*)$} $html - prevclose html
  regexp {\"OPEN-value\">(.*?)</td></tr>(.*)$} $html - open html
  regexp {\"BID-value\">(.*?)</td></tr>(.*)$} $html - bid html
  regexp {\"ASK-value\">(.*?)</td></tr>(.*)$} $html - ask html
  regexp {DAYS_RANGE-value\">(.*?)</td></tr>(.*)$} $html - dayrange html

  lappend qmap %r $prevclose %o $open %b $bid %a $ask %d $dayrange

  regexp {FIFTY_TWO_WK_RANGE-value\">(.*?)</td>(.*)$} $html - 52weeks html
  regexp {regularMarketVolume[^>]+>(.*?)</fin-streamer(.*)$} $html - volume html
  regexp {AVERAGE_VOLUME_3MONTH-value\">(.*?)</td>(.*)$} $html - avgvolume html
  regexp {\"MARKET_CAP-value\">(.*?)</td></tr>(.*)$} $html - marketcap html

  lappend qmap %w $52weeks %v $volume %g $avgvolume %m $marketcap


  set hmap [list "'" "'" "&amp;" "&" "&quot;" "\""]

  #### e f i j q s t u z ####

  #  %y  = company name      ex.  Apollo Minerals Limited (AON.AX)
  #  %x  = asx info  ??      ex.  ASX - ASX Delayed price. Currency in AUD
  #  %l  = last price        ex.  108.66
  #  %c  = price change      ex.  -0.08
  #  %p  = change percent    ex.  (-0.07%)
  #  %n  = market notice     ex.  As of  10:17AM AEDT. Market open.

  #  %r  = previous close    ex.  108.74
  #  %o  = open              ex.  108.74
  #  %b  = bid               ex.  108.66 x 36400
  #  %a  = ask               ex.  108.69 x 7100
  #  %d  = day's range       ex.  108.38 - 109.15
  #  %w  = 52-week range     ex.  86.98 - 109.20
  #  %v  = volume            ex.  3,747,153
  #  %g  = avg. volume       ex.  2,190,023
  #  %m  = market cap        ex.  183.463B

  #  %k  = nick              ex.  GreedyHamster
  #  %h  = channel           ex.  #MarketHub


  set say [list "\00306<ASX>\003 %y  \002%l AUD\002  Change: \002%c %p\002  %n"]

  set s "Previous close: \002%r\002  Open: \002%o\002  Bid: \002%b\002  "
  append s "Ask: \002%a\002  Day's range: \002%d\002  Market cap: \002%m\002"
  lappend say $s


  foreach ln $say {
    set ln [string map $qmap $ln]  ;   set ln [string map $hmap $ln]
    putserv "PRIVMSG $ch :$ln"
  }
  return 0
}

putlog "Loaded ausStocks.tcl version 0.2  27Jan2023"

}  ;## end of:  namespace eval ausStocks ##


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
rainman
Voice


Joined: 21 Apr 2021
Posts: 9

PostPosted: Sat Jan 28, 2023 11:09 pm    Post subject: Re: ausStocks.tcl version 0.2 27Jan2023 Reply with quote

Thanks Spike and LOL @ GreedyHamster Razz love it Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber