Not able to work out my first program

I'm a 14 year-old-boy learning python and I was working on the following piece of code in Spyder and I'm using the IBridgePy library to connect with Interactive Brokers. When I run the code I get the following error:

    

TypeError: _set_default_values_for_user_input.<locals>.<lambda>() missing 1 required positional argument: 'y'



Can anyone help me as to why the error comes up and any way to solve it? I'm happy to do screen sharing as well at logaarav@gmail.com

import os

file_path = r"C:\Python for finance\IBridgePy_Win_Anaconda311_64\IBridgePy\trading_state.txt"

def save_state(layers, invested_amount, file_path):
    with open(file_path, "w") as file:
        file.write(f"{layers},{invested_amount}\n")

def load_state(file_path):
    if os.path.exists(file_path):
        with open(file_path, "r") as file:
            line = file.readline()
            layers, invested_amount = map(float, line.split(","))
            return int(layers), invested_amount
    else:
        return 0, 0


def myTradingAlgorithm():
    # Initialize parameters
    symbol = 'KWEB'  # Replace with your desired stock symbol
    initial_investment = 10000  # Replace with your desired initial investment amount
    target_price = 100 # Entry price for your security
    buy_increment = 0.01  # Buy additional layers after a 1% drop
    profit_target = 0.05  # Sell each layer at a 5% profit
    max_layers = 10  # Maximum number of layers

    # Initialize variables
    current_price = get_last_price(symbol)
    # Load saved state or initialize
    layers, invested_amount = load_state(file_path)
    layered_target_price = target_price * ((layers * -1) + 100)/100

    while invested_amount >= 0 and layers < max_layers and current_price > 0:
        # Calculate the target price to buy a new layer
        target_buy_price = layered_target_price
        target_sell_price = layered_target_price * (1 + profit_target)
        
        # Check if the current price has dropped enough to buy a new layer
        if current_price <= target_buy_price:
            # Calculate the amount to invest in the new layer
            layer_investment = initial_investment / max_layers

            # Place buy order for the new layer
            place_order(symbol, layer_investment, 'BUY')
            
            #Add a condition that order should be filled
            # Update variables
            invested_amount += layer_investment
            layers += 1
        
        # Check if it's time to sell
        if current_price >= target_sell_price:
            # Place sell order for the entire invested amount
            place_order(symbol, layer_investment, 'SELL')
            
            #Add a condition that order should be filled
            # Update variables
            invested_amount -= layer_investment
            layers -= 1

        # Save state after each operation
        save_state(layers, invested_amount, file_path)
        #Update current price (you'll need to implement this function)
        current_price = get_last_price(symbol)

    # Exit the trading algorithm
    finish()

# Helper functions (you may need to implement these functions)
def get_last_price(symbol):
    # Implement this function to retrieve the last price of the given symbol
    pass

def place_order(symbol, quantity, action):
    # Implement this function to place an order for the given symbol, quantity, and action (BUY/SELL)
    pass

def finish():
    # Implement any necessary cleanup or finalization steps here
    pass

# Run the trading algorithm
ibridge_run(myTradingAlgorithm())

Hi Aarav,



The error you're encountering suggests that there's an issue with a lambda function inside the _set_default_values_for_user_input function in the IBridgePy library. Without seeing the specific code, it's a bit challenging to provide an exact solution, but here is some general advice on how to approach and potentially resolve this issue:

  1. Check Documentation and Examples: Ensure that you are using the library correctly by referring to the official documentation and any provided examples. Make sure you are following the correct syntax and usage patterns.
  2. Update IBridgePy: Check if there is a newer version of the IBridgePy library available. If so, consider updating to the latest version, as it might contain bug fixes that address the issue you're facing.
  3. Check Function Parameters: Examine the parameters of the lambda function mentioned in the error message. Ensure that the lambda function is defined with the correct number of parameters and that it's being called with the expected arguments.
  4. If the issue is still not resolved after following the above steps feel free to email the same to the IBridgePy team at IBridgePy@gmail.com.
Hope this helps!

Sorry for the late reply, thanks for the solution.