Check if currentPrice crossed or touched any of our price levels. If this is the case, we will have one or more price levels appearing between previousPrice and currentPrice OR previousPrice or currentPrice will be equel to a price level. Add the BOLD code to the end of your monitorLevels() method. It must become the last code of monitorLevels(). Study the comments and complete the code         # Loop through displayList         for i in range(0,len(displayList)):             # Test if the first item in the current sub-list contains the text "Price Level"             # Tip: Remember that each sub-list is a list within a list (displayList). So you have             #       to access its items via displayList followed by TWO indexes.              . . .                 # Extract the second item from the current sub-list into a variable called priceLevel                 priceLevel = . . .                 # Test if priceLevel is between previousPrice and currentPrice OR                 #         priceLevel == previousPrice OR                 #         priceLevel == currentPrice                 if(                     . . .                 ):                     # Sound the alarm. Pass in the frequency and duration.                     if self.currentPrice > self.previousPrice:                         frequency = 800                         duration = 700                                        else:                         frequency = 400                         duration = 700                     winsound.Beep(frequency, duration)                     # Print the text 'Alarm' with a green background colour, so that the user                     # can go back into the historical data to see what prices raised the alarm.                     . . .   CODE  def monitorLevels(self):       threading.Timer(2.0, self.monitorLevels).start() self.previousPrice = self.currentPrice tickObj = self.getBitMexPrice()         self.currentPrice = tickObj.price if self.previousPrice == 0.0:             self.previousPrice = self.currentPrice print('')         print('Price Check at ' + str(datetime.now()) + '   (Press Ctrl+C to stop the monitoring)')         print('=================================================================================') displayList = [] for price in self.levelsList:             priceLevelLabel = f'Price Level:    {price}'             displayList.append([str(priceLevelLabel), float(price)]) previousPriceLabel = f'\033[94mPrevious Price: {self.previousPrice}\033[0m'         displayList.append([str(previousPriceLabel), float(self.previousPrice)]) if self.currentPrice > self.previousPrice:             currentPriceLabel = f'\033[92mCurrent Price:  {self.currentPrice}\033[0m'         elif self.currentPrice < self.previousPrice:             currentPriceLabel = f'\033[93mCurrent Price:  {self.currentPrice}\033[0m'         else:             currentPriceLabel = f'\033[94mCurrent Price:  {self.currentPrice}\033[0m'         displayList.append([str(currentPriceLabel), float(self.currentPrice)]) displayList.sort(key=lambda x: x[1]) for item in displayList:             print(item[0])

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter15: Using Javafx And Scene Builder
Section: Chapter Questions
Problem 1CP
icon
Related questions
Question

Check if currentPrice crossed or touched any of our price levels.

If this is the case, we will have one or more price levels appearing between previousPrice and currentPrice
OR
previousPrice or currentPrice will be equel to a price level.

Add the BOLD code to the end of your monitorLevels() method. It must become the last code of monitorLevels().

Study the comments and complete the code


        # Loop through displayList

        for i in range(0,len(displayList)):

            # Test if the first item in the current sub-list contains the text "Price Level"

            # Tip: Remember that each sub-list is a list within a list (displayList). So you have

            #       to access its items via displayList followed by TWO indexes. 

            . . .

                # Extract the second item from the current sub-list into a variable called priceLevel

                priceLevel = . . .

                # Test if priceLevel is between previousPrice and currentPrice OR

                #         priceLevel == previousPrice OR

                #         priceLevel == currentPrice

                if(

                    . . .

                ):

                    # Sound the alarm. Pass in the frequency and duration.

                    if self.currentPrice > self.previousPrice:

                        frequency = 800

                        duration = 700                   

                    else:

                        frequency = 400

                        duration = 700

                    winsound.Beep(frequency, duration)

                    # Print the text 'Alarm' with a green background colour, so that the user

                    # can go back into the historical data to see what prices raised the alarm.

                    . . .

 

CODE

 def monitorLevels(self):
     
threading.Timer(2.0, self.monitorLevels).start()
self.previousPrice = self.currentPrice
tickObj = self.getBitMexPrice()
        self.currentPrice = tickObj.price
if self.previousPrice == 0.0:
            self.previousPrice = self.currentPrice
print('')
        print('Price Check at ' + str(datetime.now()) + '   (Press Ctrl+C to stop the monitoring)')
        print('=================================================================================')
displayList = []
for price in self.levelsList:
            priceLevelLabel = f'Price Level:    {price}'
            displayList.append([str(priceLevelLabel), float(price)])
previousPriceLabel = f'\033[94mPrevious Price: {self.previousPrice}\033[0m'
        displayList.append([str(previousPriceLabel), float(self.previousPrice)])
if self.currentPrice > self.previousPrice:
            currentPriceLabel = f'\033[92mCurrent Price:  {self.currentPrice}\033[0m'
        elif self.currentPrice < self.previousPrice:
            currentPriceLabel = f'\033[93mCurrent Price:  {self.currentPrice}\033[0m'
        else:
            currentPriceLabel = f'\033[94mCurrent Price:  {self.currentPrice}\033[0m'
        displayList.append([str(currentPriceLabel), float(self.currentPrice)])
displayList.sort(key=lambda x: x[1])
for item in displayList:
            print(item[0])
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning