Thursday, 1 September 2016

Trading platform in Python 2

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()

    def create_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)

    def connect_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()

Pages: 1 2 3 4 5 6 7 8 9

Save

No comments:

Post a Comment