Skip to content

Calling GetAccountPositionsAsync returns an empty list the 2nd time #23

@pablocar80

Description

@pablocar80

I have code that creates a new client and lists the positions. If I execute the code twice, the 2nd call to GetAccountPositionsAsync will return an empty list. The log on IB Gateway shows that it returned the positions correctly both times.

    // Create a logger which will write messages to the console.
    var loggerFactory = LoggerFactory.Create(builder => builder
        .AddSimpleConsole(c => c.SingleLine = true)
        .SetMinimumLevel(LogLevel.Information));

    // Create the InterReact client by connecting to TWS/Gateway on your local machine.
    await using var client = await InterReactClient.ConnectAsync(options =>
    {
        options.AllowOrderPlacement = false;
        options.UseDelayedTicks = true;
        options.LogFactory = loggerFactory;
        options.IBPortAddresses = [4002];
    });

    var positions = await client.Service.GetAccountPositionsAsync();
    Console.WriteLine("Positions:");
    foreach (var line in positions)
    {
        if (line.Position == 0) continue;
        var text = $"{line.Contract.LocalSymbol}: {line.Position}";
        Console.WriteLine(text);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions