Skip to content

Commit 19a594f

Browse files
authored
Merge pull request #60 from trader-xyz/feat/order-filtering-arrays
Adds more filtering options for searching 0x v4 public orderbook
2 parents f881391 + 3e9e758 commit 19a594f

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"isomorphic-unfetch": "^3.1.0",
7474
"lodash": "^4.17.21",
7575
"lodash-es": "^4.17.21",
76+
"query-string": "^7.1.1",
7677
"tiny-invariant": "^1.2.0",
7778
"tiny-warning": "^1.0.3",
7879
"uuid": "^8.3.2"

src/sdk/v4/orderbook.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unfetch from 'isomorphic-unfetch';
2+
import { stringify } from 'query-string';
23
import type { SignedNftOrderV4, SignedNftOrderV4Serialized } from './types';
3-
import { stringify } from '../../utils/query-string';
44
import { serializeNftOrder } from './pure';
55

66
export const ORDERBOOK_API_ROOT_URL_PRODUCTION = 'https://api.trader.xyz';
@@ -74,25 +74,44 @@ const postOrderToOrderbook = async (
7474
return orderPostResult;
7575
};
7676

77+
/**
78+
* Available query parameters for searching the orderbook
79+
*/
7780
export interface SearchOrdersParams {
78-
erc20Token?: string;
79-
nftTokenId?: string;
80-
nftToken?: string;
81-
nftType?: string;
82-
chainId?: string;
83-
maker?: string;
84-
taker?: string;
85-
nonce?: string;
81+
nftTokenId: string | string[];
82+
erc20Token: string | string[];
83+
nftToken: string | string[];
84+
nftType: 'ERC721' | 'ERC1155';
85+
chainId: string | number | string[] | number[];
86+
maker: string;
87+
taker: string;
88+
nonce: string | string[];
89+
offset: string | number;
90+
limit: string | number;
91+
sellOrBuyNft: 'sell' | 'buy';
92+
direction: '0' | '1';
8693
// Defaults to only 'open' orders
87-
status?: 'open' | 'filled' | 'expired' | 'cancelled' | 'all';
94+
status: 'open' | 'filled' | 'expired' | 'cancelled' | 'all';
95+
visibility: 'public' | 'private';
96+
valid: 'valid' | 'all';
8897
}
8998

99+
/**
100+
* Search through the public hosted orderbook
101+
* @param filters Optional query param filters
102+
* @param requestOptions Fetch options/overrides
103+
* @param fetchFn Optional fetch function override. Uses unfetch by default.
104+
* @returns
105+
*/
90106
const searchOrderbook = async (
91107
filters?: Partial<SearchOrdersParams>,
92108
requestOptions?: Partial<OrderbookRequestOptions>,
93109
fetchFn: typeof unfetch = unfetch
94110
): Promise<SearchOrdersResponsePayload> => {
95-
const stringifiedQueryParams = stringify(filters ?? {});
111+
// https://github.com/sindresorhus/query-string#arrayformat
112+
const stringifiedQueryParams = stringify(filters ?? {}, {
113+
arrayFormat: 'none',
114+
});
96115

97116
let rootUrl = requestOptions?.rootUrl ?? ORDERBOOK_API_ROOT_URL_PRODUCTION;
98117

yarn.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,6 +3519,11 @@ fill-range@^7.0.1:
35193519
dependencies:
35203520
to-regex-range "^5.0.1"
35213521

3522+
filter-obj@^1.1.0:
3523+
version "1.1.0"
3524+
resolved "https://registry.yarnpkg.com/filter-obj/-/filter-obj-1.1.0.tgz#9b311112bc6c6127a16e016c6c5d7f19e0805c5b"
3525+
integrity sha1-mzERErxsYSehbgFsbF1/GeCAXFs=
3526+
35223527
find-cache-dir@^3.3.1:
35233528
version "3.3.2"
35243529
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.2.tgz#b30c5b6eff0730731aea9bbd9dbecbd80256d64b"
@@ -5717,6 +5722,16 @@ qs@~6.5.2:
57175722
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
57185723
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
57195724

5725+
query-string@^7.1.1:
5726+
version "7.1.1"
5727+
resolved "https://registry.yarnpkg.com/query-string/-/query-string-7.1.1.tgz#754620669db978625a90f635f12617c271a088e1"
5728+
integrity sha512-MplouLRDHBZSG9z7fpuAAcI7aAYjDLhtsiVZsevsfaHWDS2IDdORKbSd1kWUA+V4zyva/HZoSfpwnYMMQDhb0w==
5729+
dependencies:
5730+
decode-uri-component "^0.2.0"
5731+
filter-obj "^1.1.0"
5732+
split-on-first "^1.0.0"
5733+
strict-uri-encode "^2.0.0"
5734+
57205735
queue-microtask@^1.2.2:
57215736
version "1.2.3"
57225737
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
@@ -6371,6 +6386,11 @@ spdx-license-ids@^3.0.0:
63716386
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.10.tgz#0d9becccde7003d6c658d487dd48a32f0bf3014b"
63726387
integrity sha512-oie3/+gKf7QtpitB0LYLETe+k8SifzsX4KixvpOsbI6S0kRiRQ5MKOio8eMSAKQ17N06+wdEOXRiId+zOxo0hA==
63736388

6389+
split-on-first@^1.0.0:
6390+
version "1.1.0"
6391+
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
6392+
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
6393+
63746394
split-string@^3.0.1, split-string@^3.0.2:
63756395
version "3.1.0"
63766396
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
@@ -6418,6 +6438,11 @@ stealthy-require@^1.1.1:
64186438
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
64196439
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=
64206440

6441+
strict-uri-encode@^2.0.0:
6442+
version "2.0.0"
6443+
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
6444+
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
6445+
64216446
string-format@^2.0.0:
64226447
version "2.0.0"
64236448
resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b"

0 commit comments

Comments
 (0)