コード例 #1
0
ファイル: getAQuote.go プロジェクト: dshanabrook/quotes
func main() {
	ticker := os.Args[1]
	stockFromYahoo, err := stocks.GetQuote(ticker)
	if err != nil {
		fmt.Println(err)
	}
	aQuote, err := stockFromYahoo.GetPrice()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("this a a quote %6.2f of a value\n", aQuote)
}
コード例 #2
0
ファイル: ib.go プロジェクト: dshanabrook/go-ib
func main() {
	//deal with os.Args
	checkArgErrors(os.Args[1], os.Args[2], os.Args[3], os.Args[4], os.Args[5])
	theAction := os.Args[1]
	theAcct := acctNametoNumber(os.Args[2])
	useLeverage := os.Args[3] == "l"
	argShares := os.Args[4]
	outsideRTH, err := strconv.ParseBool(os.Args[5])
	if os.Args[5] == "outside" {
		outsideRTH = true
	} else {
		outsideRTH = false
	}

	myEngine, err := ib.NewEngine(ib.EngineOptions{})
	if err != nil {
		panic(err)
	}

	myAccountManager, err := ib.NewAdvisorAccountManager(myEngine)
	if err != nil {
		panic(err)
	}
	<-myAccountManager.Refresh()
	defer myAccountManager.Close()

	valueMap := myAccountManager.Values()
	stockFromYahoo, err := stocks.GetQuote(ticker)
	if err != nil {
		fmt.Println(err)
	}
	aQuote, err := stockFromYahoo.GetPrice()
	if err != nil {
		fmt.Println(err)
	}
	quoteSlipped := Round((aQuote+(aQuote*slippage))*100) / 100

	//check on shares based on leverage
	for aVk, aV := range valueMap {
		//availableFunds are either buyingPower or netliquadation
		correctAcct := (aVk.AccountCode == theAcct)
		correctForLever := (aVk.Key == "BuyingPower") && useLeverage
		correctForNoLever := (aVk.Key == "BuyingPower") && !useLeverage

		if correctAcct && correctForLever {
			shares = getShares(argShares, aV.Value, quoteSlipped)
			shares = shares - int64(float64(shares)*0.6)
		}
		if correctAcct && correctForNoLever {
			shares = getShares(argShares, aV.Value, quoteSlipped)
		}
	}
	//	fmt.Println("quote", aQuote, "slipped-", quoteSlipped, "shares", shares)
	mgr := IBManager{engine: myEngine}
	mgr.engine.SubscribeAll(rc)

	mgr.engine.Send(&ib.RequestIDs{})
	nextOrderID = getNextOrderID(mgr)
	//	fmt.Println("the next order ID is: ", nextOrderID)

	if theAction == "buy" {
		doBuy(&mgr,
			"AAPL",
			shares,       // number shares
			"LOC",        // mkt, moc, lmt
			quoteSlipped, // price
			theAcct,      // account
			"DAY",        // DAY OPG
			nextOrderID,
			outsideRTH) //out side regular trading hours
	} else if theAction == "sell" { //positions := ib.RequestPositions
		doSell(&mgr, "AAPL", shares, "MARKET", "OPG", nextOrderID)
	} else {
		fmt.Println("neither a buy nor a sell")
	}
	//	nextOrderID = getNextOrderID(mgr)
}