parsec-api 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +7 -0
- package/client.d.mts +3 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts +3 -0
- package/client.d.ts.map +1 -1
- package/client.js +3 -0
- package/client.js.map +1 -1
- package/client.mjs +3 -0
- package/client.mjs.map +1 -1
- package/core/error.d.mts +12 -0
- package/core/error.d.mts.map +1 -1
- package/core/error.d.ts +12 -0
- package/core/error.d.ts.map +1 -1
- package/core/error.js +24 -0
- package/core/error.js.map +1 -1
- package/core/error.mjs +24 -0
- package/core/error.mjs.map +1 -1
- package/package.json +2 -2
- package/resources/events.d.mts +10 -0
- package/resources/events.d.mts.map +1 -1
- package/resources/events.d.ts +10 -0
- package/resources/events.d.ts.map +1 -1
- package/resources/events.js +13 -1
- package/resources/events.js.map +1 -1
- package/resources/events.mjs +13 -1
- package/resources/events.mjs.map +1 -1
- package/resources/exchanges.d.mts +22 -2
- package/resources/exchanges.d.mts.map +1 -1
- package/resources/exchanges.d.ts +22 -2
- package/resources/exchanges.d.ts.map +1 -1
- package/resources/exchanges.js +1 -1
- package/resources/exchanges.mjs +1 -1
- package/resources/execution-price.d.mts +58 -0
- package/resources/execution-price.d.mts.map +1 -0
- package/resources/execution-price.d.ts +58 -0
- package/resources/execution-price.d.ts.map +1 -0
- package/resources/execution-price.js +15 -0
- package/resources/execution-price.js.map +1 -0
- package/resources/execution-price.mjs +11 -0
- package/resources/execution-price.mjs.map +1 -0
- package/resources/index.d.mts +1 -0
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +3 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -0
- package/resources/index.mjs.map +1 -1
- package/resources/markets.d.mts +18 -0
- package/resources/markets.d.mts.map +1 -1
- package/resources/markets.d.ts +18 -0
- package/resources/markets.d.ts.map +1 -1
- package/resources/markets.js +30 -1
- package/resources/markets.js.map +1 -1
- package/resources/markets.mjs +29 -1
- package/resources/markets.mjs.map +1 -1
- package/src/client.ts +18 -0
- package/src/core/error.ts +29 -0
- package/src/resources/events.ts +24 -1
- package/src/resources/exchanges.ts +26 -2
- package/src/resources/execution-price.ts +79 -0
- package/src/resources/index.ts +5 -0
- package/src/resources/markets.ts +48 -1
- package/src/streaming.ts +18 -2
- package/src/version.ts +1 -1
- package/streaming.d.mts +5 -1
- package/streaming.d.mts.map +1 -1
- package/streaming.d.ts +5 -1
- package/streaming.d.ts.map +1 -1
- package/streaming.js +13 -2
- package/streaming.js.map +1 -1
- package/streaming.mjs +13 -2
- package/streaming.mjs.map +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/resources/markets.mjs
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
import { APIResource } from "../core/resource.mjs";
|
|
3
|
+
function findOutcomeByName(outcomes, target) {
|
|
4
|
+
const normalized = target.toLowerCase();
|
|
5
|
+
return outcomes.find((outcome) => outcome.name.toLowerCase() === normalized);
|
|
6
|
+
}
|
|
7
|
+
export function attachBinaryOutcomeGetters(market) {
|
|
8
|
+
if (!Object.prototype.hasOwnProperty.call(market, 'yes')) {
|
|
9
|
+
Object.defineProperty(market, 'yes', {
|
|
10
|
+
configurable: false,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
get: () => findOutcomeByName(market.outcomes, 'yes'),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (!Object.prototype.hasOwnProperty.call(market, 'no')) {
|
|
16
|
+
Object.defineProperty(market, 'no', {
|
|
17
|
+
configurable: false,
|
|
18
|
+
enumerable: false,
|
|
19
|
+
get: () => findOutcomeByName(market.outcomes, 'no'),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return market;
|
|
23
|
+
}
|
|
3
24
|
export class Markets extends APIResource {
|
|
4
25
|
/**
|
|
5
26
|
* Provide either `exchanges` (CSV) or `parsec_ids` (CSV). When `parsec_ids` is
|
|
6
27
|
* provided, other filters are not allowed.
|
|
7
28
|
*/
|
|
8
29
|
list(query = {}, options) {
|
|
9
|
-
|
|
30
|
+
const request = this._client.get('/api/v1/markets', {
|
|
31
|
+
query,
|
|
32
|
+
...options,
|
|
33
|
+
});
|
|
34
|
+
return request._thenUnwrap((data) => {
|
|
35
|
+
data.markets = data.markets.map((market) => attachBinaryOutcomeGetters(market));
|
|
36
|
+
return data;
|
|
37
|
+
});
|
|
10
38
|
}
|
|
11
39
|
}
|
|
12
40
|
//# sourceMappingURL=markets.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markets.mjs","sourceRoot":"","sources":["../src/resources/markets.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;AAItB,MAAM,OAAO,OAAQ,SAAQ,WAAW;IACtC;;;OAGG;IACH,IAAI,CACF,QAA6C,EAAE,EAC/C,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"markets.mjs","sourceRoot":"","sources":["../src/resources/markets.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;AAItB,SAAS,iBAAiB,CAA6B,QAAkB,EAAE,MAAc;IACvF,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACxC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,0BAA0B,CAGxC,MAAe;IACf,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;QACzD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE;YACnC,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;YACjB,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC;SACrD,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QACxD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE;YAClC,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;YACjB,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAuE,CAAC;AACjF,CAAC;AAED,MAAM,OAAO,OAAQ,SAAQ,WAAW;IACtC;;;OAGG;IACH,IAAI,CACF,QAA6C,EAAE,EAC/C,OAAwB;QAExB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YAClD,KAAK;YACL,GAAG,OAAO;SACX,CAAmC,CAAC;QACrC,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,IAAwB,EAAE,EAAE;YACtD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;YAChF,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/src/client.ts
CHANGED
|
@@ -37,6 +37,11 @@ import {
|
|
|
37
37
|
} from './resources/approvals';
|
|
38
38
|
import { EventListParams, EventListResponse, Events } from './resources/events';
|
|
39
39
|
import { ExchangeListResponse, Exchanges } from './resources/exchanges';
|
|
40
|
+
import {
|
|
41
|
+
ExecutionPrice,
|
|
42
|
+
ExecutionPriceRetrieveParams,
|
|
43
|
+
ExecutionPriceRetrieveResponse,
|
|
44
|
+
} from './resources/execution-price';
|
|
40
45
|
import { MarketListParams, MarketListResponse, Markets } from './resources/markets';
|
|
41
46
|
import { Orderbook, OrderbookRetrieveParams, OrderbookRetrieveResponse } from './resources/orderbook';
|
|
42
47
|
import {
|
|
@@ -162,6 +167,11 @@ export interface ClientOptions {
|
|
|
162
167
|
* Defaults to globalThis.console.
|
|
163
168
|
*/
|
|
164
169
|
logger?: Logger | undefined;
|
|
170
|
+
|
|
171
|
+
// TODO(verbose-mode): Add per-request debug override that logs raw request/response
|
|
172
|
+
// details (method, URL, headers, body, status) independent of global log level.
|
|
173
|
+
// pmxt exposes `verbose: true` per request, which is useful during strategy
|
|
174
|
+
// integration debugging without enabling global SDK logging noise.
|
|
165
175
|
}
|
|
166
176
|
|
|
167
177
|
/**
|
|
@@ -775,6 +785,7 @@ export class ParsecAPI {
|
|
|
775
785
|
|
|
776
786
|
exchanges: API.Exchanges = new API.Exchanges(this);
|
|
777
787
|
markets: API.Markets = new API.Markets(this);
|
|
788
|
+
executionPrice: API.ExecutionPrice = new API.ExecutionPrice(this);
|
|
778
789
|
orderbook: API.Orderbook = new API.Orderbook(this);
|
|
779
790
|
priceHistory: API.PriceHistory = new API.PriceHistory(this);
|
|
780
791
|
trades: API.Trades = new API.Trades(this);
|
|
@@ -822,6 +833,7 @@ export class ParsecAPI {
|
|
|
822
833
|
|
|
823
834
|
ParsecAPI.Exchanges = Exchanges;
|
|
824
835
|
ParsecAPI.Markets = Markets;
|
|
836
|
+
ParsecAPI.ExecutionPrice = ExecutionPrice;
|
|
825
837
|
ParsecAPI.Orderbook = Orderbook;
|
|
826
838
|
ParsecAPI.PriceHistory = PriceHistory;
|
|
827
839
|
ParsecAPI.Trades = Trades;
|
|
@@ -843,6 +855,12 @@ export declare namespace ParsecAPI {
|
|
|
843
855
|
type MarketListParams as MarketListParams,
|
|
844
856
|
};
|
|
845
857
|
|
|
858
|
+
export {
|
|
859
|
+
ExecutionPrice as ExecutionPrice,
|
|
860
|
+
type ExecutionPriceRetrieveResponse as ExecutionPriceRetrieveResponse,
|
|
861
|
+
type ExecutionPriceRetrieveParams as ExecutionPriceRetrieveParams,
|
|
862
|
+
};
|
|
863
|
+
|
|
846
864
|
export {
|
|
847
865
|
Orderbook as Orderbook,
|
|
848
866
|
type OrderbookRetrieveResponse as OrderbookRetrieveResponse,
|
package/src/core/error.ts
CHANGED
|
@@ -23,6 +23,35 @@ export class APIError<
|
|
|
23
23
|
this.error = error;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Machine-readable error code from API response body, when provided.
|
|
28
|
+
* Example: `insufficient_funds`, `rate_limit_exceeded`.
|
|
29
|
+
*/
|
|
30
|
+
get code(): string | undefined {
|
|
31
|
+
const code = (this.error as any)?.code;
|
|
32
|
+
return typeof code === 'string' ? code : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Retry hint from API response body, when provided.
|
|
37
|
+
*/
|
|
38
|
+
get retryable(): boolean | undefined {
|
|
39
|
+
const retryable = (this.error as any)?.retryable;
|
|
40
|
+
return typeof retryable === 'boolean' ? retryable : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
isCode(code: string): boolean {
|
|
44
|
+
return this.code === code;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
isRetryable(): boolean {
|
|
48
|
+
return this.retryable === true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
isInsufficientFunds(): boolean {
|
|
52
|
+
return this.code === 'insufficient_funds';
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
27
56
|
const msg =
|
|
28
57
|
error?.message ?
|
package/src/resources/events.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { APIResource } from '../core/resource';
|
|
4
4
|
import { APIPromise } from '../core/api-promise';
|
|
5
5
|
import { RequestOptions } from '../internal/request-options';
|
|
6
|
+
import { attachBinaryOutcomeGetters } from './markets';
|
|
6
7
|
|
|
7
8
|
export class Events extends APIResource {
|
|
8
9
|
/**
|
|
@@ -13,7 +14,17 @@ export class Events extends APIResource {
|
|
|
13
14
|
query: EventListParams | null | undefined = {},
|
|
14
15
|
options?: RequestOptions,
|
|
15
16
|
): APIPromise<EventListResponse> {
|
|
16
|
-
|
|
17
|
+
const request = this._client.get('/api/v1/events', {
|
|
18
|
+
query,
|
|
19
|
+
...options,
|
|
20
|
+
}) as APIPromise<EventListResponse>;
|
|
21
|
+
return request._thenUnwrap((data: EventListResponse) => {
|
|
22
|
+
data.events.forEach((event) => {
|
|
23
|
+
if (!event.markets) return;
|
|
24
|
+
event.markets = event.markets.map((market) => attachBinaryOutcomeGetters(market));
|
|
25
|
+
});
|
|
26
|
+
return data;
|
|
27
|
+
});
|
|
17
28
|
}
|
|
18
29
|
}
|
|
19
30
|
|
|
@@ -95,6 +106,18 @@ export namespace EventListResponse {
|
|
|
95
106
|
*/
|
|
96
107
|
outcomes: Array<Market.Outcome>;
|
|
97
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Convenience getter for binary markets: outcome where `name` is "Yes"
|
|
111
|
+
* (case-insensitive).
|
|
112
|
+
*/
|
|
113
|
+
readonly yes?: Market.Outcome;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Convenience getter for binary markets: outcome where `name` is "No"
|
|
117
|
+
* (case-insensitive).
|
|
118
|
+
*/
|
|
119
|
+
readonly no?: Market.Outcome;
|
|
120
|
+
|
|
98
121
|
/**
|
|
99
122
|
* Parsec group ID for cross-exchange event grouping.
|
|
100
123
|
*/
|
|
@@ -6,14 +6,38 @@ import { RequestOptions } from '../internal/request-options';
|
|
|
6
6
|
|
|
7
7
|
export class Exchanges extends APIResource {
|
|
8
8
|
/**
|
|
9
|
-
* Returns
|
|
9
|
+
* Returns exchange capabilities available to the authenticated customer.
|
|
10
10
|
*/
|
|
11
11
|
list(options?: RequestOptions): APIPromise<ExchangeListResponse> {
|
|
12
12
|
return this._client.get('/api/v1/exchanges', options);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export type ExchangeListResponse = Array<
|
|
16
|
+
export type ExchangeListResponse = Array<ExchangeListResponse.ExchangeCapability>;
|
|
17
|
+
|
|
18
|
+
export namespace ExchangeListResponse {
|
|
19
|
+
export interface ExchangeCapability {
|
|
20
|
+
/**
|
|
21
|
+
* Exchange identifier (e.g., "polymarket", "kalshi").
|
|
22
|
+
*/
|
|
23
|
+
id: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Human-readable exchange name.
|
|
27
|
+
*/
|
|
28
|
+
name: string;
|
|
29
|
+
|
|
30
|
+
has: ExchangeCapability.Has;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace ExchangeCapability {
|
|
34
|
+
export interface Has {
|
|
35
|
+
create_order: boolean;
|
|
36
|
+
fetch_markets: boolean;
|
|
37
|
+
websocket: boolean;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
17
41
|
|
|
18
42
|
export declare namespace Exchanges {
|
|
19
43
|
export { type ExchangeListResponse as ExchangeListResponse };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
import { APIPromise } from '../core/api-promise';
|
|
5
|
+
import { RequestOptions } from '../internal/request-options';
|
|
6
|
+
|
|
7
|
+
export class ExecutionPrice extends APIResource {
|
|
8
|
+
/**
|
|
9
|
+
* Estimates execution price (VWAP) for a hypothetical order without placing it.
|
|
10
|
+
*/
|
|
11
|
+
retrieve(
|
|
12
|
+
query: ExecutionPriceRetrieveParams,
|
|
13
|
+
options?: RequestOptions,
|
|
14
|
+
): APIPromise<ExecutionPriceRetrieveResponse> {
|
|
15
|
+
return this._client.get('/api/v1/execution-price', { query, ...options });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ExecutionPriceRetrieveResponse {
|
|
20
|
+
/**
|
|
21
|
+
* Volume-weighted average execution price, or null when no liquidity is available.
|
|
22
|
+
*/
|
|
23
|
+
avg_price?: number | null;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Number of contracts that would be filled.
|
|
27
|
+
*/
|
|
28
|
+
filled_amount: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* True when the full requested amount is fillable from current depth.
|
|
32
|
+
*/
|
|
33
|
+
fully_filled: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Number of orderbook levels consumed.
|
|
37
|
+
*/
|
|
38
|
+
levels_consumed: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Price impact vs best price, or null when no liquidity is available.
|
|
42
|
+
*/
|
|
43
|
+
slippage?: number | null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Total notional cost of the filled amount.
|
|
47
|
+
*/
|
|
48
|
+
total_cost: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ExecutionPriceRetrieveParams {
|
|
52
|
+
/**
|
|
53
|
+
* Requested order size in contracts.
|
|
54
|
+
*/
|
|
55
|
+
amount: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Unified market ID in format `{exchange}:{native_id}`.
|
|
59
|
+
*/
|
|
60
|
+
parsec_id: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Order side.
|
|
64
|
+
*/
|
|
65
|
+
side: 'buy' | 'sell';
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Outcome selector. For binary markets this is typically "yes" or "no"
|
|
69
|
+
* (case-insensitive). For categorical markets, this is required.
|
|
70
|
+
*/
|
|
71
|
+
outcome?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export declare namespace ExecutionPrice {
|
|
75
|
+
export {
|
|
76
|
+
type ExecutionPriceRetrieveResponse as ExecutionPriceRetrieveResponse,
|
|
77
|
+
type ExecutionPriceRetrieveParams as ExecutionPriceRetrieveParams,
|
|
78
|
+
};
|
|
79
|
+
}
|
package/src/resources/index.ts
CHANGED
|
@@ -20,6 +20,11 @@ export {
|
|
|
20
20
|
export { Events, type EventListResponse, type EventListParams } from './events';
|
|
21
21
|
export { Exchanges, type ExchangeListResponse } from './exchanges';
|
|
22
22
|
export { Markets, type MarketListResponse, type MarketListParams } from './markets';
|
|
23
|
+
export {
|
|
24
|
+
ExecutionPrice,
|
|
25
|
+
type ExecutionPriceRetrieveResponse,
|
|
26
|
+
type ExecutionPriceRetrieveParams,
|
|
27
|
+
} from './execution-price';
|
|
23
28
|
export {
|
|
24
29
|
Orderbook,
|
|
25
30
|
type OrderbookRetrieveResponse,
|
package/src/resources/markets.ts
CHANGED
|
@@ -4,6 +4,34 @@ import { APIResource } from '../core/resource';
|
|
|
4
4
|
import { APIPromise } from '../core/api-promise';
|
|
5
5
|
import { RequestOptions } from '../internal/request-options';
|
|
6
6
|
|
|
7
|
+
function findOutcomeByName<T extends { name: string }>(outcomes: Array<T>, target: string): T | undefined {
|
|
8
|
+
const normalized = target.toLowerCase();
|
|
9
|
+
return outcomes.find((outcome) => outcome.name.toLowerCase() === normalized);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function attachBinaryOutcomeGetters<
|
|
13
|
+
TOutcome extends { name: string },
|
|
14
|
+
TMarket extends { outcomes: Array<TOutcome> },
|
|
15
|
+
>(market: TMarket): TMarket & { readonly yes?: TOutcome; readonly no?: TOutcome } {
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(market, 'yes')) {
|
|
17
|
+
Object.defineProperty(market, 'yes', {
|
|
18
|
+
configurable: false,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
get: () => findOutcomeByName(market.outcomes, 'yes'),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!Object.prototype.hasOwnProperty.call(market, 'no')) {
|
|
25
|
+
Object.defineProperty(market, 'no', {
|
|
26
|
+
configurable: false,
|
|
27
|
+
enumerable: false,
|
|
28
|
+
get: () => findOutcomeByName(market.outcomes, 'no'),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return market as TMarket & { readonly yes?: TOutcome; readonly no?: TOutcome };
|
|
33
|
+
}
|
|
34
|
+
|
|
7
35
|
export class Markets extends APIResource {
|
|
8
36
|
/**
|
|
9
37
|
* Provide either `exchanges` (CSV) or `parsec_ids` (CSV). When `parsec_ids` is
|
|
@@ -13,7 +41,14 @@ export class Markets extends APIResource {
|
|
|
13
41
|
query: MarketListParams | null | undefined = {},
|
|
14
42
|
options?: RequestOptions,
|
|
15
43
|
): APIPromise<MarketListResponse> {
|
|
16
|
-
|
|
44
|
+
const request = this._client.get('/api/v1/markets', {
|
|
45
|
+
query,
|
|
46
|
+
...options,
|
|
47
|
+
}) as APIPromise<MarketListResponse>;
|
|
48
|
+
return request._thenUnwrap((data: MarketListResponse) => {
|
|
49
|
+
data.markets = data.markets.map((market) => attachBinaryOutcomeGetters(market));
|
|
50
|
+
return data;
|
|
51
|
+
});
|
|
17
52
|
}
|
|
18
53
|
}
|
|
19
54
|
|
|
@@ -52,6 +87,18 @@ export namespace MarketListResponse {
|
|
|
52
87
|
*/
|
|
53
88
|
outcomes: Array<Market.Outcome>;
|
|
54
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Convenience getter for binary markets: outcome where `name` is "Yes"
|
|
92
|
+
* (case-insensitive).
|
|
93
|
+
*/
|
|
94
|
+
readonly yes?: Market.Outcome;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Convenience getter for binary markets: outcome where `name` is "No"
|
|
98
|
+
* (case-insensitive).
|
|
99
|
+
*/
|
|
100
|
+
readonly no?: Market.Outcome;
|
|
101
|
+
|
|
55
102
|
/**
|
|
56
103
|
* Parsec group ID for cross-exchange event grouping.
|
|
57
104
|
*/
|
package/src/streaming.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface OrderbookSnapshot {
|
|
|
28
28
|
exchange: string;
|
|
29
29
|
tokenId: string;
|
|
30
30
|
marketId: string;
|
|
31
|
+
title?: string | undefined;
|
|
31
32
|
bids: StreamingOrderbookLevel[];
|
|
32
33
|
asks: StreamingOrderbookLevel[];
|
|
33
34
|
midPrice: number;
|
|
@@ -103,6 +104,7 @@ interface LocalBook {
|
|
|
103
104
|
exchange: string;
|
|
104
105
|
tokenId: string;
|
|
105
106
|
marketId: string;
|
|
107
|
+
title?: string | undefined;
|
|
106
108
|
bids: StreamingOrderbookLevel[];
|
|
107
109
|
asks: StreamingOrderbookLevel[];
|
|
108
110
|
tickSize?: number | undefined;
|
|
@@ -156,8 +158,12 @@ function subKey(parsecId: string, outcome?: string): string {
|
|
|
156
158
|
|
|
157
159
|
export class ParsecWebSocket {
|
|
158
160
|
private readonly apiKey: string;
|
|
161
|
+
private readonly terminalToken?: string | undefined;
|
|
159
162
|
private readonly wsUrl: string;
|
|
160
163
|
|
|
164
|
+
/** Customer ID returned by the server on successful auth. */
|
|
165
|
+
customerId?: string | undefined;
|
|
166
|
+
|
|
161
167
|
private ws: WebSocket | null = null;
|
|
162
168
|
private state: WsState = 'disconnected';
|
|
163
169
|
private intentionalClose = false;
|
|
@@ -171,9 +177,10 @@ export class ParsecWebSocket {
|
|
|
171
177
|
private readonly listeners = new Map<EventName, Set<(...args: any[]) => void>>();
|
|
172
178
|
|
|
173
179
|
/** @internal — called by ParsecAPI.ws(), not directly by users. */
|
|
174
|
-
constructor(apiKey: string, wsUrl: string) {
|
|
180
|
+
constructor(apiKey: string, wsUrl: string, terminalToken?: string) {
|
|
175
181
|
this.apiKey = apiKey;
|
|
176
182
|
this.wsUrl = wsUrl;
|
|
183
|
+
this.terminalToken = terminalToken;
|
|
177
184
|
}
|
|
178
185
|
|
|
179
186
|
// ── Event emitter ───────────────────────────────────────
|
|
@@ -290,6 +297,7 @@ export class ParsecWebSocket {
|
|
|
290
297
|
exchange: book.exchange,
|
|
291
298
|
tokenId: book.tokenId,
|
|
292
299
|
marketId: book.marketId,
|
|
300
|
+
title: book.title,
|
|
293
301
|
bids,
|
|
294
302
|
asks,
|
|
295
303
|
midPrice,
|
|
@@ -391,7 +399,11 @@ export class ParsecWebSocket {
|
|
|
391
399
|
|
|
392
400
|
this.ws.onopen = () => {
|
|
393
401
|
this.state = 'authenticating';
|
|
394
|
-
|
|
402
|
+
if (this.terminalToken) {
|
|
403
|
+
this.wsSend({ type: 'auth_terminal', token: this.terminalToken });
|
|
404
|
+
} else {
|
|
405
|
+
this.wsSend({ type: 'auth', api_key: this.apiKey });
|
|
406
|
+
}
|
|
395
407
|
};
|
|
396
408
|
|
|
397
409
|
this.ws.onmessage = (event: WebSocket.MessageEvent) => {
|
|
@@ -438,6 +450,7 @@ export class ParsecWebSocket {
|
|
|
438
450
|
case 'auth_ok': {
|
|
439
451
|
this.state = 'connected';
|
|
440
452
|
this.reconnectAttempt = 0;
|
|
453
|
+
this.customerId = msg.customer_id;
|
|
441
454
|
this.emit('connected');
|
|
442
455
|
|
|
443
456
|
// Clear one-shot connect() callbacks so reconnects don't re-resolve
|
|
@@ -563,6 +576,7 @@ export class ParsecWebSocket {
|
|
|
563
576
|
exchange,
|
|
564
577
|
tokenId,
|
|
565
578
|
marketId,
|
|
579
|
+
title: msg.title,
|
|
566
580
|
bids,
|
|
567
581
|
asks,
|
|
568
582
|
tickSize: msg.tick_size,
|
|
@@ -577,6 +591,7 @@ export class ParsecWebSocket {
|
|
|
577
591
|
exchange,
|
|
578
592
|
tokenId,
|
|
579
593
|
marketId,
|
|
594
|
+
title: msg.title,
|
|
580
595
|
bids: bids.map((l) => ({ ...l })),
|
|
581
596
|
asks: asks.map((l) => ({ ...l })),
|
|
582
597
|
midPrice,
|
|
@@ -656,6 +671,7 @@ export class ParsecWebSocket {
|
|
|
656
671
|
exchange: book.exchange,
|
|
657
672
|
tokenId: book.tokenId,
|
|
658
673
|
marketId: book.marketId,
|
|
674
|
+
title: book.title,
|
|
659
675
|
bids: book.bids.map((l) => ({ ...l })),
|
|
660
676
|
asks: book.asks.map((l) => ({ ...l })),
|
|
661
677
|
midPrice,
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.6.0'; // x-release-please-version
|
package/streaming.d.mts
CHANGED
|
@@ -21,6 +21,7 @@ export interface OrderbookSnapshot {
|
|
|
21
21
|
exchange: string;
|
|
22
22
|
tokenId: string;
|
|
23
23
|
marketId: string;
|
|
24
|
+
title?: string | undefined;
|
|
24
25
|
bids: StreamingOrderbookLevel[];
|
|
25
26
|
asks: StreamingOrderbookLevel[];
|
|
26
27
|
midPrice: number;
|
|
@@ -81,7 +82,10 @@ export interface ParsecWebSocketEventMap {
|
|
|
81
82
|
type EventName = keyof ParsecWebSocketEventMap;
|
|
82
83
|
export declare class ParsecWebSocket {
|
|
83
84
|
private readonly apiKey;
|
|
85
|
+
private readonly terminalToken?;
|
|
84
86
|
private readonly wsUrl;
|
|
87
|
+
/** Customer ID returned by the server on successful auth. */
|
|
88
|
+
customerId?: string | undefined;
|
|
85
89
|
private ws;
|
|
86
90
|
private state;
|
|
87
91
|
private intentionalClose;
|
|
@@ -93,7 +97,7 @@ export declare class ParsecWebSocket {
|
|
|
93
97
|
private readonly books;
|
|
94
98
|
private readonly listeners;
|
|
95
99
|
/** @internal — called by ParsecAPI.ws(), not directly by users. */
|
|
96
|
-
constructor(apiKey: string, wsUrl: string);
|
|
100
|
+
constructor(apiKey: string, wsUrl: string, terminalToken?: string);
|
|
97
101
|
on<E extends EventName>(event: E, listener: ParsecWebSocketEventMap[E]): this;
|
|
98
102
|
off<E extends EventName>(event: E, listener: ParsecWebSocketEventMap[E]): this;
|
|
99
103
|
private emit;
|
package/streaming.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.mts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,cAAc,CAAC;AAChE,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,CAAC;AAC5D,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,OAAO,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,uBAAuB,EAAE,CAAC;IAChC,IAAI,EAAE,uBAAuB,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAA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uD;IAEjF,mEAAmE;gBACvD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM;IAQjE,EAAE,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI;IAU7E,GAAG,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI;IAQ9E,OAAO,CAAC,IAAI;IAcN,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB9B,KAAK,IAAI,IAAI;IA6Bb;;;OAGG;IACH,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAS7B;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,MAAc,GAAG,iBAAiB,GAAG,SAAS;IA8BjF,SAAS,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,IAAI;IAwBnE,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,IAAI;IAoCrE,OAAO,CAAC,SAAS;IAkEjB,OAAO,CAAC,mBAAmB;IAiH3B,OAAO,CAAC,uBAAuB;IAuD/B,OAAO,CAAC,oBAAoB;IAkF5B,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,cAAc;IAUtB,2EAA2E;IAC3E,OAAO,CAAC,oBAAoB;IAa5B,OAAO,CAAC,MAAM;CAKf"}
|
package/streaming.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface OrderbookSnapshot {
|
|
|
21
21
|
exchange: string;
|
|
22
22
|
tokenId: string;
|
|
23
23
|
marketId: string;
|
|
24
|
+
title?: string | undefined;
|
|
24
25
|
bids: StreamingOrderbookLevel[];
|
|
25
26
|
asks: StreamingOrderbookLevel[];
|
|
26
27
|
midPrice: number;
|
|
@@ -81,7 +82,10 @@ export interface ParsecWebSocketEventMap {
|
|
|
81
82
|
type EventName = keyof ParsecWebSocketEventMap;
|
|
82
83
|
export declare class ParsecWebSocket {
|
|
83
84
|
private readonly apiKey;
|
|
85
|
+
private readonly terminalToken?;
|
|
84
86
|
private readonly wsUrl;
|
|
87
|
+
/** Customer ID returned by the server on successful auth. */
|
|
88
|
+
customerId?: string | undefined;
|
|
85
89
|
private ws;
|
|
86
90
|
private state;
|
|
87
91
|
private intentionalClose;
|
|
@@ -93,7 +97,7 @@ export declare class ParsecWebSocket {
|
|
|
93
97
|
private readonly books;
|
|
94
98
|
private readonly listeners;
|
|
95
99
|
/** @internal — called by ParsecAPI.ws(), not directly by users. */
|
|
96
|
-
constructor(apiKey: string, wsUrl: string);
|
|
100
|
+
constructor(apiKey: string, wsUrl: string, terminalToken?: string);
|
|
97
101
|
on<E extends EventName>(event: E, listener: ParsecWebSocketEventMap[E]): this;
|
|
98
102
|
off<E extends EventName>(event: E, listener: ParsecWebSocketEventMap[E]): this;
|
|
99
103
|
private emit;
|
package/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,cAAc,CAAC;AAChE,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,CAAC;AAC5D,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,OAAO,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAA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,GAAG,kBAAkB,EAAE,GAAG,IAAI;IAwBnE,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,IAAI;IAoCrE,OAAO,CAAC,SAAS;IAkEjB,OAAO,CAAC,mBAAmB;IAiH3B,OAAO,CAAC,uBAAuB;IAuD/B,OAAO,CAAC,oBAAoB;IAkF5B,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,cAAc;IAUtB,2EAA2E;IAC3E,OAAO,CAAC,oBAAoB;IAa5B,OAAO,CAAC,MAAM;CAKf"}
|
package/streaming.js
CHANGED
|
@@ -47,7 +47,7 @@ function subKey(parsecId, outcome) {
|
|
|
47
47
|
// ── WebSocket client ────────────────────────────────────────
|
|
48
48
|
class ParsecWebSocket {
|
|
49
49
|
/** @internal — called by ParsecAPI.ws(), not directly by users. */
|
|
50
|
-
constructor(apiKey, wsUrl) {
|
|
50
|
+
constructor(apiKey, wsUrl, terminalToken) {
|
|
51
51
|
this.ws = null;
|
|
52
52
|
this.state = 'disconnected';
|
|
53
53
|
this.intentionalClose = false;
|
|
@@ -60,6 +60,7 @@ class ParsecWebSocket {
|
|
|
60
60
|
this.listeners = new Map();
|
|
61
61
|
this.apiKey = apiKey;
|
|
62
62
|
this.wsUrl = wsUrl;
|
|
63
|
+
this.terminalToken = terminalToken;
|
|
63
64
|
}
|
|
64
65
|
// ── Event emitter ───────────────────────────────────────
|
|
65
66
|
on(event, listener) {
|
|
@@ -160,6 +161,7 @@ class ParsecWebSocket {
|
|
|
160
161
|
exchange: book.exchange,
|
|
161
162
|
tokenId: book.tokenId,
|
|
162
163
|
marketId: book.marketId,
|
|
164
|
+
title: book.title,
|
|
163
165
|
bids,
|
|
164
166
|
asks,
|
|
165
167
|
midPrice,
|
|
@@ -251,7 +253,12 @@ class ParsecWebSocket {
|
|
|
251
253
|
}
|
|
252
254
|
this.ws.onopen = () => {
|
|
253
255
|
this.state = 'authenticating';
|
|
254
|
-
|
|
256
|
+
if (this.terminalToken) {
|
|
257
|
+
this.wsSend({ type: 'auth_terminal', token: this.terminalToken });
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
this.wsSend({ type: 'auth', api_key: this.apiKey });
|
|
261
|
+
}
|
|
255
262
|
};
|
|
256
263
|
this.ws.onmessage = (event) => {
|
|
257
264
|
try {
|
|
@@ -287,6 +294,7 @@ class ParsecWebSocket {
|
|
|
287
294
|
case 'auth_ok': {
|
|
288
295
|
this.state = 'connected';
|
|
289
296
|
this.reconnectAttempt = 0;
|
|
297
|
+
this.customerId = msg.customer_id;
|
|
290
298
|
this.emit('connected');
|
|
291
299
|
// Clear one-shot connect() callbacks so reconnects don't re-resolve
|
|
292
300
|
if (onAuth) {
|
|
@@ -393,6 +401,7 @@ class ParsecWebSocket {
|
|
|
393
401
|
exchange,
|
|
394
402
|
tokenId,
|
|
395
403
|
marketId,
|
|
404
|
+
title: msg.title,
|
|
396
405
|
bids,
|
|
397
406
|
asks,
|
|
398
407
|
tickSize: msg.tick_size,
|
|
@@ -405,6 +414,7 @@ class ParsecWebSocket {
|
|
|
405
414
|
exchange,
|
|
406
415
|
tokenId,
|
|
407
416
|
marketId,
|
|
417
|
+
title: msg.title,
|
|
408
418
|
bids: bids.map((l) => ({ ...l })),
|
|
409
419
|
asks: asks.map((l) => ({ ...l })),
|
|
410
420
|
midPrice,
|
|
@@ -474,6 +484,7 @@ class ParsecWebSocket {
|
|
|
474
484
|
exchange: book.exchange,
|
|
475
485
|
tokenId: book.tokenId,
|
|
476
486
|
marketId: book.marketId,
|
|
487
|
+
title: book.title,
|
|
477
488
|
bids: book.bids.map((l) => ({ ...l })),
|
|
478
489
|
asks: book.asks.map((l) => ({ ...l })),
|
|
479
490
|
midPrice,
|