amittleider / AutoFinance.Broker

A Dotnet Core library to interact with Interactive Broker's Trader Workstation (IB TWS)
32 stars 16 forks source link

One or more errors occurred. (A task was canceled.) #32

Open Korshack opened 4 years ago

Korshack commented 4 years ago

Hi, I'm using your code to interact with IB gateway. The problem occurs when I call a method twice or more. Why all times I get "A task was canceled" error? I'm doing something wrong?. Sorry I'm new with Task on .Net and Cancellation tokens.

sceen

amittleider commented 4 years ago

Hi Korshak,

Can you try to place all that in an async Main() and call the api with "await twsController.Connect()" and "await twsController.GetAccountDetails()". If that doesnt work, please try to make a call to PlaceOrder (or any other API) and tell me if it works.

Please be sure to log into your paper account while testing. I see that you are on port 4002, which is default for live accounts. Be careful.

-Andrew

Le mar. 27 oct. 2020 à 19:17, Korshack notifications@github.com a écrit :

Hi, I'm using your code to interact with IB gateway. The problem occurs when I call a method twice or more. Why all times I get "A task was canceled" error? I'm doing something wrong?. Sorry I'm new with Task on .Net and Cancellation tokens.

[image: sceen] https://user-images.githubusercontent.com/11540471/97344097-9804c380-1888-11eb-929e-9a5e5f8f5939.PNG

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/amittleider/AutoFinance.Broker/issues/32, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMM6X72CUH6WMXFDWMA6CDSM4FCDANCNFSM4TBGSSGA .

rob-chambers commented 4 years ago

Hi @Korshack , I agree with @amittleider. When writing async code, you should avoid .Wait() and .Result if possible because you block the thread. Instead, await the async method and ensure you use async all the way down the call stack. You can make the main method async now as of C# 7.1.