Exemplo n.º 1
0
// NewOrderBookSummaryResource converts the provided query and summary into a json object
// that can be displayed to the end user.
func NewOrderBookSummaryResource(query db.OrderBookSummaryQuery, summary db.OrderBookSummaryRecord) (result OrderBookSummaryResource, err error) {
	bt, err := assets.String(query.SellingType)
	if err != nil {
		return
	}

	ct, err := assets.String(query.BuyingType)
	if err != nil {
		return
	}

	result = OrderBookSummaryResource{
		Bids: newPriceLevelResources(summary.Bids()),
		Asks: newPriceLevelResources(summary.Bids()),
		Selling: AssetResource{
			AssetType:   bt,
			AssetCode:   query.SellingCode,
			AssetIssuer: query.SellingIssuer,
		},
		Buying: AssetResource{
			AssetType:   ct,
			AssetCode:   query.BuyingCode,
			AssetIssuer: query.BuyingIssuer,
		},
	}

	return
}
Exemplo n.º 2
0
func (this *OrderBookSummary) Populate(ctx context.Context, query *db.OrderBookSummaryQuery, row db.OrderBookSummaryRecord) error {

	st, err := assets.String(query.SellingType)
	if err != nil {
		return err
	}

	bt, err := assets.String(query.BuyingType)
	if err != nil {
		return err
	}

	this.Selling = Asset{
		Type:   st,
		Code:   query.SellingCode,
		Issuer: query.SellingIssuer,
	}
	this.Buying = Asset{
		Type:   bt,
		Code:   query.BuyingCode,
		Issuer: query.BuyingIssuer,
	}

	this.populateLevels(&this.Bids, row.Bids())
	this.populateLevels(&this.Asks, row.Asks())

	return nil
}