Skip to content

Chore/update getOrders #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/orderbook/src/lib/orderbook/orderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,25 @@ export class Orderbook implements IOrderbook {
async getOrders<T extends boolean>(
matched: T,
paginationConfig?: PaginationConfig,
address?: string,
tx_hash?: string,
): AsyncResult<
PaginatedData<T extends true ? MatchedOrder : CreateOrder>,
string
> {
const endPoint = matched ? '/matched' : '/unmatched';
const url = ConstructUrl(
this.Url.endpoint('orders'),
endPoint,
paginationConfig,
);

const params: Record<string, any> = {};
if (paginationConfig) {
params['page'] = paginationConfig.page;
params['per_page'] = paginationConfig.per_page;
}
if (address) {
params['address'] = address;
}
if (tx_hash) {
params['tx_hash'] = tx_hash;
}
const url = ConstructUrl(this.Url.endpoint('orders'), endPoint, params);
try {
const res = await Fetcher.get<
APIResponse<PaginatedData<T extends true ? MatchedOrder : CreateOrder>>
Expand Down
4 changes: 4 additions & 0 deletions packages/orderbook/src/lib/orderbook/orderbook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ export interface IOrderbook {
* Get all orders from the orderbook based on the match status.
* @param matched - If true, returns matched orders, else returns unmatched orders.
* @param paginationConfig - The configuration for the pagination.
* @param address - The address to get the orders for.
* @param tx_hash - The tx hash to get the orders for (initiate_tx_hash, redeem_tx_hash, refund_tx_hash).
* @returns {AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>} A promise that resolves to the orders.
*/
getOrders<T extends boolean>(
matched: T,
paginationConfig?: PaginationConfig,
address?: string,
tx_hash?: string,
): AsyncResult<
PaginatedData<T extends true ? MatchedOrder : CreateOrder>,
string
Expand Down