2021-09-23 15:57:07 +00:00
|
|
|
# piker: trading gear for hackers
|
2022-03-08 14:52:22 +00:00
|
|
|
# Copyright (C) Tyler Goodlet (in stewardship for pikers)
|
2021-09-23 15:57:07 +00:00
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
'''
|
|
|
|
IB api client data feed reset hack for i3.
|
|
|
|
|
|
|
|
'''
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import i3ipc
|
|
|
|
|
|
|
|
i3 = i3ipc.Connection()
|
|
|
|
t = i3.get_tree()
|
|
|
|
|
2021-09-30 16:10:01 +00:00
|
|
|
orig_win_id = t.find_focused().window
|
|
|
|
|
2021-09-23 15:57:07 +00:00
|
|
|
# for tws
|
2021-09-24 15:27:35 +00:00
|
|
|
win_names: list[str] = [
|
|
|
|
'Interactive Brokers', # tws running in i3
|
2022-03-07 23:02:30 +00:00
|
|
|
'IB Gateway', # gw running in i3
|
|
|
|
# 'IB', # gw running in i3 (newer version?)
|
2021-09-24 15:27:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for name in win_names:
|
2022-03-07 23:02:30 +00:00
|
|
|
results = t.find_titled(name)
|
|
|
|
print(f'results for {name}: {results}')
|
2021-09-24 15:27:35 +00:00
|
|
|
if results:
|
|
|
|
con = results[0]
|
|
|
|
print(f'Resetting data feed for {name}')
|
|
|
|
win_id = str(con.window)
|
|
|
|
w, h = con.rect.width, con.rect.height
|
|
|
|
|
|
|
|
# TODO: seems to be a few libs for python but not sure
|
|
|
|
# if they support all the sub commands we need, order of
|
|
|
|
# most recent commit history:
|
|
|
|
# https://github.com/rr-/pyxdotool
|
|
|
|
# https://github.com/ShaneHutter/pyxdotool
|
|
|
|
# https://github.com/cphyc/pyxdotool
|
2022-03-08 14:52:22 +00:00
|
|
|
|
|
|
|
# TODO: only run the reconnect (2nd) kc on a detected
|
|
|
|
# disconnect?
|
|
|
|
for key_combo, timeout in [
|
2022-03-11 20:15:54 +00:00
|
|
|
# only required if we need a connection reset.
|
2022-03-08 14:52:22 +00:00
|
|
|
('ctrl+alt+r', 12),
|
2022-03-11 20:15:54 +00:00
|
|
|
# data feed reset.
|
2022-03-08 14:52:22 +00:00
|
|
|
('ctrl+alt+f', 6)
|
|
|
|
]:
|
|
|
|
subprocess.call([
|
|
|
|
'xdotool',
|
|
|
|
'windowactivate', '--sync', win_id,
|
|
|
|
|
|
|
|
# move mouse to bottom left of window (where there should
|
|
|
|
# be nothing to click).
|
|
|
|
'mousemove_relative', '--sync', str(w-4), str(h-4),
|
|
|
|
|
|
|
|
# NOTE: we may need to stick a `--retry 3` in here..
|
|
|
|
'click', '--window', win_id,
|
|
|
|
'--repeat', '3', '1',
|
|
|
|
|
|
|
|
# hackzorzes
|
|
|
|
'key', key_combo,
|
|
|
|
],
|
|
|
|
timeout=timeout,
|
|
|
|
)
|
2021-09-30 16:10:01 +00:00
|
|
|
|
|
|
|
# re-activate and focus original window
|
|
|
|
subprocess.call([
|
|
|
|
'xdotool',
|
|
|
|
'windowactivate', '--sync', str(orig_win_id),
|
|
|
|
'click', '--window', str(orig_win_id), '1',
|
|
|
|
])
|