-
Notifications
You must be signed in to change notification settings - Fork 320
/
Copy pathorderbook_call_builder.ts
33 lines (32 loc) · 1.4 KB
/
orderbook_call_builder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Asset } from "stellar-base";
import { CallBuilder } from "./call_builder";
import { ServerApi } from "./server_api";
/**
* Creates a new {@link OrderbookCallBuilder} pointed to server defined by serverUrl.
*
* Do not create this object directly, use {@link Server#orderbook}.
* @see [Orderbook Details](https://developers.stellar.org/api/aggregations/order-books/)
* @param {string|URL} serverUrl serverUrl Horizon server URL.
* @param {Asset} selling Asset being sold
* @param {Asset} buying Asset being bought
*/
export class OrderbookCallBuilder extends CallBuilder<ServerApi.OrderbookRecord> {
constructor(serverUrl: URL | string, selling: Asset, buying: Asset) {
super(serverUrl);
this.segment("order_book");
if (!selling.isNative()) {
this.url.searchParams.set("selling_asset_type", selling.getAssetType());
this.url.searchParams.set("selling_asset_code", selling.getCode());
this.url.searchParams.set("selling_asset_issuer", selling.getIssuer());
} else {
this.url.searchParams.set("selling_asset_type", "native");
}
if (!buying.isNative()) {
this.url.searchParams.set("buying_asset_type", buying.getAssetType());
this.url.searchParams.set("buying_asset_code", buying.getCode());
this.url.searchParams.set("buying_asset_issuer", buying.getIssuer());
} else {
this.url.searchParams.set("buying_asset_type", "native");
}
}
}