Hi,

I get an error when trying to compile a class that I have created: "EWrapperImpl.cs"
Error: TestCsharp.EWrapperImpl' does not implement interface member 'IBApi.EWrapper.currentTime(long)

It is documented in an example that: "you need to provide at least an empty shell of the method declared in EWrapper"
but I don't know how to do this. I wonder if it is a basic delaration that can be done in EWrapper ?

    namespace TestCsharp
    {
        public class EWrapperImpl : EWrapper
        {

            EClientSocket clientSocket;

            private int nextOrderId;

            public EWrapperImpl()
            {
                clientSocket = new EClientSocket(this);
            }

            public EClientSocket ClientSocket
            {
                get { return clientSocket; }
                set { clientSocket = value; }
            }


        }
    }

Dani AI

Generated

As discovered, the class declared as : EWrapper must provide implementations for every member the EWrapper interface defines. Use the IDE to inspect EWrapper (or hit Ctrl+. as suggested) and either copy the exact signature or let Visual Studio generate stubs. This is the normal C# rule: a class that implements an interface must implement all non‑default members. (learn.microsoft.com)

Add the missing currentTime method to your EWrapperImpl with the exact signature declared by IB's interface. A minimal implementation might look like this:

public void currentTime(long time)
{
    // IB's currentTime historically returns a Unix epoch value (seconds).
    var utc = DateTimeOffset.FromUnixTimeSeconds(time).UtcDateTime;
    System.Diagnostics.Debug.WriteLine($"TWS currentTime: {utc:O}");
    // store/use utc as needed
}

Check the EWrapper you're compiling against — the IB API declares currentTime(long) on EWrapper. Newer API releases also added a currentTimeInMillis variant, so verify whether the value you receive is seconds or milliseconds before converting. (interactivebrokers.com)

If you prefer the method not to appear as a public member of your class, implement it explicitly so it is only called when the instance is cast to the interface:

void IBApi.EWrapper.currentTime(long time)
{
    // same body as above
}

Explicit implementations and the rules about matching signatures are covered in the C# docs — use explicit implementation when you want the member accessible only via the interface. If many methods are missing, use the IDE’s “Implement interface” quick action to generate all stubs, then fill them in. (learn.microsoft.com)

Recommended Answers

All 3 Replies

Can you show us EWapper? Is that an interface? If so click on it above and hit Ctrl period.

If it is an interface, then its a convention to name then with an I - eg IEwrapper

You're writing a class that implements an interface:

public class EWrapperImpl : EWrapper

This means your EWrapperImpl class must have methods that match everything in EWrapper...

Error: TestCsharp.EWrapperImpl' does not implement interface member 'IBApi.EWrapper.currentTime(long)

...but it doesn't, so...

you need to provide at least an empty shell of the method declared in EWrapper but I don't know how to do this. I wonder if it is a basic delaration that can be done in EWrapper ?

Implementing an interface is a way of saying, "My class has these methods."

EWrapperImpl needs to have a method called currentTime that matches the declaration in EWrapper; i.e., it has the same parameter and return types.

commented: supported. +3

Implement interface member is a way of saying my class has these methods. If it is an interface, then its a convention to name then with an I - eg IEwrapper.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.