Create a trading platform using Python programming language.
connect to tws
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
from tkinter import *
from tkinter import ttk
import time
class Application(Frame):
def__init__(self, master):
"""Initialize the Frame"""
ttk.Frame.__init__(self, master)
self.port=7496
self.client_id = 86 # this can be any number
self.grid()
self.create_widgets()
defcreate_widgets(self):
""" create the window layout. """# create connect button widget
self.btnConnect = ttk.Button(self, text='Connect', command=self.connect_to_tws)
self.btnConnect.grid(row=0, column=0)
defconnect_to_tws(self):
self.tws_conn = Connection.create(port=self.port,
clientId=self.client_id)
self.tws_conn.connect()
root = Tk()
root.title("Connect to IB TWS with Python")
root.geometry('600x480')
root.attributes('-topmost', True)
app = Application(root)
root.mainloop()
No comments:
Post a Comment