pmxtjs 2.41.7 → 2.42.2

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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Feed client — CCXT-compatible method names over /api/feeds/* endpoints.
3
+ *
4
+ * Usage:
5
+ * const feed = new FeedClient('chainlink', { pmxtApiKey: '...' });
6
+ * const ticker = await feed.fetchTicker('BTC/USD');
7
+ */
8
+ export interface Ticker {
9
+ symbol: string;
10
+ info: any;
11
+ timestamp: number | undefined;
12
+ datetime: string | undefined;
13
+ high: number | undefined;
14
+ low: number | undefined;
15
+ bid: number | undefined;
16
+ bidVolume: number | undefined;
17
+ ask: number | undefined;
18
+ askVolume: number | undefined;
19
+ vwap: number | undefined;
20
+ open: number | undefined;
21
+ close: number | undefined;
22
+ last: number | undefined;
23
+ previousClose: number | undefined;
24
+ change: number | undefined;
25
+ percentage: number | undefined;
26
+ average: number | undefined;
27
+ quoteVolume: number | undefined;
28
+ baseVolume: number | undefined;
29
+ indexPrice: number | undefined;
30
+ markPrice: number | undefined;
31
+ }
32
+ export type Tickers = Record<string, Ticker>;
33
+ export type OHLCV = [number, number, number, number, number, number];
34
+ export interface Market {
35
+ id: string;
36
+ symbol: string;
37
+ base: string;
38
+ quote: string;
39
+ active: boolean;
40
+ type: string;
41
+ info: any;
42
+ }
43
+ export interface OracleRound {
44
+ feed: string;
45
+ roundId: string;
46
+ answer: number;
47
+ startedAt: number;
48
+ updatedAt: number;
49
+ answeredInRound: string;
50
+ decimals: number;
51
+ description?: string;
52
+ }
53
+ export interface FeedClientOptions {
54
+ pmxtApiKey?: string;
55
+ baseUrl?: string;
56
+ }
57
+ export declare class FeedClient {
58
+ private readonly feedName;
59
+ private readonly baseUrl;
60
+ private readonly headers;
61
+ constructor(feedName: string, options?: FeedClientOptions);
62
+ loadMarkets(): Promise<Record<string, Market>>;
63
+ fetchTicker(symbol: string): Promise<Ticker>;
64
+ fetchTickers(symbols?: string[]): Promise<Tickers>;
65
+ fetchOHLCV(symbol: string, timeframe?: string, since?: number, limit?: number): Promise<OHLCV[]>;
66
+ fetchOracleRound(feed: string): Promise<OracleRound>;
67
+ fetchOracleHistory(feed: string, limit?: number): Promise<OracleRound[]>;
68
+ fetchHistoricalPrices(symbol: string, opts?: {
69
+ fromTimestamp?: number;
70
+ untilTimestamp?: number;
71
+ maxSize?: number;
72
+ order?: 'asc' | 'desc';
73
+ }): Promise<Ticker[]>;
74
+ private get;
75
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Feed client — CCXT-compatible method names over /api/feeds/* endpoints.
3
+ *
4
+ * Usage:
5
+ * const feed = new FeedClient('chainlink', { pmxtApiKey: '...' });
6
+ * const ticker = await feed.fetchTicker('BTC/USD');
7
+ */
8
+ import { resolvePmxtBaseUrl } from "./constants.js";
9
+ import { PmxtError } from "./errors.js";
10
+ export class FeedClient {
11
+ feedName;
12
+ baseUrl;
13
+ headers;
14
+ constructor(feedName, options = {}) {
15
+ this.feedName = feedName;
16
+ const resolved = resolvePmxtBaseUrl({
17
+ baseUrl: options.baseUrl,
18
+ pmxtApiKey: options.pmxtApiKey,
19
+ });
20
+ this.baseUrl = resolved.baseUrl;
21
+ this.headers = {
22
+ ...(resolved.pmxtApiKey ? { 'Authorization': `Bearer ${resolved.pmxtApiKey}` } : {}),
23
+ };
24
+ }
25
+ async loadMarkets() {
26
+ return this.get('loadMarkets', {});
27
+ }
28
+ async fetchTicker(symbol) {
29
+ return this.get('fetchTicker', { symbol });
30
+ }
31
+ async fetchTickers(symbols) {
32
+ const params = {};
33
+ if (symbols)
34
+ params.symbols = symbols.join(',');
35
+ return this.get('fetchTickers', params);
36
+ }
37
+ async fetchOHLCV(symbol, timeframe, since, limit) {
38
+ return this.get('fetchOHLCV', { symbol, timeframe, since, limit });
39
+ }
40
+ async fetchOracleRound(feed) {
41
+ return this.get('fetchOracleRound', { feed });
42
+ }
43
+ async fetchOracleHistory(feed, limit) {
44
+ const params = { feed };
45
+ if (limit !== undefined)
46
+ params.limit = limit;
47
+ return this.get('fetchOracleHistory', params);
48
+ }
49
+ async fetchHistoricalPrices(symbol, opts) {
50
+ return this.get('fetchHistoricalPrices', { symbol, ...opts });
51
+ }
52
+ async get(method, params) {
53
+ const qs = Object.entries(params)
54
+ .filter(([, v]) => v !== undefined && v !== null)
55
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
56
+ .join('&');
57
+ const url = `${this.baseUrl}/api/feeds/${this.feedName}/${method}${qs ? '?' + qs : ''}`;
58
+ const response = await fetch(url, { headers: this.headers });
59
+ if (!response.ok) {
60
+ const body = await response.json().catch(() => ({}));
61
+ throw new PmxtError(body.error || response.statusText);
62
+ }
63
+ const json = await response.json();
64
+ if (!json.success) {
65
+ throw new PmxtError(json.error || 'Unknown feed error');
66
+ }
67
+ return json.data;
68
+ }
69
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Feed client — CCXT-compatible method names over /api/feeds/* endpoints.
3
+ *
4
+ * Usage:
5
+ * const feed = new FeedClient('chainlink', { pmxtApiKey: '...' });
6
+ * const ticker = await feed.fetchTicker('BTC/USD');
7
+ */
8
+ export interface Ticker {
9
+ symbol: string;
10
+ info: any;
11
+ timestamp: number | undefined;
12
+ datetime: string | undefined;
13
+ high: number | undefined;
14
+ low: number | undefined;
15
+ bid: number | undefined;
16
+ bidVolume: number | undefined;
17
+ ask: number | undefined;
18
+ askVolume: number | undefined;
19
+ vwap: number | undefined;
20
+ open: number | undefined;
21
+ close: number | undefined;
22
+ last: number | undefined;
23
+ previousClose: number | undefined;
24
+ change: number | undefined;
25
+ percentage: number | undefined;
26
+ average: number | undefined;
27
+ quoteVolume: number | undefined;
28
+ baseVolume: number | undefined;
29
+ indexPrice: number | undefined;
30
+ markPrice: number | undefined;
31
+ }
32
+ export type Tickers = Record<string, Ticker>;
33
+ export type OHLCV = [number, number, number, number, number, number];
34
+ export interface Market {
35
+ id: string;
36
+ symbol: string;
37
+ base: string;
38
+ quote: string;
39
+ active: boolean;
40
+ type: string;
41
+ info: any;
42
+ }
43
+ export interface OracleRound {
44
+ feed: string;
45
+ roundId: string;
46
+ answer: number;
47
+ startedAt: number;
48
+ updatedAt: number;
49
+ answeredInRound: string;
50
+ decimals: number;
51
+ description?: string;
52
+ }
53
+ export interface FeedClientOptions {
54
+ pmxtApiKey?: string;
55
+ baseUrl?: string;
56
+ }
57
+ export declare class FeedClient {
58
+ private readonly feedName;
59
+ private readonly baseUrl;
60
+ private readonly headers;
61
+ constructor(feedName: string, options?: FeedClientOptions);
62
+ loadMarkets(): Promise<Record<string, Market>>;
63
+ fetchTicker(symbol: string): Promise<Ticker>;
64
+ fetchTickers(symbols?: string[]): Promise<Tickers>;
65
+ fetchOHLCV(symbol: string, timeframe?: string, since?: number, limit?: number): Promise<OHLCV[]>;
66
+ fetchOracleRound(feed: string): Promise<OracleRound>;
67
+ fetchOracleHistory(feed: string, limit?: number): Promise<OracleRound[]>;
68
+ fetchHistoricalPrices(symbol: string, opts?: {
69
+ fromTimestamp?: number;
70
+ untilTimestamp?: number;
71
+ maxSize?: number;
72
+ order?: 'asc' | 'desc';
73
+ }): Promise<Ticker[]>;
74
+ private get;
75
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Feed client — CCXT-compatible method names over /api/feeds/* endpoints.
4
+ *
5
+ * Usage:
6
+ * const feed = new FeedClient('chainlink', { pmxtApiKey: '...' });
7
+ * const ticker = await feed.fetchTicker('BTC/USD');
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FeedClient = void 0;
11
+ const constants_js_1 = require("./constants.js");
12
+ const errors_js_1 = require("./errors.js");
13
+ class FeedClient {
14
+ feedName;
15
+ baseUrl;
16
+ headers;
17
+ constructor(feedName, options = {}) {
18
+ this.feedName = feedName;
19
+ const resolved = (0, constants_js_1.resolvePmxtBaseUrl)({
20
+ baseUrl: options.baseUrl,
21
+ pmxtApiKey: options.pmxtApiKey,
22
+ });
23
+ this.baseUrl = resolved.baseUrl;
24
+ this.headers = {
25
+ ...(resolved.pmxtApiKey ? { 'Authorization': `Bearer ${resolved.pmxtApiKey}` } : {}),
26
+ };
27
+ }
28
+ async loadMarkets() {
29
+ return this.get('loadMarkets', {});
30
+ }
31
+ async fetchTicker(symbol) {
32
+ return this.get('fetchTicker', { symbol });
33
+ }
34
+ async fetchTickers(symbols) {
35
+ const params = {};
36
+ if (symbols)
37
+ params.symbols = symbols.join(',');
38
+ return this.get('fetchTickers', params);
39
+ }
40
+ async fetchOHLCV(symbol, timeframe, since, limit) {
41
+ return this.get('fetchOHLCV', { symbol, timeframe, since, limit });
42
+ }
43
+ async fetchOracleRound(feed) {
44
+ return this.get('fetchOracleRound', { feed });
45
+ }
46
+ async fetchOracleHistory(feed, limit) {
47
+ const params = { feed };
48
+ if (limit !== undefined)
49
+ params.limit = limit;
50
+ return this.get('fetchOracleHistory', params);
51
+ }
52
+ async fetchHistoricalPrices(symbol, opts) {
53
+ return this.get('fetchHistoricalPrices', { symbol, ...opts });
54
+ }
55
+ async get(method, params) {
56
+ const qs = Object.entries(params)
57
+ .filter(([, v]) => v !== undefined && v !== null)
58
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
59
+ .join('&');
60
+ const url = `${this.baseUrl}/api/feeds/${this.feedName}/${method}${qs ? '?' + qs : ''}`;
61
+ const response = await fetch(url, { headers: this.headers });
62
+ if (!response.ok) {
63
+ const body = await response.json().catch(() => ({}));
64
+ throw new errors_js_1.PmxtError(body.error || response.statusText);
65
+ }
66
+ const json = await response.json();
67
+ if (!json.success) {
68
+ throw new errors_js_1.PmxtError(json.error || 'Unknown feed error');
69
+ }
70
+ return json.data;
71
+ }
72
+ }
73
+ exports.FeedClient = FeedClient;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.41.7",
3
+ "version": "2.42.2",
4
4
  "description": "OpenAPI client for pmxtjs",
5
5
  "author": "OpenAPI-Generator",
6
6
  "repository": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.41.7",
3
+ "version": "2.42.2",
4
4
  "description": "Unified prediction market data API - The ccxt for prediction markets",
5
5
  "author": "PMXT Contributors",
6
6
  "repository": {
@@ -43,7 +43,7 @@
43
43
  "unified"
44
44
  ],
45
45
  "dependencies": {
46
- "pmxt-core": "2.41.7",
46
+ "pmxt-core": "2.42.2",
47
47
  "ws": "^8.18.0"
48
48
  },
49
49
  "devDependencies": {
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Feed client — CCXT-compatible method names over /api/feeds/* endpoints.
3
+ *
4
+ * Usage:
5
+ * const feed = new FeedClient('chainlink', { pmxtApiKey: '...' });
6
+ * const ticker = await feed.fetchTicker('BTC/USD');
7
+ */
8
+
9
+ import { resolvePmxtBaseUrl } from "./constants.js";
10
+ import { PmxtError } from "./errors.js";
11
+
12
+ export interface Ticker {
13
+ symbol: string;
14
+ info: any;
15
+ timestamp: number | undefined;
16
+ datetime: string | undefined;
17
+ high: number | undefined;
18
+ low: number | undefined;
19
+ bid: number | undefined;
20
+ bidVolume: number | undefined;
21
+ ask: number | undefined;
22
+ askVolume: number | undefined;
23
+ vwap: number | undefined;
24
+ open: number | undefined;
25
+ close: number | undefined;
26
+ last: number | undefined;
27
+ previousClose: number | undefined;
28
+ change: number | undefined;
29
+ percentage: number | undefined;
30
+ average: number | undefined;
31
+ quoteVolume: number | undefined;
32
+ baseVolume: number | undefined;
33
+ indexPrice: number | undefined;
34
+ markPrice: number | undefined;
35
+ }
36
+
37
+ export type Tickers = Record<string, Ticker>;
38
+ export type OHLCV = [number, number, number, number, number, number];
39
+
40
+ export interface Market {
41
+ id: string;
42
+ symbol: string;
43
+ base: string;
44
+ quote: string;
45
+ active: boolean;
46
+ type: string;
47
+ info: any;
48
+ }
49
+
50
+ export interface OracleRound {
51
+ feed: string;
52
+ roundId: string;
53
+ answer: number;
54
+ startedAt: number;
55
+ updatedAt: number;
56
+ answeredInRound: string;
57
+ decimals: number;
58
+ description?: string;
59
+ }
60
+
61
+ export interface FeedClientOptions {
62
+ pmxtApiKey?: string;
63
+ baseUrl?: string;
64
+ }
65
+
66
+ export class FeedClient {
67
+ private readonly feedName: string;
68
+ private readonly baseUrl: string;
69
+ private readonly headers: Record<string, string>;
70
+
71
+ constructor(feedName: string, options: FeedClientOptions = {}) {
72
+ this.feedName = feedName;
73
+ const resolved = resolvePmxtBaseUrl({
74
+ baseUrl: options.baseUrl,
75
+ pmxtApiKey: options.pmxtApiKey,
76
+ });
77
+ this.baseUrl = resolved.baseUrl;
78
+ this.headers = {
79
+ ...(resolved.pmxtApiKey ? { 'Authorization': `Bearer ${resolved.pmxtApiKey}` } : {}),
80
+ };
81
+ }
82
+
83
+ async loadMarkets(): Promise<Record<string, Market>> {
84
+ return this.get<Record<string, Market>>('loadMarkets', {});
85
+ }
86
+
87
+ async fetchTicker(symbol: string): Promise<Ticker> {
88
+ return this.get<Ticker>('fetchTicker', { symbol });
89
+ }
90
+
91
+ async fetchTickers(symbols?: string[]): Promise<Tickers> {
92
+ const params: Record<string, unknown> = {};
93
+ if (symbols) params.symbols = symbols.join(',');
94
+ return this.get<Tickers>('fetchTickers', params);
95
+ }
96
+
97
+ async fetchOHLCV(symbol: string, timeframe?: string, since?: number, limit?: number): Promise<OHLCV[]> {
98
+ return this.get<OHLCV[]>('fetchOHLCV', { symbol, timeframe, since, limit });
99
+ }
100
+
101
+ async fetchOracleRound(feed: string): Promise<OracleRound> {
102
+ return this.get<OracleRound>('fetchOracleRound', { feed });
103
+ }
104
+
105
+ async fetchOracleHistory(feed: string, limit?: number): Promise<OracleRound[]> {
106
+ const params: Record<string, unknown> = { feed };
107
+ if (limit !== undefined) params.limit = limit;
108
+ return this.get<OracleRound[]>('fetchOracleHistory', params);
109
+ }
110
+
111
+ async fetchHistoricalPrices(symbol: string, opts?: {
112
+ fromTimestamp?: number;
113
+ untilTimestamp?: number;
114
+ maxSize?: number;
115
+ order?: 'asc' | 'desc';
116
+ }): Promise<Ticker[]> {
117
+ return this.get<Ticker[]>('fetchHistoricalPrices', { symbol, ...opts });
118
+ }
119
+
120
+ private async get<T>(method: string, params: Record<string, unknown>): Promise<T> {
121
+ const qs = Object.entries(params)
122
+ .filter(([, v]) => v !== undefined && v !== null)
123
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
124
+ .join('&');
125
+
126
+ const url = `${this.baseUrl}/api/feeds/${this.feedName}/${method}${qs ? '?' + qs : ''}`;
127
+
128
+ const response = await fetch(url, { headers: this.headers });
129
+
130
+ if (!response.ok) {
131
+ const body = await response.json().catch(() => ({}));
132
+ throw new PmxtError(body.error || response.statusText);
133
+ }
134
+
135
+ const json = await response.json() as { success: boolean; data: T; error?: string };
136
+ if (!json.success) {
137
+ throw new PmxtError(json.error || 'Unknown feed error');
138
+ }
139
+ return json.data;
140
+ }
141
+ }