Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply rubocop #3

Open
kvokka opened this issue Oct 8, 2020 · 2 comments · Fixed by #4
Open

Apply rubocop #3

kvokka opened this issue Oct 8, 2020 · 2 comments · Fixed by #4
Assignees

Comments

@kvokka
Copy link
Collaborator

kvokka commented Oct 8, 2020

Project contain tons of hassle which makes reading the code harder, rubocop should heal it

@kvokka kvokka self-assigned this Oct 8, 2020
@kvokka kvokka mentioned this issue Oct 8, 2020
@topofocus
Copy link
Member

Hi,
I was unable to run the tests after applying the changes.
Got

newdevel:~/workspace/ib-api$ bundle exec guard
18:46:25 - INFO - Guard::RSpec is running
18:46:25 - INFO - Guard is now watching at '/home/ubuntu/workspace/ib-api'
18:46:54 - INFO - Running: spec/ib/connect_spec.rb

An error occurred while loading spec_helper.
Failure/Error: self::Classes[message_id] = message_class

FrozenError:
  can't modify frozen Hash
# ./lib/ib/messages/abstract_message.rb:92:in `def_message'
# ./lib/ib/messages/outgoing.rb:20:in `<module:Outgoing>'
# ./lib/ib/messages/outgoing.rb:8:in `<module:Messages>'
# ./lib/ib/messages/outgoing.rb:6:in `<module:IB>'
# ./lib/ib/messages/outgoing.rb:5:in `<top (required)>'
# ./lib/ib/messages.rb:11:in `require'
# ./lib/ib/messages.rb:11:in `<top (required)>'
# ./lib/ib/connection.rb:4:in `require'
# ./lib/ib/connection.rb:4:in `<top (required)>'
# ./lib/requires.rb:8:in `require'
# ./lib/requires.rb:8:in `<top (required)>'
# ./lib/ib-api.rb:6:in `require'
# ./lib/ib-api.rb:6:in `<top (required)>'
# ./spec/spec_helper.rb:7:in `require'
# ./spec/spec_helper.rb:7:in `<top (required)>'

revoked the merge into to master branch.

Lets look together, what went wrong (mail me: topofocus@gmail,com)

@topofocus topofocus reopened this Oct 12, 2020
@topofocus
Copy link
Member

topofocus commented Oct 15, 2020

Hi,
using the improved random id generation I run in some trouble

newdevel:~/workspace/ib-api/bin$ ./console 

>> IB-Core Interactive Console <<
---------------------------------------------

Namespace is IB ! 

---------------------------------------------
Connected to server, version: 137,
 connection time: 2020-10-15 12:47:44 +0000 local, 2020-10-15T12:47:43+00:00 remote.
< ManagedAccounts: DF167347 - DU167348 - DU167349>
TWS Warning 2107: HMDS data farm connection is inactive but should be available upon demand.ushmds
newdevel:~/workspace/ib-api/bin$ 

the console does not start

First I changed the method name to 'generate', because ib-api at some point tests if a Constant responds to call.

Same result.

When i switched bach to `random 99999' anything works fine again.
Then

newdevel:~/workspace/ib-api/lib$ grep -rn random_id .
./ib/connection.rb:44:                   client_id: random_id,
./ib/connection.rb:179:        id = random_id
./ib/connection.rb:416:		def random_id

leads to the solution: random_id is also used to generate id's for the received-array, where messages arriving from the tws are stored.

   def subscribe *args, &block
      @subscribe_lock.synchronize do
        subscriber = args.last.respond_to?(:call) ? args.pop : block
        id = random_id

Then this experiment reveals the problem.
Modifiying random_it to

		def random_id
			puts SafeRandIdGenerator.generate
			rand 9999
		end

ans subsequent usage of the console
``'`
newdevel:~/workspace/ib-api/bin$ ./console

IB-Core Interactive Console

Namespace is IB !


25967018522
25967018522
25967018522
25967018522
25967018522
25967018522
Connected to server, version: 137,
connection time: 2020-10-15 13:03:38 +0000 local, 2020-10-15T13:03:37+00:00 remote.
< ManagedAccounts: DF167347 - DU167348 - DU167349>
Got next valid order id: 14.


exploits that tws-messages went to only one received-array-entry. 

No wonder, that the application crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants