Jump to content
Sign in to follow this  
Joec49

get stock quotes

Recommended Posts

Joec49

#include <GuiConstants.au3>

; Hides tray icon

#NoTrayIcon

; enables events

Opt("GUIOnEventMode", 1)

;builds the gui

$hmain=GUICreate("Stocks",150, 200) ;1st number is width, 2nd is height

GUISetOnEvent($GUI_EVENT_CLOSE, 'myExit')

GUICtrlCreateLabel("Stock Quote",50,10,-1,-1,-1)

GUICtrlSetColor(-1,0x0000FF) ;makes color of the above blue

$theStock=GUICtrlCreateInput("",20,40,100,20); ;left, top, width, height

GUICtrlCreateButton("Process", 20, 100, 50, 20)

GUICtrlSetOnEvent(-1, 'process') ; Runs process() when pressed

GuiCtrlCreateButton("About",90,100,50,20)

GUICtrlSetOnEvent(-1,'About')

GUICtrlCreateButton("Exit", 20,130,50,20)

GUICtrlSetOnEvent(-1,'myExit')

GuiCtrlCreateButton("HELP",90,130,50,20)

GuiCtrlSetOnEvent(-1,'help')

GUISetState(@SW_SHOW)

;--------------we now loop, waiting on events-------------------------------------

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then myExit()

sleep(1000) ;************wait 1 seconds in each loop to keep cpu load low****************

WEnd

GUIDelete()

func myExit()

exit

EndFunc

func About()

msgbox(64,"ABOUT","Written by Joe Collins using AutoIt3, 3/9/2009")

Return

EndFunc

func help()

$l= "This pogram retrives stock quotes from finance.yahoo.com and" & @CRLF

$l=$l&"displays it along with other market data. To get multiple quotes," & @CRLF

$l=$l&"place a + between the ticker symbols."

Msgbox(64,"HELP",$l)

EndFunc

func process()

$symbol=GuiCtrlread($theStock)

$symbol=StringRegExpReplace($symbol," ","")

$mystr="http://quote.yahoo.com/d/quotes.csv?s=^DJI+^GSPC+^RUI+^RUT+^RUA+^DWC+^VIX+^TV.N+" & $symbol & "&f=d1t1sl1c1&e=csv";

InetGet($mystr, "\temp\results.txt", 1, 0) ;1=forced get of data, avoid cached results; 0=wait until done

$str=FileRead("\temp\results.txt")

