예제 #1
0
 def onLoadInstrumentEnd(self, instrumentName, success):
     try:
         print "Instrument ", instrumentName, " Loaded."
         inst = Context.Context_getInstance().getInstrument(instrumentName)
         print "subscribing instrument ", inst.getInstrumentName()
         Context.Context_getInstance().subscribe(inst)
     except Exception, e:
         print e
예제 #2
0
    def onLogin(self, val):
        try:
            print "************ Got onLogin ********************* ", val
            print "Calling Load instrument for ", sd.firstLegSymbol
            if val == False:
                print "Login Error...."
            else:
                print "Calling Load instrument for ", sd.firstLegSymbol
                Context.Context_getInstance().loadInstrument(sd.firstLegSymbol)
                Context.Context_getInstance().loadInstrument(
                    sd.secondLegSymbol)

            print "************** On login End ****************"
        except Exception, e:
            print e
예제 #3
0
 def cancelFirstLeg(self):
     try:
         print "\n**************** In cancelFirstLeg *********************\n"
         sd.firstLegOrder.setTransactionType(Context.TransactionType_CANCEL)
         sd.firstLegOrder.setSymbol(sd.firstLegSymbol)
         sd.firstLegOrder.setOrderStatus(Context.OrderStatus_PENDING)
         sd.firstLegOrder.setOrigClOrdId(sd.firstLegOrder.getOrigClOrdId())
         sd.firstLegOrder.setClOrdId(sd.firstLegOrder.getClOrderId())
         Context.Context_getInstance().placeOrder(sd.firstLegOrder)
     except Exception, e:
         print e
예제 #4
0
    def onExecutionReport(self, execReport):
        try:
            print "Got on onreportutionReport Event."
            execReport.dump()
            if execReport.getInstrumentName() == sd.firstLegSymbol:

                if execReport.getOrderStatus(
                ) == Context.OrderStatus_CONFIRMED:
                    sd.firstLegOrder.setClOrdId(execReport.getClOrderId())
                    sd.firstLegOrder.setOrigClOrdId(
                        execReport.getOriginalClOrderId())
                    sd.firstLegOrder.setOrderStatus(
                        Context.OrderStatus_CONFIRMED)
                    sd.isOrderPending = False

                elif execReport.getOrderStatus(
                ) == Context.OrderStatus_REPLACED:
                    sd.firstLegOrder.setClOrdId(execReport.getClOrderId())
                    sd.firstLegOrder.setOrigClOrdId(
                        execReport.getOriginalClOrderId())
                    sd.firstLegOrder.setOrderStatus(
                        Context.OrderStatus_CONFIRMED)
                    sd.isOrderPending = False
                elif execReport.getOrderStatus() == Context.OrderStatus_FILLED:
                    self.placeSecondLegMarket()
                    sd.isOrderPending = True

            elif execReport.getInstrumentName() == sd.secondLegSymbol:
                if execReport.getOrderStatus(
                ) == Context.OrderStatus_CONFIRMED:
                    sd.secondLegOrder.setClOrdId(execReport.getClOrderId())
                    sd.secondLegOrder.setOrigClOrdId(
                        execReport.getOriginalClOrderId())
                    sd.isOrderPending = False
                elif execReport.getOrderStatus() == Context.OrderStatus_FILLED:
                    print "Strategy completed successfully."
                    netPos = Context.Portfolio_getInstance().getNetPositions()
                    firstInst = Context.Context_getInstance().getInstrument(
                        sd.firstLegSymbol)
                    firstPos = netPos.getPosition(firstInst, sd.firstLegSide)
                    print "Qty from net position for first leg : ", firstPos.getQuantity(
                    )
                    print "Price from net position for first leg : ", firstPos.getAveragePrice(
                    )
                    tradeBook = Context.Portfolio_getInstance().getTradeBook()
                    trdlst = tradeBook.getTrades()
                    print "Type ", type(trdlst)
                    print trdlst

        except Exception, e:
            print e
