home *** CD-ROM | disk | FTP | other *** search
- ; Script: DOFEED.SC
- ; Version: 3.5
- ; Date: 23 March 1990
- ;
- ; The DOFEED script contains the procedures used to generate random stock
- ; buying and selling activity. When DOFEED first begins, it attempts to
- ; initialize the PRICE table--if the PRICE table has already been
- ; initialized, it is assumed that another copy of FEED is running elsewhere
- ; on the network, and the information in the fields manipulated by Rnd is not
- ; zeroed out. If the PRICE table is not yet initialized, then information
- ; about the latest stock trading is zeroed out (High and Low set to the
- ; Price, Last Activity zeroed, and so on).
-
- ; The SingleDoFeed procedure creates random stock trading information in a
- ; single user environment (necessary to create a real-time graph).
-
- PROC CLOSED SingleDoFeed() ; simulates Dofeed.sc for single user
- IF NETTYPE() = "SingleUser" ; should work on single user only
- THEN
- EDIT "Price" ; put the Price table on workspace
- Zip = INT(RAND() * NRECORDS(TABLE())) ; generate random record # in table
- MOVETO RECORD Zip + 1 ; and move to that record
- ChangePrice() ; make random changes to Price
- DO_IT! ; save all new info in Price table
- ENDIF
- ENDPROC ; SingleDoFeed
-
- ; The DoFeed procedure creates random stock trading information on a network
- ; and displays it as it is generated.
-
- PROC CLOSED DoFeed()
- USEVARS CurLine, FirstStockrow, LastStockrow, LeftMargin, IsColorMonitor
- @ 0, 0
- ?? FORMAT("W80,AC",
- "Simulated price feed is running. Press any key to escape.")
- R = FirstStockRow - 1 ; display trades on starting line
- COEDIT "Price" ; get the PRICE table on workspace
- WHILE NOT CHARWAITING() ; for as long as user doesn't press key
- Zip = INT(RAND()*NRECORDS(TABLE())) ; generate random record # in table
- MOVETO RECORD Zip + 1 ; and move to that record
- Retry = FALSE ; don't want to retry just yet
- LOCKRECORD ; Can we get the record?
- WHILE NOT Retval ; No, so we must
- Retry = TRUE ; keep reminder that we need to retry,
- SLEEP 200 ; pause a moment before retrying,
- LOCKRECORD ; try to get the record again, and
- PutMessage("*") ; display an asterisk to show we're retrying.
- ENDWHILE
-
- ; If we get here, we locked record successfully.
-
- IF (Retry) ; if we had to retry, erase asterisk
- THEN ClearMessage()
- ENDIF
- ChangePrice() ; make random changes to Price Table
-
- ; Time to display what we've done
-
- Lastr = R ; Lastr is previous row we displayed trade on
- R = R + 1 ; increment our row counter to get new trade row
- IF R > LastStockRow ; wrap to start line when we get to bottom
- THEN R = FirstStockRow
- ENDIF
- @ Lastr, LeftMargin
- ?? " " ; clear Last trade: marker from previous trade
- ?? CurLine ; and display previous trade
- IF (IsColorMonitor)
- THEN STYLE ATTRIBUTE 116 ; red on light grey for color monitors
- ELSE STYLE REVERSE ; everyone else gets inverse
- ENDIF
-
- @ R, LeftMargin
- ?? "Last trade: " ; and update the trade information
- CurLine = FORMAT("W6", [TICKER]) +
- " " + FORMAT("W9.3", [PRICE]) +
- " " + FORMAT("W6", Volume) + " Shares " +
- " at " + [LAST] + " "
- SWITCH
- CASE Change > .001 :
- CurLine = CurLine + "+" + FORMAT("W8.3", Change)
- CASE Change < -.001 :
- CurLine = CurLine + "-" + FORMAT("W8.3", -Change)
- OTHERWISE:
- CurLine = CurLine + "Unchanged"
- ENDSWITCH
- ?? CurLine ; display the trade information
- STYLE ATTRIBUTE 31 ; back to high intensity or white on blue
- UNLOCKRECORD
- ENDWHILE
-
- ; If we drop out of the preceding loop, user must have pressed a key.
-
- x = GETCHAR() ; gobble up the keystroke
- DO_IT! ; update the table
- CLEARALL ; clear the workspace
- DoneFeed() ; update Semaphor to tell world we're done
- ENDPROC ; DoFeed
-
- PROC ChangePrice() ; procedure makes random changes to Price table
- WHILE (TRUE)
- ChangeDecimal = .125 * INT(RAND()*8) ; convert changes to 1/8 of dollar
- ChangeInt = INT(ROUND((RAND()-.5)*[Price],3)) ; generate a random price
- IF ChangeInt < 0
- THEN Change = ChangeInt - ChangeDecimal
- ELSE Change = ChangeInt + ChangeDecimal
- ENDIF
- Newprice = [Price] + Change ; calculate new stock price
- If Newprice > 200 ; maximum of new price should be less than $200
- THEN LOOP
- ELSE QUITLOOP
- ENDIF
- ENDWHILE
- Volume = INT(RAND() * 5000) + 5 ; calculate new random value for Volume
- [High] = MAX([High], Newprice) ; calculate new session High price
- [Low] = MIN([Low], Newprice) ; calculate new session Low price
- [Volume] = [Volume] + Volume ; update the stock trading volume
- [Chg] = Newprice - ([Price] - [Chg]) ; insert the change in price
- [Price] = NewPrice ; and update the Price field
- [LAST] = TIME() ; finally, insert the time of the trade
- ENDPROC ; ChangePrice
-
-
- ; TryToInitialize attempts to reinitialize fields in the Price table.
- ; If we are the first ones there, we perform the initialization by
- ; zeroing out the fields that will be generated by RND. If we aren't the
- ; first ones there, then someone else is already generating stock activity
- ; and we shouldn't reinitialize the table.
-
- PROC TryToInitialize()
- TestInitialize() ; Can we perform an initialization?
- IF (NOT Retval) ; No, so
- THEN TestWaitForInitialize() ; Do we need to wait for someone else to
- WHILE (Retval) ; complete an initialization?
- PutMessage( ; Yes, so
- "Session Initialization being performed by another user. Please wait...")
- SLEEP 500 ; after a short pause,
- TestWaitForInitialize() ; keep checking.
- ENDWHILE
- ClearMessage() ; erase the message, since we can go on
- RETURN ; move on
- ENDIF
-
- ; If we get here, we must have to initialize the market
-
- PutMessage("Initializing Stock Transaction Session...")
- WHILE (TRUE) ; wait for any query to finish,
- LOCK "Price" PWL ; since queries do a WL on table
- IF (Retval)
- THEN QUITLOOP
- ENDIF
- SLEEP 200
- ENDWHILE
- COEDIT "Price" ; get the table on workspace
- SCAN ; and for each record,
- [Volume] = 0 ; reset the daily volume
- [High] = [Price] ; today's high price is equal to previous close
- [Low] = [Price] ; today's low price is equal to previous close
- [Chg] = 0 ; no change in price yet
- ENDSCAN
- DO_IT! ; and save the new table
- UNLOCK "Price" PWL
- DoneInitialize() ; release the initialization semaphore
- ClearMessage() ; erase the init message
- ENDPROC ; TryToInitialize
-
- PROC ClearBackground(Attr, FirstLine, LastLine)
- PRIVATE FirstLine, LastLine, Attr
- PAINTCANVAS FILL " " ATTRIBUTE Attr FirstLine, 0, LastLine, 79
- ENDPROC
-
- PROC PutMessage(Msg) ; define a message window like Paradox's
- IF (IsColorMonitor) ; are we on a color monitor?
- THEN STYLE ATTRIBUTE 116 ; yes, so use red on light grey
- ELSE STYLE REVERSE ; no, everyone else gets inverse
- ENDIF
- @ 24, 80 - LEN(Msg) ?? Msg ; displays in message window
- STYLE ATTRIBUTE 31 ; return style to normal
- ENDPROC
-
- PROC ClearMessage() ; clear the message window we defined
- ClearBackground(31, 24, 24)
- ENDPROC
-
- PROC StartUp() ; get the feed started
- RESET ; start with a known system state
- CurLine = ""
- FirstStockRow = 8 ; Where will the stock info display start?
- LastStockRow = 20 ; Where will the stock info display end?
- LeftMargin = 6
- CURSOR OFF ; don't need the cursor to display info
- IsColorMonitor = (Monitor()="Color") ; find out what kind of monitor we're on
- ClearBackground(31, 0, 24) ; and initialize the screen to blank
- TryToInitialize() ; see if we need to initialize Price table
- @ FirstStockRow - 2, LeftMargin ; finally, display headings for stock listings
- ?? " " +
- FORMAT("W6,AL", "Symbol") +
- FORMAT("W11,AR", "Price") +
- FORMAT("W20,AC", "Shares Traded") +
- FORMAT("W8,AC", "Time") +
- FORMAT("W9,AR", "Change")
- CLEARALL ; clear all tables on workspace
- ENDPROC ; StartUp
-
- PROC TestInitialize()
- LOCK "Semaphor" WL, "Semaphor" PWL
- RETURN Retval
- ENDPROC
-
- PROC TestWaitForInitialize()
- LOCK "Semaphor" WL
- RETURN NOT Retval
- ENDPROC
-
- PROC DoneInitialize()
- UNLOCK "Semaphor" PWL
- ENDPROC
-
- PROC DoneFeed()
- UNLOCK "Semaphor" WL
- ENDPROC
-
-