// GetOrderBook retrieves the limit order book. func GetOrderBook(c appengine.Context) (x xgen.OrderBook, err os.Error) { defer func() { if e, ok := recover().(os.Error); ok { err = e } }() var b OrderBook err = restapi.GetJson(c, JsonDepth, &b) check(err) for _, ask := range b.Asks { var o xgen.Order o.Price, err = strconv.Atof64(ask[Price]) check(err) o.Amount, err = strconv.Atof64(ask[Amount]) check(err) x.SellTree = append(x.SellTree, o) } for _, bid := range b.Bids { var o xgen.Order o.Price, err = strconv.Atof64(bid[Price]) check(err) o.Amount, err = strconv.Atof64(bid[Amount]) check(err) x.BuyTree = append(x.BuyTree, o) } if !x.Validate() { panic("Invalid Depth") } sort.Sort(x.BuyTree) sort.Sort(x.SellTree) x.BuyTree.Reverse() return }
// GetQuote retrieves the "ticker" data. func GetQuote(c appengine.Context) (x xgen.Quote, err os.Error) { defer func() { if e, ok := recover().(os.Error); ok { err = e } }() var q Quote err = restapi.GetJson(c, JsonTicker, &q) check(err) x.Date = datastore.SecondsToTime(time.Seconds()) x.HighestBuy = q.Ticker.Buy x.LowestSell = q.Ticker.Sell x.Last = q.Ticker.Last if !x.Validate() { panic("Invalid Ticker") } return }