Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I unable stop this program using the VSCode terminal command: ctrl + c, or ctrl + z?

Background:

  1. This was not an issue until I added the try/except. I added this because at times I feel there was a deeper issue, perhaps rooted in the function I call from kucoin.helpers. (I call a while loop, while inside of a while loop in my code.)

  2. Specifically I would find myself unable to consistently finish the cycle of purchase and then sale of asset: This failure would stem from between a successful purchase of asset and the sale.

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  3. The try/except loop was the only way to "flawlessly execute my code".

  4. I know the try/except loop was not utilized properly, I am inexperienced and will delve into it.

import kucoin_helpers
import time
import random
from twilio.rest import Client as TwilioClient 
import twiliodata

####Set API Credentials for Twilio
text_client = TwilioClient(twiliodata.account_sid, twiliodata.auth_token)
#This is going to be Lumiere himself. The man, the bot, the first iteration and legend.
########IMMEDIATELY BEGIN KEEPING rounds of data. 
                    #Leave room for INFO: in database to allow comment made to first and last entry in database for round
                        ##This will allow for easy diefin tin
                    #look forward to using minimax  
take_profit = 0
stop_loss = 0
keep_testing = True
while keep_testing:   
    try:            
    starting_account_balance = kucoin_helpers.doge_musk_check_balance()
    print(f"BEGINNING BALANCE: {starting_account_balance}")

    list_of_winLOSS = []
    ####Start keeping this data
    total_times_to_run = random.randrange(start=20, stop=50)
    total_times_to_run = int(total_times_to_run)

    #####We need to run this loop repetitively until we reach an output ratio where Success to Failure is near (0.7/0.3)==2.63
    #Add Each trials results (tp to sl limits/)
        ##Consider using limits that are proportionate to the "confidence" in current trend in timeframe

    for i in range(total_times_to_run):
        input_tp = random.uniform(1.001, 1.009)
        take_profit=input_tp
        print(input_tp)
        input_sl = random.uniform(0.991, 0.99989)
        take_profit=input_sl
        print(input_sl)
        answer = kucoin_helpers.execute_doge_musktrade(input_tp=input_tp, input_sl=input_sl)
        list_of_winLOSS.append(answer)
        time.sleep(0.5)
    failure = 0
    success = 0
    for outcome in list_of_winLOSS:
        if outcome == "Failure":
            failure += 1
        if outcome == "Success":
            success += 1


    ending_account_balance = kucoin_helpers.doge_musk_check_balance()


    total_PNL = ending_account_balance - starting_account_balance

    print(f"SUCCESS: {success}\nFailure: {failure}")
    print(f"BEGINNING BALANCE: {starting_account_balance}")
    print(f"ENDING BALANCE: {ending_account_balance}")
    print(f"PNL : {total_PNL}")
    body = f"SUCCESS: {success}\nFAILURE: {failure}\nBEGINNING BALANCE: {starting_account_balance}\nENDING BALANCE: {ending_account_balance}\nPNL: {total_PNL}"
    text_client.messages.create(to="7177295751", from_=twiliodata.phone_number, body=body)
    
except:
    print("Unable to perform Action")

>Solution :

As you already mentioned, a good use of try-except clauses would capture your specific exceptions and not all. What is happening right now is that you are throwing a KeyboardInterrupt exception by pressing Ctrl+c, which is caught by your except statement and results in printing "Unable to perform Action".

You could add an exception handler for the KeyboardInterrupt exception with exit() to end the program, ones you hit Ctrl+c:

try:
    ...
except KeyboardInterrupt:
    exit()
except:
    print("Unable to perform Action")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading