pmxtjs 0.1.0 → 0.1.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.
Files changed (60) hide show
  1. package/{src/BaseExchange.ts → dist/BaseExchange.d.ts} +4 -22
  2. package/dist/BaseExchange.js +30 -0
  3. package/dist/exchanges/Kalshi.d.ts +20 -0
  4. package/{src/exchanges/Kalshi.ts → dist/exchanges/Kalshi.js} +75 -114
  5. package/dist/exchanges/Polymarket.d.ts +38 -0
  6. package/{src/exchanges/Polymarket.ts → dist/exchanges/Polymarket.js} +105 -146
  7. package/{src/index.ts → dist/index.d.ts} +0 -1
  8. package/dist/index.js +20 -0
  9. package/{src/types.ts → dist/types.d.ts} +3 -17
  10. package/dist/types.js +5 -0
  11. package/package.json +9 -1
  12. package/readme.md +62 -0
  13. package/coverage/clover.xml +0 -334
  14. package/coverage/coverage-final.json +0 -4
  15. package/coverage/lcov-report/base.css +0 -224
  16. package/coverage/lcov-report/block-navigation.js +0 -87
  17. package/coverage/lcov-report/favicon.png +0 -0
  18. package/coverage/lcov-report/index.html +0 -131
  19. package/coverage/lcov-report/pmxt/BaseExchange.ts.html +0 -256
  20. package/coverage/lcov-report/pmxt/exchanges/Kalshi.ts.html +0 -1132
  21. package/coverage/lcov-report/pmxt/exchanges/Polymarket.ts.html +0 -1456
  22. package/coverage/lcov-report/pmxt/exchanges/index.html +0 -131
  23. package/coverage/lcov-report/pmxt/index.html +0 -116
  24. package/coverage/lcov-report/prettify.css +0 -1
  25. package/coverage/lcov-report/prettify.js +0 -2
  26. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  27. package/coverage/lcov-report/sorter.js +0 -210
  28. package/coverage/lcov-report/src/BaseExchange.ts.html +0 -256
  29. package/coverage/lcov-report/src/exchanges/Kalshi.ts.html +0 -1132
  30. package/coverage/lcov-report/src/exchanges/Polymarket.ts.html +0 -1456
  31. package/coverage/lcov-report/src/exchanges/index.html +0 -131
  32. package/coverage/lcov-report/src/index.html +0 -116
  33. package/coverage/lcov.info +0 -766
  34. package/examples/get_event_prices.ts +0 -37
  35. package/examples/historical_prices.ts +0 -117
  36. package/examples/orderbook.ts +0 -102
  37. package/examples/recent_trades.ts +0 -29
  38. package/examples/search_events.ts +0 -68
  39. package/examples/search_market.ts +0 -29
  40. package/jest.config.js +0 -11
  41. package/pmxt-0.1.0.tgz +0 -0
  42. package/test/exchanges/kalshi/ApiErrors.test.ts +0 -132
  43. package/test/exchanges/kalshi/EmptyResponse.test.ts +0 -44
  44. package/test/exchanges/kalshi/FetchAndNormalizeMarkets.test.ts +0 -56
  45. package/test/exchanges/kalshi/LiveApi.integration.test.ts +0 -40
  46. package/test/exchanges/kalshi/MarketHistory.test.ts +0 -185
  47. package/test/exchanges/kalshi/OrderBook.test.ts +0 -149
  48. package/test/exchanges/kalshi/SearchMarkets.test.ts +0 -174
  49. package/test/exchanges/kalshi/VolumeFallback.test.ts +0 -44
  50. package/test/exchanges/polymarket/DataValidation.test.ts +0 -271
  51. package/test/exchanges/polymarket/ErrorHandling.test.ts +0 -34
  52. package/test/exchanges/polymarket/FetchAndNormalizeMarkets.test.ts +0 -68
  53. package/test/exchanges/polymarket/GetMarketsBySlug.test.ts +0 -268
  54. package/test/exchanges/polymarket/LiveApi.integration.test.ts +0 -44
  55. package/test/exchanges/polymarket/MarketHistory.test.ts +0 -207
  56. package/test/exchanges/polymarket/OrderBook.test.ts +0 -167
  57. package/test/exchanges/polymarket/RequestParameters.test.ts +0 -39
  58. package/test/exchanges/polymarket/SearchMarkets.test.ts +0 -176
  59. package/test/exchanges/polymarket/TradeHistory.test.ts +0 -248
  60. package/tsconfig.json +0 -12