$str=StringRegExpReplace($str,"""","")

if(StringRegExp($str,"N/A")) Then

msgbox(64,"ERROR","unknown symbol found: "& $symbol)

GUICtrlSetData($theStock,"")

return

Else

;a set of regular expression to clean up the result

$str=StringRegExpReplace($str,"\^GSPC","S\&P 500")

$str=StringRegExpReplace($str,"\^DJI","DJIA")

$str=StringRegExpReplace($str,"\^TV.N","NYSE VOLU")

$str=StringRegExpReplace($str,",0.00","")

$str=StringRegExpReplace($str,"\^VIX","Volatility Index")

$str=StringregExpReplace($str,"\^RUI","Russell 1000")

$str=StringregExpReplace($str,"\^RUT","Russell 2000")

$str=StringregExpReplace($str,"\^RUA","Russell 3000")

$str=StringRegExpReplace($str,"\^DWC","Wilshire 5000")

$str=StringRegExpReplace($str,"\d{1,2}/\d{1,2}\/\d{4},","") ;remove date sloppily

$str=StringRegExpreplace($str,"\d{1,2}:\d{2}(a|p)m,","") ;remove time sloppily

;now display it

MsgBox(64,"MOST RECENT RESULTS",$str)

endif

EndFunc

Share this post


Link to post
Share on other sites
FireFox

@joec49

I dont think the title can explain all :P

PS: Add a description to your script and if possible a screenshot, add also CODE tags to insert your code in :unsure:

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
crashdemons

...

I liked the purpose of this example.

So I re-used the URL and defiled your script by creating this GDI+ StockTicker

Posted Image

ScreenShot

(It also expands so that you can set the default ticker as well as manually request a specific stock symbol [shows a bit more info that way too])

- and Yes, it does resize.

Note: some windows visual styles may have an effect on the GUI dimensions. X(

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $GUI_DOCKHORZ=$GUI_DOCKLEFT+$GUI_DOCKRIGHT
Global $GUI_DOCKMARQUEE=$GUI_DOCKHORZ+$GUI_DOCKHEIGHT
Global $GUI_InitSize
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Stock Ticker", 200, 64, -1,-1,$WS_CAPTION + $WS_SIZEBOX + $WS_SYSMENU, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE,'GUI_Close')
$Label1 = GUICtrlCreateLabel(" Loading Ticker... Please wait.", 0, 0, 180, 21, -1, $WS_EX_STATICEDGE)
GUICtrlSetResizing(-1,$GUI_DOCKMARQUEE+$GUI_DOCKTOP)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$RollButton=GUICtrlCreateButton('+',180,0,20,21)
GUICtrlSetResizing(-1,$GUI_DOCKSIZE+$GUI_DOCKTOP+$GUI_DOCKRIGHT)
GUICtrlSetOnEvent(-1,'GUI_QuickToggle')


$Input1 = GUICtrlCreateInput("Symbol", 1, 21, 109, 21)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKSIZE+$GUI_DOCKTOP)
$Button1 = GUICtrlCreateButton("Get Quote", 112, 20, 77, 22, 0)
GUICtrlSetOnEvent(-1,'GUI_ReadStockSymbol')
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKSIZE+$GUI_DOCKTOP)
$Input2 = GUICtrlCreateInput("GOOG,MSFT", 1, 42, 110, 21)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKSIZE+$GUI_DOCKTOP)
$Button2 = GUICtrlCreateButton("Set Ticker", 112, 42, 77, 22, 0)
GUICtrlSetOnEvent(-1,'GUI_SetTicker')
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKSIZE+$GUI_DOCKTOP)
GUISetState(@SW_HIDE)
$GUI_InitSize=WinGetPos($Form1)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO"); Ripped from Zedna - http://www.autoitscript.com/forum/index.php?showtopic=63272&view=findpost&p=472003
Global $TickerEntries,$TickerTimer, $TickerText
GUI_QuickToggle()
GUI_SetTicker()
_GDIPlus_Startup()
Global $hCtrl=ControlGetHandle($Form1,'',$Label1)
Global $gro
Global $grb
Global $gr
Global $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
Global $hFont = _GDIPlus_FontCreate ($hFamily, 10, 2)
Global $tLayout
Global $hFormat = _GDIPlus_StringFormatCreate ()
Global $hBrush=_GDIPlus_BrushCreateSolid(0xFF00FF00)
Global $iMove=0
Global $gr_dim[4]=[0,0,0,0]

WinMove($Form1,'',100,100,500)
GUISetState(@SW_SHOW)
GUI_TickerSize()
GUIRegisterMsg($WM_SIZE, "WM_SIZE")


While 1
    If IsArray($TickerEntries) Then
        If TimerDiff($TickerTimer)>60000 Then
            $TickerText=''
            For $i=1 To UBound($TickerEntries)-1
                If StringLen($TickerEntries[$i])<1 Then ContinueLoop
                Local $StockInfo=_Stock_GetInfo($TickerEntries[$i])
                If IsArray($StockInfo) Then
                    $TickerText&=$StockInfo[1]&' '&$StockInfo[3]&' ('&$StockInfo[4]&')  - '
                EndIf
            Next
            $TickerTimer=TimerInit()
        Else
            GUI_DrawTicker($TickerText)
            Sleep(25)
            $iMove+=1
        EndIf
    Else
        Sleep(300)
    EndIf
WEnd


Func GUI_ReadStockSymbol()
    GUICtrlSetState($Button1,128)
    GUICtrlSetState($Button2,128)
    Local $StockInfo=_Stock_GetInfo(GUICtrlRead($Input1))
    If IsArray($StockInfo) Then
        Local $t=$StockInfo[5]&' '
        $t&='Close: '&$StockInfo[2]&' '
        $t&='Change: '&$StockInfo[3]&' ('&$StockInfo[4]&')'
        Local $timer=TimerInit()
        $iMove=0
        While TimerDiff($timer)<8000
            GUI_DrawTicker($t)
            Sleep(25)
            $iMove+=1
        WEnd
    EndIf
    GUICtrlSetState($Button1,64)
    GUICtrlSetState($Button2,64)
EndFunc
Func GUI_SetTicker()
    GUICtrlSetState($Button1,128)
    GUICtrlSetState($Button2,128)
    Global $TickerEntries, $TickerTimer, $TickerText
    $TickerTimer=0
    $TickerEntries=''
    $TickerText=''
    $TickerEntries=StringSplit(GUICtrlRead($Input2)&',',',')
    GUICtrlSetState($Button1,64)
    GUICtrlSetState($Button2,64)
EndFunc

Func GUI_QuickToggle()
    Local $wgp=WinGetPos($Form1)
    If $wgp[3]>70 Then
; not the right height because of Visual Styles differences X(
; but it can't go less than the forced min.
        WinMove($Form1,'',$wgp[0],$wgp[1],$wgp[2],21)
    Else
        WinMove($Form1,'',$wgp[0],$wgp[1],$wgp[2],100); not right again. :P - hopefully hits the max Height.
    EndIf
EndFunc
Func GUI_Close()
    
    If @InetGetActive Then InetGet('abort')
    
    $TickerTimer=0
    $TickerEntries=''
    $TickerText=''
    
    $tLayout=0
    If $hFamily Then _GDIPlus_FontFamilyDispose($hFamily)
    If $hFont Then _GDIPlus_FontDispose($hFont)
    If $hFormat Then _GDIPlus_StringFormatDispose($hFormat)
    If $hBrush Then _GDIPlus_BrushDispose($hBrush)
    If $gr Then _GDIPlus_GraphicsDispose($gr)
    If $grb Then _GDIPlus_BitmapDispose($grb)
    If $gro Then _GDIPlus_GraphicsDispose($gro)
    
    
    GUISetState(@SW_HIDE)
    GUIDelete($Form1)
    Exit
EndFunc









Func GUI_TickerSize()
    Global $gro, $grb, $gr_dim
    $gr_dim=ControlGetPos($Form1,'',$Label1)
    ConsoleWrite('TickerResize '&$gr_dim[2]&@CRLF)
    Local $cgp=$gr_dim
    
    If $gro Then _GDIPlus_GraphicsDispose($gro)
    $gro=_GDIPlus_GraphicsCreateFromHWND($hCtrl)
    
    If $gr Then _GDIPlus_GraphicsDispose($gr)
    If $grb Then _GDIPlus_BitmapDispose($grb)
    $grb=_GDIPlus_BitmapCreateFromGraphics($cgp[2],$cgp[3],$gro); I'd only make one - but the darn thing has to resize!
    $gr=_GDIPlus_ImageGetGraphicsContext($grb)
    
    
    
EndFunc
Func GUI_DrawTicker($str)
    Global $gr_dim,$iMove
    Local $cgp=$gr_dim
    
    
    If $iMove>$cgp[2] Then
        ConsoleWrite('TickerBack '&$iMove&'>'&$cgp[2]&@CRLF)
        $iMove=0
    EndIf
    _GDIPlus_GraphicsClear($gr,0xFF000000)
    
    $tLayout = 0
    $tLayout = _GDIPlus_RectFCreate ($iMove,0, $cgp[2], $cgp[3])
    _GDIPlus_GraphicsDrawStringEx ($gr, $str, $hFont, $tLayout, $hFormat, $hBrush)
    
    $tLayout = 0
    $tLayout = _GDIPlus_RectFCreate ($iMove-$cgp[2],0, $cgp[2], $cgp[3])
    _GDIPlus_GraphicsDrawStringEx ($gr, $str, $hFont, $tLayout, $hFormat, $hBrush)
    
    
    _GDIPlus_GraphicsDrawImageRect($gro, $grb, 0, 0, $cgp[2], $cgp[3]);copy to bitmap
EndFunc





Func _Stock_GetInfo($Symbol)
;http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=sl1c1p2n&e=.csv
;StrSymbol,FloatLastValue,FloatLastChange,StrPercentChange,StrCompany
    Local $qf=@TempDir&'\yahoo_stockinfo.csv'
    InetGet('http://download.finance.yahoo.com/d/quotes.csv?s='&StringUpper($Symbol)&'&f=sl1c1p2n&e=.csv',$qf,1,1)
    $iMove=0
    While @InetGetActive
        GUI_DrawTicker('Loading '&$Symbol&'... Please Wait.')
        Sleep(25)
        $iMove+=1
    WEnd
    
    Local $StockInfo=StringSplit(StringReplace(StringStripCR(FileRead($qf)),@LF,'')&',',',')
    Local $StockInfo_Max=UBound($StockInfo)-1
    For $i=1 To $StockInfo_Max
        If StringMid($StockInfo[$i],1,1)=='"' And StringMid($StockInfo[$i],StringLen($StockInfo[$i]),1)=='"' Then
            $StockInfo[$i]=StringTrimRight(StringTrimLeft($StockInfo[$i],1),1)
        EndIf
    Next
    Return $StockInfo
EndFunc


Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    GUI_TickerSize()
    Return $GUI_RUNDEFMSG
EndFunc
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam); ty Zedna;)
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
    DllStructSetData($minmaxinfo,7,$GUI_InitSize[2]); min X
    DllStructSetData($minmaxinfo,8,$GUI_InitSize[3]-43); min Y - this should leave just 21px for the stock ticker (visual styles may break this x_x )
;DllStructSetData($minmaxinfo,9,500); max X
    DllStructSetData($minmaxinfo,10,$GUI_InitSize[3]); max Y
    Return 0
EndFunc
Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
Hellooopsforgotsendcommand

Great work both of you

now just one more thing

can you tell me who I can borrow some money from to invest!

Share this post


Link to post
Share on other sites
Hellooopsforgotsendcommand

Crashdemons, Can you input more than one code at a time? ie if I want to check KPN and DSM It seems a bit slow to have to type in each one at a time. Maybe the ability to check a list of codes you have?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.