コード例 #1
0
ファイル: ibstockcli.go プロジェクト: dsouzae/ibstockcli
func doSellTrail(mgr *IBManager, symbol string, quantity uint64, trailamount float64) {
	request := ib.PlaceOrder{
		Contract: NewContract(symbol),
	}

	request.Order, _ = NewOrder()
	request.Order.Action = "SELL"
	request.Order.TotalQty = int64(quantity)
	request.Order.OrderType = "TRAIL"
	request.Order.AuxPrice = trailamount
	request.SetID(mgr.NextOrderID())

	mgr.engine.Send(&request)
	log.Printf("%s: Sending SELL for %s, quantity %v, %s - %.2f", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.AuxPrice)
}
コード例 #2
0
ファイル: ibstockcli.go プロジェクト: dsouzae/ibstockcli
func doStopMarket(mgr *IBManager, symbol string, quantity uint64, stopprice float64) {
	request := ib.PlaceOrder{
		Contract: NewContract(symbol),
	}

	request.Order, _ = NewOrder()
	request.Order.Action = "SELL"
	request.Order.TotalQty = int64(quantity)
	request.Order.OrderType = "STP"
	request.Order.AuxPrice = stopprice

	request.SetID(mgr.NextOrderID())

	mgr.engine.Send(&request)
	log.Printf("%s: Sending STP SELL for %s, quantity %v, - %s - %v", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.AuxPrice)
}
コード例 #3
0
ファイル: ibstockcli.go プロジェクト: dsouzae/ibstockcli
func doBuyTrailLimit(mgr *IBManager, symbol string, quantity uint64, trailamount float64, stopprice float64, limitoffset float64) {
	request := ib.PlaceOrder{
		Contract: NewContract(symbol),
	}

	request.Order, _ = NewOrder()
	request.Order.Action = "BUY"
	request.Order.TotalQty = int64(quantity)
	request.Order.OrderType = "TRAIL LIMIT"
	request.Order.AuxPrice = trailamount
	request.Order.TrailStopPrice = stopprice
	request.Order.LimitPrice = stopprice + limitoffset
	request.SetID(mgr.NextOrderID())

	mgr.engine.Send(&request)
	log.Printf("%s: Sending BUY for %s, quantity %v, %s - trail:%.2f stop:%.2f", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.AuxPrice, request.Order.TrailStopPrice)
}
コード例 #4
0
ファイル: ib.go プロジェクト: dshanabrook/go-ib
func doBuy(mgr *IBManager, symbol string, quantity int64, orderType string, limitPrice float64, account string, tIF string, nextOrderID int64, outsideRTH bool) {
	request := ib.PlaceOrder{Contract: NewContract(symbol)}

	request.Order, _ = NewOrder()
	request.Order.Action = "BUY"
	request.Order.TIF = tIF
	request.Order.OrderType = orderType
	request.Order.LimitPrice = limitPrice
	request.Order.TotalQty = quantity
	request.Order.Account = account
	request.Order.OutsideRTH = outsideRTH
	request.SetID(nextOrderID)

	fmt.Printf("%s %s %d shares at $%6.2f using %s, outside: %t\n", request.Order.Account, request.Order.Action, request.Order.TotalQty, request.Order.LimitPrice, request.Order.OrderType, request.Order.OutsideRTH)
	if doExecute {
		mgr.engine.Send(&request)
	}

}
コード例 #5
0
ファイル: ibstockcli.go プロジェクト: dsouzae/ibstockcli
func doBuy(mgr *IBManager, symbol string, quantity uint64, market bool, price float64) {
	request := ib.PlaceOrder{
		Contract: NewContract(symbol),
	}

	request.Order, _ = NewOrder()
	request.Order.Action = "BUY"
	request.Order.TotalQty = int64(quantity)

	if market {
		request.Order.OrderType = "MKT"
	} else {
		request.Order.OrderType = "LMT"
		request.Order.LimitPrice = price
	}
	request.SetID(mgr.NextOrderID())

	mgr.engine.Send(&request)
	log.Printf("%s: Sending BUY for %s, quantity %v, - %s - %v", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.LimitPrice)
}
コード例 #6
0
ファイル: ib.go プロジェクト: dshanabrook/go-ib
func doSell(mgr *IBManager, symbol string, shares int64, orderType string, tIF string, nextOrderID int64) {
	request := ib.PlaceOrder{Contract: NewContract(symbol)}

	request.Order, _ = NewOrder()
	request.Order.Action = "SELL"
	request.Order.TIF = tIF
	request.Order.OrderType = orderType
	request.Order.LimitPrice = 0
	request.Order.FAMethod = "PctChange"
	request.Order.FAPercentage = "-70"
	request.Order.FAGroup = "everyone"
	request.Order.FAProfile = ""
	request.Order.Account = ""

	request.SetID(nextOrderID)
	fmt.Printf("%s %s %s%% at %s, using %s\n", request.Order.FAGroup, request.Order.Action, request.Order.FAPercentage, request.Order.TIF, request.Order.OrderType)
	if doExecute {
		mgr.engine.Send(&request)
	}

}
コード例 #7
0
ファイル: ibstockcli.go プロジェクト: dsouzae/ibstockcli
func doBracket(mgr *IBManager, symbol string, quantity uint64, buyprice float64, sellprice float64, stopprice float64) {
	var parentid int64

	request := ib.PlaceOrder{
		Contract: NewContract(symbol),
	}

	parentid = mgr.NextOrderID()
	request.SetID(parentid)
	request.Order, _ = NewOrder()
	request.Order.Transmit = false
	request.Order.Action = "BUY"
	request.Order.TotalQty = int64(quantity)
	request.Order.OrderType = "LMT"
	request.Order.LimitPrice = buyprice

	mgr.engine.Send(&request)
	log.Printf("%s: BRK - Sending BUY for %s, quantity %v, - %s - %v", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.LimitPrice)

	request.SetID(mgr.NextOrderID())
	request.Order, _ = NewOrder()
	request.Order.ParentID = parentid
	request.Order.Transmit = false

	request.Order.Action = "SELL"
	request.Order.TotalQty = int64(quantity)
	request.Order.OrderType = "STP"
	request.Order.AuxPrice = stopprice

	mgr.engine.Send(&request)
	log.Printf("%s: BRK - Sending STP for %s, quantity %v, - %s - %v", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.AuxPrice)

	request.SetID(mgr.NextOrderID())
	request.Order, _ = NewOrder()
	request.Order.ParentID = parentid

	request.Order.Action = "SELL"
	request.Order.TotalQty = int64(quantity)
	request.Order.OrderType = "LMT"
	request.Order.LimitPrice = sellprice

	mgr.engine.Send(&request)
	log.Printf("%s: BRK - Sending SELL for %s, quantity %v, - %s - %v", mgr.label, symbol, quantity, request.Order.OrderType, request.Order.LimitPrice)
}