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
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
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
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
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.