Example #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
}
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
}
Example #3
0
func (f *EffectOrderBookFilter) Apply(ctx context.Context, in sq.SelectBuilder) (sql sq.SelectBuilder, err error) {
	sql = in

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

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

	if f.SellingType == xdr.AssetTypeAssetTypeNative {
		sql = sql.Where(`
				(heff.details->>'sold_asset_type' = ?
		AND heff.details ?? 'sold_asset_code' = false
		AND heff.details ?? 'sold_asset_issuer' = false)`,
			sellingType,
		)
	} else {
		sql = sql.Where(`
				(heff.details->>'sold_asset_type' = ?
		AND heff.details->>'sold_asset_code' = ?
		AND heff.details->>'sold_asset_issuer' = ?)`,
			sellingType,
			f.SellingCode,
			f.SellingIssuer,
		)
	}

	if f.BuyingType == xdr.AssetTypeAssetTypeNative {
		sql = sql.Where(`
				(heff.details->>'bought_asset_type' = ?
		AND heff.details ?? 'bought_asset_code' = false
		AND heff.details ?? 'bought_asset_issuer' = false)`,
			buyingType,
		)
	} else {
		sql = sql.Where(`
				(heff.details->>'bought_asset_type' = ?
		AND heff.details->>'bought_asset_code' = ?
		AND heff.details->>'bought_asset_issuer' = ?)`,
			buyingType,
			f.BuyingCode,
			f.BuyingIssuer,
		)
	}

	if err != nil {
		return
	}

	return
}
Example #4
0
func (this *Balance) PopulateNative(stroops xdr.Int64) (err error) {
	this.Type, err = assets.String(xdr.AssetTypeAssetTypeNative)
	if err != nil {
		return
	}

	this.Balance = amount.String(stroops)
	this.Limit = ""
	this.Issuer = ""
	this.Code = ""
	return
}
Example #5
0
func (this *Balance) Populate(ctx context.Context, row core.Trustline) (err error) {
	this.Type, err = assets.String(row.Assettype)
	if err != nil {
		return
	}

	this.Balance = amount.String(row.Balance)
	this.Limit = amount.String(row.Tlimit)
	this.Issuer = row.Issuer
	this.Code = row.Assetcode
	return
}