pmxt-core 2.8.0 → 2.9.1
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/dist/BaseExchange.d.ts +48 -0
- package/dist/BaseExchange.js +116 -0
- package/dist/exchanges/kalshi/api.d.ts +1763 -0
- package/dist/exchanges/kalshi/api.js +2554 -0
- package/dist/exchanges/kalshi/fetchEvents.d.ts +3 -2
- package/dist/exchanges/kalshi/fetchEvents.js +9 -16
- package/dist/exchanges/kalshi/fetchMarkets.d.ts +3 -2
- package/dist/exchanges/kalshi/fetchMarkets.js +24 -32
- package/dist/exchanges/kalshi/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/kalshi/fetchOHLCV.js +9 -11
- package/dist/exchanges/kalshi/index.d.ts +2 -1
- package/dist/exchanges/kalshi/index.js +161 -183
- package/dist/exchanges/kalshi/kalshi.test.js +51 -31
- package/dist/exchanges/limitless/api.d.ts +555 -0
- package/dist/exchanges/limitless/api.js +863 -0
- package/dist/exchanges/limitless/fetchEvents.d.ts +1 -2
- package/dist/exchanges/limitless/fetchEvents.js +9 -15
- package/dist/exchanges/limitless/fetchMarkets.d.ts +1 -2
- package/dist/exchanges/limitless/fetchMarkets.js +9 -16
- package/dist/exchanges/limitless/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/limitless/fetchOHLCV.js +2 -11
- package/dist/exchanges/limitless/fetchOrderBook.d.ts +1 -2
- package/dist/exchanges/limitless/fetchOrderBook.js +2 -11
- package/dist/exchanges/limitless/index.d.ts +1 -0
- package/dist/exchanges/limitless/index.js +28 -7
- package/dist/exchanges/limitless/websocket.d.ts +2 -1
- package/dist/exchanges/limitless/websocket.js +6 -4
- package/dist/exchanges/myriad/api.d.ts +294 -0
- package/dist/exchanges/myriad/api.js +690 -0
- package/dist/exchanges/myriad/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/myriad/fetchOHLCV.js +3 -11
- package/dist/exchanges/myriad/fetchOrderBook.d.ts +1 -2
- package/dist/exchanges/myriad/fetchOrderBook.js +3 -11
- package/dist/exchanges/myriad/index.d.ts +2 -0
- package/dist/exchanges/myriad/index.js +116 -103
- package/dist/exchanges/myriad/websocket.d.ts +2 -2
- package/dist/exchanges/myriad/websocket.js +28 -6
- package/dist/exchanges/polymarket/api-clob.d.ts +346 -0
- package/dist/exchanges/polymarket/api-clob.js +517 -0
- package/dist/exchanges/polymarket/api-data.d.ts +789 -0
- package/dist/exchanges/polymarket/api-data.js +860 -0
- package/dist/exchanges/polymarket/api-gamma.d.ts +556 -0
- package/dist/exchanges/polymarket/api-gamma.js +1161 -0
- package/dist/exchanges/polymarket/fetchEvents.js +0 -68
- package/dist/exchanges/polymarket/fetchOHLCV.d.ts +1 -2
- package/dist/exchanges/polymarket/fetchOHLCV.js +4 -10
- package/dist/exchanges/polymarket/fetchOrderBook.d.ts +1 -2
- package/dist/exchanges/polymarket/fetchOrderBook.js +2 -10
- package/dist/exchanges/polymarket/fetchTrades.d.ts +1 -2
- package/dist/exchanges/polymarket/fetchTrades.js +2 -11
- package/dist/exchanges/polymarket/index.d.ts +10 -0
- package/dist/exchanges/polymarket/index.js +110 -5
- package/dist/exchanges/probable/api.d.ts +605 -0
- package/dist/exchanges/probable/api.js +887 -0
- package/dist/exchanges/probable/fetchEvents.d.ts +3 -3
- package/dist/exchanges/probable/fetchEvents.js +28 -25
- package/dist/exchanges/probable/fetchMarkets.d.ts +1 -1
- package/dist/exchanges/probable/fetchMarkets.js +25 -21
- package/dist/exchanges/probable/index.d.ts +1 -0
- package/dist/exchanges/probable/index.js +92 -10
- package/dist/exchanges/probable/utils.d.ts +1 -2
- package/dist/exchanges/probable/utils.js +4 -11
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/utils/openapi.d.ts +9 -0
- package/dist/utils/openapi.js +59 -0
- package/package.json +4 -3
- package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -3
- package/dist/exchanges/kalshi/fetchOrderBook.js +0 -59
- package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -4
- package/dist/exchanges/kalshi/fetchTrades.js +0 -31
- package/dist/exchanges/limitless/fetchPositions.d.ts +0 -2
- package/dist/exchanges/limitless/fetchPositions.js +0 -34
- package/dist/exchanges/myriad/fetchTrades.d.ts +0 -4
- package/dist/exchanges/myriad/fetchTrades.js +0 -62
- package/dist/exchanges/polymarket/fetchPositions.d.ts +0 -2
- package/dist/exchanges/polymarket/fetchPositions.js +0 -34
- package/dist/exchanges/probable/fetchOHLCV.d.ts +0 -4
- package/dist/exchanges/probable/fetchOHLCV.js +0 -83
- package/dist/exchanges/probable/fetchOrderBook.d.ts +0 -3
- package/dist/exchanges/probable/fetchOrderBook.js +0 -37
- package/dist/exchanges/probable/fetchPositions.d.ts +0 -2
- package/dist/exchanges/probable/fetchPositions.js +0 -33
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchOrderBook = fetchOrderBook;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const validation_1 = require("../../utils/validation");
|
|
9
|
-
const errors_1 = require("./errors");
|
|
10
|
-
async function fetchOrderBook(id, http = axios_1.default) {
|
|
11
|
-
(0, validation_1.validateIdFormat)(id, 'OrderBook');
|
|
12
|
-
try {
|
|
13
|
-
// Check if this is a NO outcome request
|
|
14
|
-
const isNoOutcome = id.endsWith('-NO');
|
|
15
|
-
const ticker = id.replace(/-NO$/, '');
|
|
16
|
-
const url = `https://api.elections.kalshi.com/trade-api/v2/markets/${ticker}/orderbook`;
|
|
17
|
-
const response = await http.get(url);
|
|
18
|
-
const data = response.data.orderbook;
|
|
19
|
-
// Structure: { yes: [[price, qty], ...], no: [[price, qty], ...] }
|
|
20
|
-
// Kalshi returns bids at their actual prices (not inverted)
|
|
21
|
-
// - yes: bids for buying YES at price X
|
|
22
|
-
// - no: bids for buying NO at price X
|
|
23
|
-
let bids;
|
|
24
|
-
let asks;
|
|
25
|
-
if (isNoOutcome) {
|
|
26
|
-
// NO outcome order book:
|
|
27
|
-
// - Bids: people buying NO (use data.no directly)
|
|
28
|
-
// - Asks: people selling NO = people buying YES (invert data.yes)
|
|
29
|
-
bids = (data.no || []).map((level) => ({
|
|
30
|
-
price: level[0] / 100,
|
|
31
|
-
size: level[1]
|
|
32
|
-
}));
|
|
33
|
-
asks = (data.yes || []).map((level) => ({
|
|
34
|
-
price: 1 - (level[0] / 100), // Invert YES price to get NO ask price
|
|
35
|
-
size: level[1]
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// YES outcome order book:
|
|
40
|
-
// - Bids: people buying YES (use data.yes directly)
|
|
41
|
-
// - Asks: people selling YES = people buying NO (invert data.no)
|
|
42
|
-
bids = (data.yes || []).map((level) => ({
|
|
43
|
-
price: level[0] / 100,
|
|
44
|
-
size: level[1]
|
|
45
|
-
}));
|
|
46
|
-
asks = (data.no || []).map((level) => ({
|
|
47
|
-
price: 1 - (level[0] / 100), // Invert NO price to get YES ask price
|
|
48
|
-
size: level[1]
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
// Sort bids desc, asks asc
|
|
52
|
-
bids.sort((a, b) => b.price - a.price);
|
|
53
|
-
asks.sort((a, b) => a.price - b.price);
|
|
54
|
-
return { bids, asks, timestamp: Date.now() };
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
throw errors_1.kalshiErrorMapper.mapError(error);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { HistoryFilterParams, TradesParams } from '../../BaseExchange';
|
|
3
|
-
import { Trade } from '../../types';
|
|
4
|
-
export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, http?: AxiosInstance): Promise<Trade[]>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchTrades = fetchTrades;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const errors_1 = require("./errors");
|
|
9
|
-
async function fetchTrades(id, params, http = axios_1.default) {
|
|
10
|
-
try {
|
|
11
|
-
const ticker = id.replace(/-NO$/, '');
|
|
12
|
-
const url = `https://api.elections.kalshi.com/trade-api/v2/markets/trades`;
|
|
13
|
-
const response = await http.get(url, {
|
|
14
|
-
params: {
|
|
15
|
-
ticker: ticker,
|
|
16
|
-
limit: params.limit || 100
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const trades = response.data.trades || [];
|
|
20
|
-
return trades.map((t) => ({
|
|
21
|
-
id: t.trade_id,
|
|
22
|
-
timestamp: new Date(t.created_time).getTime(),
|
|
23
|
-
price: t.yes_price / 100,
|
|
24
|
-
amount: t.count,
|
|
25
|
-
side: t.taker_side === 'yes' ? 'buy' : 'sell'
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
throw errors_1.kalshiErrorMapper.mapError(error);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchPositions = fetchPositions;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
async function fetchPositions(userAddress) {
|
|
10
|
-
try {
|
|
11
|
-
const url = `${utils_1.LIMITLESS_API_URL}/portfolio/${userAddress}/positions`;
|
|
12
|
-
const response = await axios_1.default.get(url);
|
|
13
|
-
const data = response.data?.data || response.data || [];
|
|
14
|
-
return data.map((p) => ({
|
|
15
|
-
marketId: p.market?.slug || p.conditionId,
|
|
16
|
-
outcomeId: p.asset,
|
|
17
|
-
outcomeLabel: p.outcome || 'Unknown',
|
|
18
|
-
size: parseFloat(p.size || '0'),
|
|
19
|
-
entryPrice: parseFloat(p.avgPrice || '0'),
|
|
20
|
-
currentPrice: parseFloat(p.curPrice || '0'),
|
|
21
|
-
unrealizedPnL: parseFloat(p.cashPnl || '0'),
|
|
22
|
-
realizedPnL: parseFloat(p.realizedPnl || '0')
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
// Limitless returns 404 if the user has no history on the platform.
|
|
27
|
-
// We treat this as an empty portfolio rather than an error.
|
|
28
|
-
if (error.response?.status === 404) {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
console.error(`Error fetching Limitless positions: ${error.message}`);
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { TradesParams, HistoryFilterParams } from '../../BaseExchange';
|
|
3
|
-
import { Trade } from '../../types';
|
|
4
|
-
export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, headers?: Record<string, string>, http?: AxiosInstance): Promise<Trade[]>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchTrades = fetchTrades;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const errors_1 = require("./errors");
|
|
10
|
-
async function fetchTrades(id, params, headers, http = axios_1.default) {
|
|
11
|
-
try {
|
|
12
|
-
// id format: {networkId}:{marketId}:{outcomeId} or {networkId}:{marketId}
|
|
13
|
-
const parts = id.split(':');
|
|
14
|
-
if (parts.length < 2) {
|
|
15
|
-
throw new Error(`Invalid Myriad ID format: "${id}". Expected "{networkId}:{marketId}" or "{networkId}:{marketId}:{outcomeId}".`);
|
|
16
|
-
}
|
|
17
|
-
const [networkId, marketId] = parts;
|
|
18
|
-
const outcomeId = parts.length >= 3 ? parts[2] : undefined;
|
|
19
|
-
const queryParams = {
|
|
20
|
-
network_id: Number(networkId),
|
|
21
|
-
page: 1,
|
|
22
|
-
limit: params.limit || 100,
|
|
23
|
-
};
|
|
24
|
-
// Handle date range filters
|
|
25
|
-
const ensureDate = (d) => {
|
|
26
|
-
if (typeof d === 'string') {
|
|
27
|
-
if (!d.endsWith('Z') && !d.match(/[+-]\d{2}:\d{2}$/)) {
|
|
28
|
-
return new Date(d + 'Z');
|
|
29
|
-
}
|
|
30
|
-
return new Date(d);
|
|
31
|
-
}
|
|
32
|
-
return d;
|
|
33
|
-
};
|
|
34
|
-
if (params.start) {
|
|
35
|
-
queryParams.since = Math.floor(ensureDate(params.start).getTime() / 1000);
|
|
36
|
-
}
|
|
37
|
-
if (params.end) {
|
|
38
|
-
queryParams.until = Math.floor(ensureDate(params.end).getTime() / 1000);
|
|
39
|
-
}
|
|
40
|
-
const response = await http.get(`${utils_1.BASE_URL}/markets/${marketId}/events`, {
|
|
41
|
-
params: queryParams,
|
|
42
|
-
headers,
|
|
43
|
-
});
|
|
44
|
-
const events = response.data.data || response.data.events || [];
|
|
45
|
-
// Filter to buy/sell actions only (skip liquidity events)
|
|
46
|
-
const tradeEvents = events.filter((e) => e.action === 'buy' || e.action === 'sell');
|
|
47
|
-
// Filter by outcomeId if specified
|
|
48
|
-
const filtered = outcomeId
|
|
49
|
-
? tradeEvents.filter((e) => String(e.outcomeId) === outcomeId)
|
|
50
|
-
: tradeEvents;
|
|
51
|
-
return filtered.map((t, index) => ({
|
|
52
|
-
id: `${t.blockNumber || t.timestamp}-${index}`,
|
|
53
|
-
timestamp: (t.timestamp || 0) * 1000,
|
|
54
|
-
price: t.shares > 0 ? Number(t.value) / Number(t.shares) : 0,
|
|
55
|
-
amount: Number(t.shares || 0),
|
|
56
|
-
side: t.action === 'buy' ? 'buy' : 'sell',
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
throw errors_1.myriadErrorMapper.mapError(error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchPositions = fetchPositions;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
async function fetchPositions(userAddress) {
|
|
10
|
-
try {
|
|
11
|
-
const response = await axios_1.default.get(`${utils_1.DATA_API_URL}/positions`, {
|
|
12
|
-
params: {
|
|
13
|
-
user: userAddress,
|
|
14
|
-
limit: 100
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const data = Array.isArray(response.data) ? response.data : [];
|
|
18
|
-
return data.map((p) => ({
|
|
19
|
-
marketId: p.conditionId,
|
|
20
|
-
outcomeId: p.asset,
|
|
21
|
-
outcomeLabel: p.outcome || 'Unknown',
|
|
22
|
-
size: parseFloat(p.size),
|
|
23
|
-
entryPrice: parseFloat(p.avgPrice),
|
|
24
|
-
currentPrice: parseFloat(p.curPrice || '0'),
|
|
25
|
-
unrealizedPnL: parseFloat(p.cashPnl || '0'),
|
|
26
|
-
realizedPnL: parseFloat(p.realizedPnl || '0')
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
const apiError = error.response?.data?.error || error.response?.data?.message || error.message;
|
|
31
|
-
console.error(`[Polymarket] fetchPositions failed for ${userAddress}: ${apiError}`);
|
|
32
|
-
throw new Error(`Polymarket Positions API Error: ${apiError}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { OHLCVParams, HistoryFilterParams } from '../../BaseExchange';
|
|
3
|
-
import { PriceCandle } from '../../types';
|
|
4
|
-
export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams, http?: AxiosInstance): Promise<PriceCandle[]>;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchOHLCV = fetchOHLCV;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const errors_1 = require("./errors");
|
|
10
|
-
const INTERVAL_MAP = {
|
|
11
|
-
'1m': '1m',
|
|
12
|
-
'5m': '1m',
|
|
13
|
-
'15m': '1m',
|
|
14
|
-
'1h': '1h',
|
|
15
|
-
'6h': '6h',
|
|
16
|
-
'1d': '1d',
|
|
17
|
-
};
|
|
18
|
-
function aggregateCandles(candles, intervalMs) {
|
|
19
|
-
if (candles.length === 0)
|
|
20
|
-
return [];
|
|
21
|
-
const buckets = new Map();
|
|
22
|
-
for (const c of candles) {
|
|
23
|
-
const key = Math.floor(c.timestamp / intervalMs) * intervalMs;
|
|
24
|
-
const existing = buckets.get(key);
|
|
25
|
-
if (!existing) {
|
|
26
|
-
buckets.set(key, { ...c, timestamp: key });
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
existing.high = Math.max(existing.high, c.high);
|
|
30
|
-
existing.low = Math.min(existing.low, c.low);
|
|
31
|
-
existing.close = c.close;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return Array.from(buckets.values()).sort((a, b) => a.timestamp - b.timestamp);
|
|
35
|
-
}
|
|
36
|
-
async function fetchOHLCV(id, params, http = axios_1.default) {
|
|
37
|
-
if (!params.resolution) {
|
|
38
|
-
throw new Error('fetchOHLCV requires a resolution parameter.');
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const apiInterval = INTERVAL_MAP[params.resolution] || '1h';
|
|
42
|
-
const queryParams = {
|
|
43
|
-
market: id,
|
|
44
|
-
interval: apiInterval,
|
|
45
|
-
};
|
|
46
|
-
if (params.start)
|
|
47
|
-
queryParams.startTs = Math.floor(params.start.getTime() / 1000);
|
|
48
|
-
if (params.end)
|
|
49
|
-
queryParams.endTs = Math.floor(params.end.getTime() / 1000);
|
|
50
|
-
const response = await http.get(`${utils_1.CLOB_BASE_URL}/prices-history`, {
|
|
51
|
-
params: queryParams,
|
|
52
|
-
});
|
|
53
|
-
const points = response.data?.history || response.data || [];
|
|
54
|
-
let candles = points
|
|
55
|
-
.map((p) => {
|
|
56
|
-
const price = Number(p.p);
|
|
57
|
-
const ts = Number(p.t) * 1000;
|
|
58
|
-
return {
|
|
59
|
-
timestamp: ts,
|
|
60
|
-
open: price,
|
|
61
|
-
high: price,
|
|
62
|
-
low: price,
|
|
63
|
-
close: price,
|
|
64
|
-
volume: 0,
|
|
65
|
-
};
|
|
66
|
-
})
|
|
67
|
-
.sort((a, b) => a.timestamp - b.timestamp);
|
|
68
|
-
// Client-side aggregation for intervals that don't have a direct API mapping
|
|
69
|
-
if (params.resolution === '5m') {
|
|
70
|
-
candles = aggregateCandles(candles, 5 * 60 * 1000);
|
|
71
|
-
}
|
|
72
|
-
else if (params.resolution === '15m') {
|
|
73
|
-
candles = aggregateCandles(candles, 15 * 60 * 1000);
|
|
74
|
-
}
|
|
75
|
-
if (params.limit) {
|
|
76
|
-
candles = candles.slice(-params.limit);
|
|
77
|
-
}
|
|
78
|
-
return candles;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
throw errors_1.probableErrorMapper.mapError(error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchOrderBook = fetchOrderBook;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const errors_1 = require("./errors");
|
|
10
|
-
async function fetchOrderBook(id, http = axios_1.default) {
|
|
11
|
-
try {
|
|
12
|
-
const response = await http.get(`${utils_1.CLOB_BASE_URL}/book`, {
|
|
13
|
-
params: { token_id: id },
|
|
14
|
-
});
|
|
15
|
-
const data = response.data;
|
|
16
|
-
const bids = (data.bids || [])
|
|
17
|
-
.map((level) => ({
|
|
18
|
-
price: parseFloat(level.price),
|
|
19
|
-
size: parseFloat(level.size),
|
|
20
|
-
}))
|
|
21
|
-
.sort((a, b) => b.price - a.price);
|
|
22
|
-
const asks = (data.asks || [])
|
|
23
|
-
.map((level) => ({
|
|
24
|
-
price: parseFloat(level.price),
|
|
25
|
-
size: parseFloat(level.size),
|
|
26
|
-
}))
|
|
27
|
-
.sort((a, b) => a.price - b.price);
|
|
28
|
-
return {
|
|
29
|
-
bids,
|
|
30
|
-
asks,
|
|
31
|
-
timestamp: data.timestamp ? new Date(data.timestamp).getTime() : Date.now(),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
throw errors_1.probableErrorMapper.mapError(error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchPositions = fetchPositions;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const errors_1 = require("./errors");
|
|
9
|
-
const POSITIONS_URL = 'https://api.probable.markets/public/api/v1/position/current';
|
|
10
|
-
async function fetchPositions(userAddress) {
|
|
11
|
-
try {
|
|
12
|
-
const response = await axios_1.default.get(POSITIONS_URL, {
|
|
13
|
-
params: {
|
|
14
|
-
user: userAddress,
|
|
15
|
-
limit: 500,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
const data = Array.isArray(response.data) ? response.data : (response.data?.data || []);
|
|
19
|
-
return data.map((p) => ({
|
|
20
|
-
marketId: String(p.conditionId || p.condition_id || ''),
|
|
21
|
-
outcomeId: String(p.asset || p.token_id || ''),
|
|
22
|
-
outcomeLabel: p.outcome || p.title || 'Unknown',
|
|
23
|
-
size: parseFloat(p.size || '0'),
|
|
24
|
-
entryPrice: parseFloat(p.avgPrice || p.avg_price || '0'),
|
|
25
|
-
currentPrice: parseFloat(p.curPrice || p.cur_price || '0'),
|
|
26
|
-
unrealizedPnL: parseFloat(p.cashPnl || p.cash_pnl || '0'),
|
|
27
|
-
realizedPnL: parseFloat(p.realizedPnl || p.realized_pnl || '0'),
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
throw errors_1.probableErrorMapper.mapError(error);
|
|
32
|
-
}
|
|
33
|
-
}
|