@@ -1,248 +0,0 @@
1
- import axios from 'axios';
2
- import { PolymarketExchange } from '../../../src/exchanges/Polymarket';
3
-
4
- /**
5
- * Polymarket getTradeHistory() Test
6
- *
7
- * What: Tests fetching raw trade history data from CLOB API.
8
- * Why: Trade history is CRITICAL for market analysis and price discovery.
9
- * How: Mocks CLOB trades API responses and verifies data transformation.
10
- */
11
-
12
- jest.mock('axios');
13
- const mockedAxios = axios as jest.Mocked<typeof axios>;
14
-
15
- describe('PolymarketExchange - getTradeHistory', () => {
16
- let exchange: PolymarketExchange;
17
-
18
- beforeEach(() => {
19
- exchange = new PolymarketExchange();
20
- jest.clearAllMocks();
21
- });
22
-
23
- it('should fetch and parse trade history', async () => {
24
- mockedAxios.get.mockResolvedValue({
25
- data: [
26
- {
27
- id: 'trade-1',
28
- timestamp: 1704067200,
29
- price: '0.52',
30
- size: '100',
31
- side: 'BUY'
32
- },
33
- {
34
- id: 'trade-2',
35
- timestamp: 1704067260,
36
- price: '0.53',
37
- size: '250',
38
- side: 'SELL'
39
- }
40
- ]
41
- });
42
-
43
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
44
-
45
- expect(trades.length).toBe(2);
46
- expect(trades[0].id).toBe('trade-1');
47
- expect(trades[0].price).toBe(0.52);
48
- expect(trades[0].amount).toBe(100);
49
- expect(trades[0].side).toBe('buy');
50
- });
51
-
52
- it('should convert timestamps to milliseconds', async () => {
53
- mockedAxios.get.mockResolvedValue({
54
- data: [{
55
- id: 'trade-1',
56
- timestamp: 1704067200,
57
- price: '0.50',
58
- size: '100',
59
- side: 'BUY'
60
- }]
61
- });
62
-
63
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
64
-
65
- expect(trades[0].timestamp).toBe(1704067200 * 1000);
66
- });
67
-
68
- it('should handle BUY and SELL sides correctly', async () => {
69
- mockedAxios.get.mockResolvedValue({
70
- data: [
71
- { id: 'trade-1', timestamp: 1704067200, price: '0.50', size: '100', side: 'BUY' },
72
- { id: 'trade-2', timestamp: 1704067260, price: '0.51', size: '150', side: 'SELL' }
73
- ]
74
- });
75
-
76
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
77
-
78
- expect(trades[0].side).toBe('buy');
79
- expect(trades[1].side).toBe('sell');
80
- });
81
-
82
- it('should handle unknown side values', async () => {
83
- mockedAxios.get.mockResolvedValue({
84
- data: [{
85
- id: 'trade-1',
86
- timestamp: 1704067200,
87
- price: '0.50',
88
- size: '100',
89
- side: 'UNKNOWN'
90
- }]
91
- });
92
-
93
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
94
-
95
- expect(trades[0].side).toBe('unknown');
96
- });
97
-
98
- it('should handle missing trade ID with fallback', async () => {
99
- mockedAxios.get.mockResolvedValue({
100
- data: [{
101
- timestamp: 1704067200,
102
- price: '0.50',
103
- size: '100',
104
- side: 'BUY'
105
- // Missing id
106
- }]
107
- });
108
-
109
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
110
-
111
- expect(trades[0].id).toBe('1704067200-0.50');
112
- });
113
-
114
- it('should handle alternative amount field names', async () => {
115
- mockedAxios.get.mockResolvedValue({
116
- data: [{
117
- id: 'trade-1',
118
- timestamp: 1704067200,
119
- price: '0.50',
120
- amount: '200', // Alternative field
121
- side: 'BUY'
122
- }]
123
- });
124
-
125
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
126
-
127
- expect(trades[0].amount).toBe(200);
128
- });
129
-
130
- it('should respect limit parameter', async () => {
131
- const mockTrades = Array.from({ length: 100 }, (_, i) => ({
132
- id: `trade-${i}`,
133
- timestamp: 1704067200 + i,
134
- price: '0.50',
135
- size: '100',
136
- side: 'BUY'
137
- }));
138
-
139
- mockedAxios.get.mockResolvedValue({ data: mockTrades });
140
-
141
- const trades = await exchange.getTradeHistory('token123456789', {
142
- resolution: '1h',
143
- limit: 20
144
- });
145
-
146
- expect(trades.length).toBe(20);
147
- });
148
-
149
- it('should include start timestamp in query params', async () => {
150
- mockedAxios.get.mockResolvedValue({ data: [] });
151
-
152
- const start = new Date('2025-01-01T00:00:00Z');
153
- await exchange.getTradeHistory('token123456789', {
154
- resolution: '1h',
155
- start
156
- });
157
-
158
- expect(mockedAxios.get).toHaveBeenCalledWith(
159
- expect.any(String),
160
- expect.objectContaining({
161
- params: expect.objectContaining({
162
- after: Math.floor(start.getTime() / 1000)
163
- })
164
- })
165
- );
166
- });
167
-
168
- it('should include end timestamp in query params', async () => {
169
- mockedAxios.get.mockResolvedValue({ data: [] });
170
-
171
- const end = new Date('2025-01-31T00:00:00Z');
172
- await exchange.getTradeHistory('token123456789', {
173
- resolution: '1h',
174
- end
175
- });
176
-
177
- expect(mockedAxios.get).toHaveBeenCalledWith(
178
- expect.any(String),
179
- expect.objectContaining({
180
- params: expect.objectContaining({
181
- before: Math.floor(end.getTime() / 1000)
182
- })
183
- })
184
- );
185
- });
186
-
187
- it('should handle empty trades array', async () => {
188
- mockedAxios.get.mockResolvedValue({ data: [] });
189
-
190
- const trades = await exchange.getTradeHistory('token123456789', { resolution: '1h' });
191
-
192
- expect(trades).toEqual([]);
193
- });
194
-
195
- it('should throw error for invalid token ID format', async () => {
196
- await expect(exchange.getTradeHistory('123', { resolution: '1h' }))
197
- .rejects
198
- .toThrow(/Invalid ID/i);
199
- });
200
-
201
- it('should handle API errors with detailed messages', async () => {
202
- const error = {
203
- response: {
204
- status: 401,
205
- data: { error: 'Authentication required' }
206
- },
207
- isAxiosError: true
208
- };
209
- mockedAxios.get.mockRejectedValue(error);
210
- // @ts-expect-error - Mock type mismatch is expected in tests
211
- mockedAxios.isAxiosError = jest.fn().mockReturnValue(true);
212
-
213
- await expect(exchange.getTradeHistory('token123456789', { resolution: '1h' }))
214
- .rejects
215
- .toThrow(/Trades API Error/i);
216
- });
217
-
218
- it('should handle unexpected errors', async () => {
219
- mockedAxios.get.mockRejectedValue(new Error('Network failure'));
220
- const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
221
-
222
- await expect(exchange.getTradeHistory('token123456789', { resolution: '1h' }))
223
- .rejects
224
- .toThrow('Network failure');
225
-
226
- expect(consoleSpy).toHaveBeenCalled();
227
- consoleSpy.mockRestore();
228
- });
229
-
230
- it('should return most recent trades when limit is applied', async () => {
231
- const mockTrades = [
232
- { id: 'trade-1', timestamp: 1704067200, price: '0.50', size: '100', side: 'BUY' },
233
- { id: 'trade-2', timestamp: 1704067260, price: '0.51', size: '100', side: 'BUY' },
234
- { id: 'trade-3', timestamp: 1704067320, price: '0.52', size: '100', side: 'BUY' }
235
- ];
236
-
237
- mockedAxios.get.mockResolvedValue({ data: mockTrades });
238
-
239
- const trades = await exchange.getTradeHistory('token123456789', {
240
- resolution: '1h',
241
- limit: 2
242
- });
243
-
244
- expect(trades.length).toBe(2);
245
- expect(trades[0].id).toBe('trade-2'); // Most recent 2
246
- expect(trades[1].id).toBe('trade-3');
247
- });
248
- });
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "skipLibCheck": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "outDir": "./dist"
10
- },
11
- "include": ["src/**/*"]
12
- }