Author Topic: Help with Stock Quote project  (Read 3247 times)

Tomas

  • Newbie
  • *
  • Posts: 7
Help with Stock Quote project
« on: October 05, 2011, 11:47:03 AM »
I need some help with the Stock Quote project as I'm really stumped and don't know where to start as there aren't any texts explaing how it works. I can see it graphing on my phone but how it does it is a mystery. Perhaps someone can give me an overview of how it works, where it gets the stock quotes from, and how it can be changed to get other company quotes.

Would it be possible to get multiple quotes in real time?

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: Help with Stock Quote project
« Reply #1 on: October 05, 2011, 02:46:15 PM »
I need some help with the Stock Quote project as I'm really stumped and don't know where to start as there aren't any texts explaing how it works. I can see it graphing on my phone but how it does it is a mystery. Perhaps someone can give me an overview of how it works, where it gets the stock quotes from, and how it can be changed to get other company quotes.

Hi Tomas

The Stock Quote project basically does 3 things:-

1) Sends a request to the Yahoo finance website for data about a specific company code.

2) Parse the returned data to extract information about the company's stock details.

3) Display and graph the information.


These are the basic scripts as located in the MainCode section.

0) CARD TIMER THAT TRIGGERS REQUESTS

Code: [Select]
Global companyCode,quoteList
Local slen


DebugMessage('Quote','Timer')

Put field 1 into companyCode
Put LenFN(companyCode) into slen


If slen=0 Then
    DebugMessage('Quoue','No Code!')
    @Message 'No code!'
Else
    Call GetQuote
    Call ParseQuote
    Put quoteList into field 2
    Call DisplayUpdate
    Beep
EndIf



1)  REQUEST STOCK DATA

Code: [Select]
GLOBAL companyCode,fileName,quoteText
LOCAL webaddr,yield,timeout,okay

CLEAR quoteText

@ --- Form quote request ---
PUT 'http://download.finance.yahoo.com' INTO webaddr
APPEND '/d/quotes.csv?s=' ONTO webaddr
APPEND companyCode ONTO webaddr
APPEND '&f=sl1d1t1c1ohgv&e=.csv' ONTO webaddr

@ --- Get quote and save TO file ---
PUT 1 INTO yield
PUT 30 INTO timeout

PUT URLexistsFN(webaddr,yield,timeout,fileName) INTO okay

@ --- Read in quote FROM file ---
LOCAL h1,fend

IF okay=0 THEN
    CALL OnlineStatus(1)
ELSE
    CALL OnlineStatus(2)
    OpenTReadLoc(fileName,h1)
        Put EndTFileFN(h1) into fend
        if fend=0 then
            ReadTLine(h1,quoteText)
        endif
    CloseTRead(h1)
ENDIF



2) PARSE STOCK DATA

Code: [Select]
GLOBAL fileName,quoteText,quoteList
LOCAL n

@ --- Create quote list ---
CLEAR quoteList

FOR n=1 TO 9
    PUT NthChunkFN(quoteText,',',n) AFTER quoteList
ENDFOR

@ --- Remove " FROM list ---
REPLACEALL '"' WITH '' in quoteList



3) DISPLAY INFORMATION

Code: [Select]
GLOBAL quoteList,limitLow,limitHigh,timePlot
LOCAL fnum,n,current,y,lim,change,cc

@ --- SET plot position ---
PUT canvasWidth INTO lim
SUBTRACT 2 FROM lim
IF timePlot<lim THEN
    ADD 2 TO timePlot
ELSE
    CanvasScroll(1,-2,0,0,0,canvasWidth,canvasHeight)
ENDIF

@ --- fill fields ---
PUT 2 INTO fnum
FOR n=1 TO 9
    PUT line n OF quoteList INTO field fnum
    INCREMENT fnum
ENDFOR

@ --- SET color OF change field ---
PUT line 5 OF quoteList INTO change
PUT LeftFN(change,1) INTO cc
IF cc$='+' THEN
    FieldPaperColor(6,0,255,0)
ELSE
    FieldPaperColor(6,255,0,0)
ENDIF

@ -- SET labels ---
TextSetValue(11,limitHigh)
TextSetValue(12,limitLow)

@ --- Prepare plot ---
PUT line 2 OF quoteList INTO current
PUT current INTO y
SUBTRACT limitLow FROM y
MULTIPLY y BY yScale

@ --- Do plot ---
CanvasSetColor(1,255,0,0)
CanvasFillrect(1,timePlot,y,2,2)





Would it be possible to get multiple quotes in real time?

You could make it appear that multiple quotes are being made by storing company codes in a list and using  an index counter  that relates to a specific company.
Every time that the card timer ticks it could increment the index counter and when the counter reaches the maximum value it resets it back to 1.
The GetQuote and ParseQuote procedures would look at this index counter to see which company the data relates to.


I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

Tomas

  • Newbie
  • *
  • Posts: 7
Re: Help with Stock Quote project
« Reply #2 on: October 05, 2011, 03:31:46 PM »
Thank you for the big picture, that a really good description and makes a lot of sense. Now I'll look at these scripts to try and understand their details.

 

anything