Exemple #1
0
 def m_req_Update(self, sender, e):
     """ 
      <summary>
      Event notification for instrument lookup
      </summary>
     """
     if e.Instrument != None and e.Error == None:
         # Instrument was found
         print("Found: {0}".format(e.Instrument.Name))
         # Subscribe for Inside Market Data
         self.m_ps = ttapi.PriceSubscription(e.Instrument, ttapi.Dispatcher.Current)
         self.m_ps.Settings = ttapi.PriceSubscriptionSettings(ttapi.PriceSubscriptionType.InsideMarket)
         self.m_ps.FieldsUpdated += self.m_ps_FieldsUpdated
         self.m_ps.Start()
         # Create a TradeSubscription to listen for order / fill events only for orders submitted through it
         self.m_ts = tradebk.InstrumentTradeSubscription(self.m_apiInstance.Session, ttapi.Dispatcher.Current, e.Instrument, True, True, False, False)
         self.m_ts.OrderUpdated += self.m_ts_OrderUpdated
         self.m_ts.OrderAdded += self.m_ts_OrderAdded
         self.m_ts.OrderDeleted += self.m_ts_OrderDeleted
         self.m_ts.OrderFilled += self.m_ts_OrderFilled
         self.m_ts.OrderRejected += self.m_ts_OrderRejected
         self.m_ts.Start()
     elif e.IsFinal:
         # Instrument was not found and TT API has given up looking for it
         print("Cannot find instrument: {0}".format(e.Error.Message))
         self.Dispose()
    def m_req_Update(self, sender, e):
        """
        <summary>
		 Event notification for instrument lookup
		 </summary>
        """
        if e.Instrument != None and e.Error == None:
            # Instrument was found
            print("Found: {0}".format(e.Instrument.Name))
            self.statusbar.Text = "Found: {0}".format(e.Instrument.Name)
            # Subscribe for Inside Market Data
            self.m_ps = ttapi.PriceSubscription(e.Instrument,
                                                ttapi.Dispatcher.Current)
            self.m_ps.Settings = ttapi.PriceSubscriptionSettings(
                ttapi.PriceSubscriptionType.InsideMarket)
            self.m_ps.FieldsUpdated += self.m_ps_FieldsUpdated
            self.m_ps.Start()
        elif e.IsFinal:
            # Instrument was not found and TT API has given up looking for it
            print("Cannot find instrument: {0}".format(e.Error.Message))
            self.statusbar.Text = "Cannot find instrument: {0}".format(
                e.Error.Message)
            self.Dispose()
        else:
            print('Searching Instrument in progress...')
            self.statusbar.Text = 'Searching Instrument in progress...'
Exemple #3
0
 def Init(self):
     """ <summary>
      Initialize TT API
      </summary>
     """
     # Use "Universal Login" Login Mode
     h = ttapi.ApiInitializeHandler(self.ttApiInitComplete)
     ttapi.TTAPI.CreateUniversalLoginTTAPI(ttapi.Dispatcher.Current, self.m_username, self.m_password,h)
Exemple #4
0
 def Init(self):
     """ <summary>
      Initialize TT API
      </summary>
     """
     # Use "Universal Login" Login Mode
     h = ttapi.ApiInitializeHandler(self.ttApiInitComplete)
     ttapi.TTAPI.CreateXTraderModeTTAPI(ttapi.Dispatcher.Current, h)
Exemple #5
0
    def m_apiInstance_ConnectionStatusUpdate(self, sender, e):
        """
        <summary>
		 Event notification for status of authentication
		 </summary>
        """
        if e.Status.IsSuccess:
            # Add code here to begin working with the TT API
            # lookup an instrument
            self.m_req = ttapi.InstrumentLookupSubscription(
                self.m_apiInstance.Session, ttapi.Dispatcher.Current,
                ttapi.ProductKey(ttapi.MarketKey.Cme, ttapi.ProductType.Future,
                                 "YM"), "Jun17")
            self.m_req.Update += self.m_req_Update
            print("Connection Success!")
            self.m_req.Start()
        else:
            print("TT Login failed: {0}".format(e.Status.StatusMessage))
            self.Dispose()
    def m_apiInstance_ConnectionStatusUpdate(self, sender, e):
        """
        <summary>
		 Event notification for status of authentication
		 </summary>
        """
        if e.Status.IsSuccess:
            # Add code here to begin working with the TT API
            # lookup an instrument
            self.m_req = ttapi.InstrumentLookupSubscription(
                self.m_apiInstance.Session, ttapi.Dispatcher.Current,
                ttapi.ProductKey(self.instrexch, self.instrType, self.instr),
                self.instrMonth)
            self.m_req.Update += self.m_req_Update
            self.statusbar.Text = 'Connection Success... YOU R IN!'
            ##            print("Connection Success!")
            self.m_req.Start()
        else:
            print("TT Login failed: {0}".format(e.Status.StatusMessage))
            self.statusbar.Text = "TT Login failed: {0}".format(
                e.Status.StatusMessage)
            self.Dispose()
Exemple #7
0
 def m_ps_FieldsUpdated(self, sender, e):
     """ 
      <summary>
      Event notification for price update
      </summary>
     """
     if e.Error == None:
         # Make sure that there is a valid bid
         if e.Fields.GetBestBidPriceField().HasValidValue:
             if self.m_orderKey == "":
                 # If there is no order working, submit one through the first valid order feed.
                 # You should use the order feed that is valid for your purposes.
                 op = ttapi.OrderProfile(e.Fields.Instrument.GetValidOrderFeeds()[0], e.Fields.Instrument)
                 op.BuySell = ttapi.BuySell.Buy
                 op.AccountName = "12345678"
                 op.AccountType = ttapi.AccountType.A1
                 op.OrderQuantity = ttapi.Quantity.FromInt(e.Fields.Instrument, 1)
                 op.OrderType = ttapi.OrderType.Limit
                 op.LimitPrice = e.Fields.GetBestBidPriceField().Value
                 if not self.m_ts.SendOrder(op):
                     print("Send new order failed.  {0}".format(op.RoutingStatus.Message))
                     self.Dispose()
                 else:
                     self.m_orderKey = op.SiteOrderKey
                     print("Send new order succeeded.")
             elif self.m_ts.Orders.ContainsKey(self.m_orderKey) and self.m_ts.Orders[self.m_orderKey].LimitPrice != e.Fields.GetBestBidPriceField().Value:
                 # If there is a working order, reprice it if its price is not the same as the bid
                 op = self.m_ts.Orders[self.m_orderKey].GetOrderProfile()
                 op.LimitPrice = e.Fields.GetBestBidPriceField().Value
                 op.Action = ttapi.OrderAction.Change
                 if not self.m_ts.SendOrder(op):
                     print("Send change order failed.  {0}".format(op.RoutingStatus.Message))
                 else:
                     print("Send change order succeeded.")
     else:
         if e.Error.IsRecoverableError == False:
             print("Unrecoverable price subscription error: {0}".format(e.Error.Message))
             self.Dispose()
Exemple #8
0
clr.AddReference('C:\\tt\\ttapi\\bin\\TradingTechnologies.TTAPI')

import TradingTechnologies.TTAPI as ttapi

help(ttapi)

ttapi.XTraderModeTTAPI
print(ttapi.XTraderModeTTAPI)
ttapi.XTraderModeTTAPI.Start()
ttapi.XTraderModeTTAPI.StartFillFeed
ttapi.XTraderModeTTAPI.StartFillFeed()
help(ttapi.Dispatcher)
disp = ttapi.Dispatcher.AttachWorkerDispatcher()
disp.BeginInvoke(new Action(Init))
disp.BeginInvoke(Action(Init))
disp.BeginInvoke(Action)
disp.BeginInvoke()
disp = ttapi.Dispatcher.AttachUIDispatcher()
h=ttapi.ApiInitializeHandler()
h=ttapi.ApiInitializeHandler(ttapi.FillUpdateFlag)
ttapi.XTraderModeTTAPIOptions.StartOrderFillFeed()
ttapi.XTraderModeTTAPI.ConnectionStatusUpdate()
ttapi.XTraderModeTTAPI.CreateXTraderModeTTAPI(disp,h)
ttapi.XTraderModeTTAPI.ConnectionStatusUpdate()
star = ttapi.XTraderModeTTAPI.CreateXTraderModeTTAPI(disp,h)
star = ttapi.XTraderModeTTAPI.Start()
ttapi.Session()
ttapi.XTraderModeTTAPI.ConnectionStatusUpdate()
ttapi.XTraderModeTTAPI.m_UserName()
ttapi.XTraderModeTTAPI.Shutdown()
Exemple #9
0
                self.m_req.Update -= self.m_req_Update
                self.m_req.Dispose()
                self.m_req = None
            if (self.m_ps != None):
                self.m_ps.FieldsUpdated -= self.m_ps_FieldsUpdated
                self.m_ps.Dispose()
                self.m_ps = None
        #Begin shutdown the TT API
        ttapi.TTAPI.ShutdownCompleted += self.TTAPI_ShutdownCompleted
        ttapi.TTAPI.Shutdown()
        self.m_disposed = True

# Unattached callbacks and dispose of all subscriptions
# Begin shutdown the TT API

    def TTAPI_ShutdownCompleted(self, sender, e):
        """ <summary>
		 Event notification for completion of TT API shutdown
		 </summary>
        """
        # Shutdown the Dispatcher
        if self.m_disp != None:
            self.m_disp.BeginInvokeShutdown()
            self.m_disp = None

with ttapi.Dispatcher.AttachUIDispatcher() as disp:
    tr = TTAPIReadForm()
    m_handler = ttapi.ApiInitializeHandler(tr.ttApiInitHandler)
    ttapi.TTAPI.CreateXTraderModeTTAPI(disp, m_handler)
    Application.Run(tr)
Exemple #10
0
 def loginBtn_eventhandler(self, sender, event):
     ##tf = TTAPIFunctions("CHOODTS","12345678")
     name = sender.Name
     self.m_disp = ttapi.Dispatcher.AttachUIDispatcher()
     self.m_handler = ttapi.ApiInitializeHandler(tr.ttApiInitHandler)
     ttapi.TTAPI.CreateXTraderModeTTAPI(self.m_disp, self.m_handler)