// 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 (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' IS NULL AND heff.details->>'sold_asset_issuer' IS NULL)`, 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' IS NULL AND heff.details->>'bought_asset_issuer' IS NULL)`, 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 }