예제 #5
0
 def placeSecondLegMarket(self):
     try:
         print "\n**************** In placeSecondLegMarket ******************\n"
         sd.secondLegOrder.setTransactionType(Context.TransactionType_NEW)
         sd.secondLegOrder.setSymbol(sd.secondLegSymbol)
         sd.secondLegOrder.setOrderMode(sd.secondLegSide)
         sd.secondLegOrder.setQuantity(sd.qty)
         sd.secondLegOrder.setPrice(0)
         sd.secondLegOrder.setSecurityType(Context.InstrumentType_FUTURE)
         sd.secondLegOrder.setDisclosedQuantity(sd.qty)
         sd.secondLegOrder.setOrderValidity(Context.TimeInForce_DAY)
         sd.secondLegOrder.setOrderType(Context.OrderType_MARKET)
         sd.secondLegOrder.setOrderStatus(Context.OrderStatus_PENDING)
         Context.Context_getInstance().placeOrder(sd.secondLegOrder)
     except Exception, e:
         print e
예제 #6
0
 def firstLegBid(self):
     try:
         print "\n**************** In firstLegBid *********************\n"
         sd.firstLegOrder.setTransactionType(Context.TransactionType_NEW)
         sd.firstLegOrder.setSymbol(sd.firstLegSymbol)
         sd.firstLegOrder.setOrderMode(sd.firstLegSide)
         sd.firstLegOrder.setQuantity(sd.qty)
         sd.firstLegOrder.setPrice(sd.orderPriceFirstLeg)
         sd.firstLegOrder.setSecurityType(Context.InstrumentType_FUTURE)
         sd.firstLegOrder.setDisclosedQuantity(sd.qty)
         sd.firstLegOrder.setOrderValidity(Context.TimeInForce_DAY)
         sd.firstLegOrder.setOrderType(Context.OrderType_LIMIT)
         sd.firstLegOrder.setOrderStatus(Context.OrderStatus_PENDING)
         sd.previousBidPrice = sd.orderPriceFirstLeg
         Context.Context_getInstance().placeOrder(sd.firstLegOrder)
     except Exception, e:
         print e
예제 #7
0
 def modifyOrder(self):
     try:
         print "\n**************** In modifyOrder *********************\n"
         sd.firstLegOrder.setTransactionType(Context.TransactionType_MODIFY)
         sd.firstLegOrder.setSymbol(sd.firstLegSymbol)
         sd.firstLegOrder.setOrderMode(sd.firstLegSide)
         sd.firstLegOrder.setQuantity(sd.qty)
         sd.firstLegOrder.setPrice(sd.orderPriceFirstLeg)
         sd.firstLegOrder.setSecurityType(Context.InstrumentType_FUTURE)
         sd.firstLegOrder.setDisclosedQuantity(sd.qty)
         sd.firstLegOrder.setOrderValidity(Context.TimeInForce_DAY)
         sd.firstLegOrder.setOrderType(Context.OrderType_LIMIT)
         sd.firstLegOrder.setOrderStatus(Context.OrderStatus_PENDING)
         sd.firstLegOrder.setOrigClOrdId(sd.firstLegOrder.getOrigClOrdId())
         sd.firstLegOrder.setClOrdId(sd.firstLegOrder.getClOrderId())
         Context.Context_getInstance().placeOrder(sd.firstLegOrder)
     except Exception, e:
         print e
예제 #8
0
        tempQty = 0
        for i in range(5):
            p = md.getPrice(side, i + 1)
            q = md.getQty(side, i + 1)
            tempPrice = tempPrice + p * q
            tempQty = tempQty + q
            if tempQty >= qty:
                break
        if tempQty < qty:
            return False, 0
        avgPrice = tempPrice / tempQty
        print "avgPrice = ", avgPrice
        return True, avgPrice


sd = symbolData("ESMNSE INFY 20131031", "ESMNSE ACC 20131031", 267500, 0, 0,
                Context.Side_SELL, Context.Side_BUY, False, 1, -1, 0, 250,
                Context.Order(), Context.Order(), 0, 0, 0)
a = Bar(sd)
#a = Application()
contxt = Context.Context_getInstance()
contxt.setApplication(a)
host = "10.0.0.31"
passw = "pass2@123"
user = 14
port = 8286
try:
    contxt.login(user, passw, host, port, False)
except Exception, e:
    print e