Code Monkey home page Code Monkey logo

Comments (14)

dsouzae avatar dsouzae commented on August 16, 2024

Hi Uwe,

Can you show your code how you are connecting to TWS running on the Windows VM? Specifically looking for the NewEngineOptions passed to the NewEngine function.

And the code on how you are connecting using your Perl script might help on diagnosing connection problems.

from ib.

uwe avatar uwe commented on August 16, 2024

This is my Go code:

package main

import (
"fmt"
"github.com/gofinance/ib"
"github.com/kr/pretty"
"time"
)

func main() {
gw := "127.0.0.1:7496"
opts := ib.NewEngineOptions{Gateway: gw}

engine, err := ib.NewEngine(opts)
if err != nil {
    fmt.Println("Could not connect to IB:", err)
}

id := engine.NextRequestID()
fmt.Println(id)

contract := ib.Contract{
    Symbol:       "GOOG",
    SecurityType: "STK",
    Exchange:     "SMART",
    Currency:     "USD",
}

m, err := ib.NewChainManager(engine, contract)
if err != nil {
    fmt.Println(err)
}

time.Sleep(5 * time.Second)

fmt.Printf("%# v", pretty.Formatter(m.Chains()))

defer m.Close()
defer engine.Stop()

}

I assume the code for the Contract search is wrong, but it fails way earlier.

The same code runs on Mac OS (at least the connection and the NextRequestID() call).

I have port forwarding for my VM. This is working, as my perl script can connect to the Windows VM (from Mac) without any problems.

Here is my perl script (https://github.com/uwe/finance-tws-simple/blob/master/examples/contract.pl):

#!/usr/bin/env perl

show contract details

use strict;
use warnings;

use Data::Dumper;
use Finance::TWS::Simple;

my $tws = Finance::TWS::Simple->new(
host => $ENV{TWS_HOST} || '127.0.0.1',
port => $ENV{TWS_PORT} || '7496',
);

my $contract = $tws->struct(
Contract => {
symbol => 'EUR',
secType => 'CASH',
exchange => 'IDEALPRO',
localSymbol => 'EUR.USD',
},
);

my $details = $tws->call(
ContractDetails => {
contract => $contract,
},
);

warn Dumper $details;

As the perl code can connect, I doubt there is a general connection problem.

from ib.

dsouzae avatar dsouzae commented on August 16, 2024

From your first output, it looks like it connects but when it reads the buffer from the server, it looks like the server response is shorter than what was expected. I think the EOF is from a read on a short buffer.

What version of TWS are you running on your Windows? The golang version needs 943.2a or higher, see the testserver directory for the jar file.

Also you can can set "DumpConversation" to true in NewEngineOptions for extra debugging. You might be able to turn on client logging in TWS.

from ib.

uwe avatar uwe commented on August 16, 2024

On Windows I use the latest (web) version. I will report the exact number this evening. This is slightly newer than my Mac version.

When I set DumpConversation, the output does not change. Maybe it's the first read with the problem. I once put ReadByte (or whatever it was called) directly after the connect and it could not even read one byte - the error was the same: EOF. So something is really strange here.

from ib.

uwe avatar uwe commented on August 16, 2024

On Windows I use 948.3c (from 5th of January 2015).

from ib.

uwe avatar uwe commented on August 16, 2024

Maybe I found something: In types.go the startApi (71, 1, cliend_id) packet is sent immediately after the client_version (63). When I look at the Cpp reference implementation, startApi is just sent after the server_version and server_timestamp is received.

from ib.

dsouzae avatar dsouzae commented on August 16, 2024

not sure where that is. but if you look at engine.go, function handshake, it sends client version and reads server version first.

I think the EOF is returned from the call to serverShake.read...

from ib.

uwe avatar uwe commented on August 16, 2024

I looked at types.go:

func (c *clientHandshake) write(b *bytes.Buffer) error {
if err := writeInt(b, c.version); err != nil {
return err
}
if err := writeInt(b, mStartAPI); err != nil {
return err
}
if err := writeInt(b, 1); err != nil {
return err
}
return writeInt(b, c.id)
}

from ib.

dsouzae avatar dsouzae commented on August 16, 2024

you are right. I need to check against the IB Java reference implementation version of the latest version against the version this project is built against. I think if you used an old version of TWS it probably will work, but might of changed behaviour in a later version of TWS.

from ib.

dsouzae avatar dsouzae commented on August 16, 2024

I checked the reference implement that gofinance/ib is based off. You are right the handshake is not done correctly.

I will see if I can reproduce the issue and see if I can supply you with a patch after the weekend.

from ib.

dsouzae avatar dsouzae commented on August 16, 2024

Hi Uwe,

See my pull request #9.

I was able to reproduce the EOF issue, and my pull request fixes the issue. Still need to test if it works on older clients, but it matches the Java reference implementation for client version 63.

from ib.

uwe avatar uwe commented on August 16, 2024

Thanks. I will check this with my setup tomorrow (or maybe this evening). But so far it looks right.

Regarding older servers, I'm quite sure it won't work with very old servers because client version 63 changed the handshake. Before it was client version and then directly the client id. With 63 this startApi was introduced. But I think that is fine, because even the latest stable API is quite old (and the beta doesn't change that much).

from ib.

dsouzae avatar dsouzae commented on August 16, 2024

The code limits minimum server version to be 70. I tested against server versions 70 and 76, connection works okay for me.

from ib.

uwe avatar uwe commented on August 16, 2024

Thanks a lot. Your patch solves my connection problem.

from ib.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.