@parcl-finance/product-sdk
Version:
TypeScript SDK for interacting with Parcl's product APIs
101 lines • 3.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Predictions = void 0;
const constants_1 = require("./constants");
const httpClient_1 = require("./httpClient");
class Predictions {
baseUrl;
headers;
expressClient;
constructor(accessToken, env) {
const headers = {};
if (accessToken !== undefined) {
headers["Authorization"] = "Bearer " + accessToken;
}
this.headers = headers;
this.baseUrl = `/predictions`;
this.expressClient = new httpClient_1.HttpClient((0, constants_1.getDefaultExpressApiUrl)(env), this.headers);
}
async getUserPortfolio({ userAddress }) {
const { availablePoints, openInterestPoints } = await this.expressClient.getWithAuth({
path: this.baseUrl + "/portfolio",
authority: userAddress,
});
return { availablePoints, openInterestPoints };
}
async getUserOrders({ userAddress, orderStatusFilter, }) {
const { orders } = await this.expressClient.getWithAuth({
path: this.baseUrl + `/orders`,
authority: userAddress,
params: {
orderStatusFilter,
},
});
return orders;
}
async getUserPositions({ userAddress }) {
const { positions } = await this.expressClient.getWithAuth({
path: this.baseUrl + `/positions`,
authority: userAddress,
});
return positions;
}
async getUserTrades({ userAddress }) {
const { trades } = await this.expressClient.getWithAuth({
path: this.baseUrl + `/trades`,
authority: userAddress,
});
return trades;
}
async getPredictionMarkets({ marketCategoryFilter, isResolvedFilter, }) {
const { markets } = await this.expressClient.get({
path: this.baseUrl + "/markets",
params: {
marketCategoryFilter,
isResolvedFilter,
},
});
return markets;
}
async getPredictionMarketInfo({ marketId }) {
const { market } = await this.expressClient.get({
path: this.baseUrl + `/markets/${marketId}`,
});
return market;
}
async getOrderBook({ marketId }) {
const { yesOrderBook, noOrderBook, bestYesBidPrice, bestYesAskPrice, bestNoBidPrice, bestNoAskPrice, } = await this.expressClient.get({
path: this.baseUrl + `/markets/${marketId}/order-book`,
});
return {
yesOrderBook,
noOrderBook,
bestYesBidPrice,
bestYesAskPrice,
bestNoBidPrice,
bestNoAskPrice,
};
}
async placeOrder({ userAddress, marketId, type, side, price, contracts, }) {
const { order: placedOrder } = await this.expressClient.postWithAuth({
path: this.baseUrl + `/markets/${marketId}/orders`,
body: {
type,
side,
price,
contracts,
},
authority: userAddress,
});
return placedOrder;
}
async cancelOrder({ orderId, userAddress }) {
const { status } = await this.expressClient.postWithAuth({
path: this.baseUrl + `/orders/${orderId}/cancel`,
authority: userAddress,
});
return status;
}
}
exports.Predictions = Predictions;
//# sourceMappingURL=predictions.js.map