shrimpy-node
Version:
Client for the Shrimpy API
1,010 lines • 55.4 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var querystring = require("querystring");
var rp = require("request-promise-native");
var authentication_provider_1 = require("./authentication-provider");
var dto_converters_1 = require("../dto-converters");
var ShrimpyApiClient = /** @class */ (function () {
function ShrimpyApiClient(publicKey, privateKey) {
this._accountBalanceDtoConverter = new dto_converters_1.AccountBalanceDtoConverter();
this._allocationDtoConverter = new dto_converters_1.AllocationDtoConverter();
this._assetInsightDtoConverter = new dto_converters_1.AssetInsightDtoConverter();
this._backtestAssetDtoConveter = new dto_converters_1.BacktestAssetDtoConverter();
this._backtestDataPointDtoConverter = new dto_converters_1.BacktestDataPointDtoConverter();
this._candlestickDtoConverter = new dto_converters_1.CandlestickDtoConverter();
this._dateDtoConverter = new dto_converters_1.DateDtoConverter();
this._decimalDtoConverter = new dto_converters_1.DecimalDtoConverter();
this._historicalCandlestickDtoConverter = new dto_converters_1.HistoricalCandlestickDtoConverter();
this._historicalOrderBooksDtoConverter = new dto_converters_1.HistoricalOrderBooksDtoConverter();
this._historicalInstrumentsDtoConverter = new dto_converters_1.HistoricalInstrumentsDtoConverter();
this._historicalTradesDtoConverter = new dto_converters_1.HistoricalTradesDtoConverter();
this._limitOrderDtoConverter = new dto_converters_1.LimitOrderDtoConverter();
this._limitOrderStatusDtoConverter = new dto_converters_1.LimitOrderStatusDtoConverter();
this._marketOrderBooksDtoConverter = new dto_converters_1.MarketOrderBooksDtoConverter();
this._predictionsDtoConverter = new dto_converters_1.PredictionsDtoConverter();
this._strategyDtoConverter = new dto_converters_1.StrategyDtoConverter();
this._tickerDtoConverter = new dto_converters_1.TickerDtoConverter();
this._totalBalanceHistoryItemDtoConverter = new dto_converters_1.TotalBalanceHistoryItemDtoConverter();
this._tradeChangesDtoConverter = new dto_converters_1.TradeChangesDtoConverter();
this._tradeDtoConverter = new dto_converters_1.TradeDtoConverter();
this._userDtoConverter = new dto_converters_1.UserDtoConverter();
this._authenticationProvider = null;
if (publicKey && privateKey) {
// keys were supplied, use them
this._setApiCredentials(publicKey, privateKey);
}
}
/* Public */
ShrimpyApiClient.prototype.getSupportedExchanges = function () {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "list_exchanges";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, false)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.getExchangeAssets = function (exchange) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "exchanges/" + exchange + "/assets";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, false)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.getTradingPairs = function (exchange) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "exchanges/" + exchange + "/trading_pairs";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, false)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/* Market Data */
ShrimpyApiClient.prototype.getTicker = function (exchange) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, tickerDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "exchanges/" + exchange + "/ticker";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, false)];
case 1:
tickerDtos = _a.sent();
return [2 /*return*/, tickerDtos.map(function (tickerDto) {
return _this._tickerDtoConverter.convertFromDto(tickerDto);
})];
}
});
});
};
ShrimpyApiClient.prototype.getOrderBooks = function (exchange, baseSymbol, quoteSymbol, limit) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, exchangeString, parameters, orderBooksListDto;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "orderbooks";
if (Array.isArray(exchange)) {
exchangeString = exchange.join(',');
}
else {
exchangeString = exchange;
}
parameters = {
exchange: exchangeString
};
if (baseSymbol) {
if (Array.isArray(baseSymbol)) {
parameters.baseSymbol = baseSymbol.join(',');
}
else {
parameters.baseSymbol = baseSymbol;
}
}
if (quoteSymbol) {
if (Array.isArray(quoteSymbol)) {
parameters.quoteSymbol = quoteSymbol.join(',');
}
else {
parameters.quoteSymbol = quoteSymbol;
}
}
if (limit) {
parameters.limit = limit;
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, false)];
case 1:
orderBooksListDto = _a.sent();
return [2 /*return*/, orderBooksListDto.map(function (orderBooksDto) {
return _this._marketOrderBooksDtoConverter.convertFromDto(orderBooksDto);
})];
}
});
});
};
ShrimpyApiClient.prototype.getCandles = function (exchange, baseTradingSymbol, quoteTradingSymbol, interval, startTime) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, candlestickDtos, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "exchanges/" + exchange + "/candles";
parameters = {
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol,
interval: interval,
};
if (startTime) {
parameters.startTime = this._dateDtoConverter.convertToDto(startTime);
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, false)];
case 1:
candlestickDtos = _a.sent();
result = candlestickDtos.map(function (candlestickDto) {
return _this._candlestickDtoConverter.convertFromDto(candlestickDto);
});
return [2 /*return*/, result];
}
});
});
};
/* Users */
ShrimpyApiClient.prototype.getUsers = function () {
return __awaiter(this, void 0, void 0, function () {
var endpoint, userDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = 'users';
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
userDtos = _a.sent();
return [2 /*return*/, userDtos.map(function (userDto) {
return _this._userDtoConverter.convertFromDto(userDto);
})];
}
});
});
};
ShrimpyApiClient.prototype.getUser = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, userDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
userDto = _a.sent();
return [2 /*return*/, this._userDtoConverter.convertFromDto(userDto)];
}
});
});
};
ShrimpyApiClient.prototype.createUser = function (name) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = 'users';
parameters = null;
if (name) {
parameters = { name: name };
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
result = _a.sent();
return [2 /*return*/, result.id];
}
});
});
};
ShrimpyApiClient.prototype.setUserName = function (userId, name) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/name";
parameters = {
name: name
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.removeUser = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'DELETE', {}, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.enableUser = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/enable";
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', null, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.disableUser = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/disable";
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', null, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/* User API Keys */
ShrimpyApiClient.prototype.getApiKeys = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/keys";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.createApiKeys = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/keys";
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.deleteApiKeys = function (userId, publicKey) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/keys/" + publicKey;
return [4 /*yield*/, this._callEndpoint(endpoint, 'DELETE', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.getPermissions = function (userId, publicKey) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/keys/" + publicKey + "/permissions";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.setPermissions = function (userId, publicKey, account, trade) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/keys/" + publicKey + "/permissions";
parameters = {
account: account,
trade: trade
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/* Accounts */
ShrimpyApiClient.prototype.getAccounts = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.getAccount = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
ShrimpyApiClient.prototype.createAccount = function (userId, exchange, publicKey, privateKey, passphrase) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts";
parameters = {
exchange: exchange,
publicKey: publicKey,
privateKey: privateKey,
passphrase: passphrase,
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
result = _a.sent();
return [2 /*return*/, result.id];
}
});
});
};
ShrimpyApiClient.prototype.deleteAccount = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'DELETE', null, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.getIpWhitelistAddresses = function (userId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/whitelist";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/* Trading */
ShrimpyApiClient.prototype.createTrade = function (userId, accountId, fromSymbol, toSymbol, amount, smartRouting, maxSpreadPercent, maxSlippagePercent) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/trades";
parameters = {
fromSymbol: fromSymbol,
toSymbol: toSymbol,
amount: this._decimalDtoConverter.convertToDto(amount),
};
if (smartRouting) {
parameters.smartRouting = smartRouting;
}
if (maxSpreadPercent) {
parameters.maxSpreadPercent = this._decimalDtoConverter.convertToDto(maxSpreadPercent);
}
if (maxSlippagePercent) {
parameters.maxSlippagePercent = this._decimalDtoConverter.convertToDto(maxSlippagePercent);
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
result = _a.sent();
return [2 /*return*/, result.id];
}
});
});
};
ShrimpyApiClient.prototype.getTrade = function (userId, accountId, tradeId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, tradeChangesDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/trades/" + tradeId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
tradeChangesDto = _a.sent();
return [2 /*return*/, this._tradeChangesDtoConverter.convertFromDto(tradeChangesDto)];
}
});
});
};
ShrimpyApiClient.prototype.getActiveTrades = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, tradeDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/trades";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
tradeDtos = _a.sent();
return [2 /*return*/, tradeDtos.map(function (tradeDto) {
return _this._tradeDtoConverter.convertFromDto(tradeDto);
})];
}
});
});
};
/* Balances */
ShrimpyApiClient.prototype.getBalance = function (userId, accountId, date) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, accountBalanceDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/balance";
parameters = null;
if (date) {
parameters = { date: this._dateDtoConverter.convertToDto(date) };
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
accountBalanceDto = _a.sent();
return [2 /*return*/, this._accountBalanceDtoConverter.convertFromDto(accountBalanceDto)];
}
});
});
};
ShrimpyApiClient.prototype.getTotalBalanceHistory = function (userId, accountId, startTime, endTime) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, totalBalanceHistoryDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/total_balance_history";
parameters = null;
if (startTime || endTime) {
parameters = {};
if (startTime) {
parameters.startTime = this._dateDtoConverter.convertToDto(startTime);
}
if (endTime) {
parameters.endTime = this._dateDtoConverter.convertToDto(endTime);
}
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
totalBalanceHistoryDtos = _a.sent();
return [2 /*return*/, totalBalanceHistoryDtos.map(function (totalBalanceHistoryDto) {
return _this._totalBalanceHistoryItemDtoConverter.convertFromDto(totalBalanceHistoryDto);
})];
}
});
});
};
/* Asset Management */
ShrimpyApiClient.prototype.rebalance = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/rebalance";
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', null, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.getRebalancePeriod = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/rebalance_period";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
result = _a.sent();
return [2 /*return*/, result.rebalancePeriod];
}
});
});
};
ShrimpyApiClient.prototype.setRebalancePeriod = function (userId, accountId, rebalancePeriodHours) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
// verify rebalancePeriodHours is an integer
if (!Number.isInteger(rebalancePeriodHours)) {
throw new Error("Invalid rebalance period. Rebalance period must be an integer");
}
endpoint = "users/" + userId + "/accounts/" + accountId + "/rebalance_period";
parameters = {
rebalancePeriod: rebalancePeriodHours
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.getStrategy = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, strategyDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/strategy";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
strategyDto = _a.sent();
return [2 /*return*/, this._strategyDtoConverter.convertFromDto(strategyDto)];
}
});
});
};
ShrimpyApiClient.prototype.setStrategy = function (userId, accountId, strategy) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/strategy";
parameters = this._strategyDtoConverter.convertToDto(strategy);
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.clearStrategy = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/strategy";
return [4 /*yield*/, this._callEndpoint(endpoint, 'DELETE', null, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ShrimpyApiClient.prototype.allocate = function (userId, accountId, strategy) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/allocate";
parameters = this._strategyDtoConverter.convertToDto(strategy);
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/* Limit Orders */
ShrimpyApiClient.prototype.createOrder = function (userId, accountId, baseSymbol, quoteSymbol, quantity, price, side, timeInForce) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/orders";
parameters = {
baseSymbol: baseSymbol,
quoteSymbol: quoteSymbol,
quantity: this._decimalDtoConverter.convertToDto(quantity),
price: this._decimalDtoConverter.convertToDto(price),
side: side,
timeInForce: timeInForce
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
result = _a.sent();
return [2 /*return*/, result.id];
}
});
});
};
ShrimpyApiClient.prototype.getOrder = function (userId, accountId, orderId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, limitOrderStatusDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/orders/" + orderId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
limitOrderStatusDto = _a.sent();
return [2 /*return*/, this._limitOrderStatusDtoConverter.convertFromDto(limitOrderStatusDto)];
}
});
});
};
ShrimpyApiClient.prototype.getOrders = function (userId, accountId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, limitOrderDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/orders";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
limitOrderDtos = _a.sent();
return [2 /*return*/, limitOrderDtos.map(function (limitOrderDto) {
return _this._limitOrderDtoConverter.convertFromDto(limitOrderDto);
})];
}
});
});
};
ShrimpyApiClient.prototype.cancelOrder = function (userId, accountId, orderId) {
return __awaiter(this, void 0, void 0, function () {
var endpoint;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "users/" + userId + "/accounts/" + accountId + "/orders/" + orderId;
return [4 /*yield*/, this._callEndpoint(endpoint, 'DELETE', null, true)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
/* Analytics */
ShrimpyApiClient.prototype.getBacktestAssets = function (exchange, startTime, endTime) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, backtestAssetDtos, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "analytics/backtest/" + exchange + "/assets";
parameters = {};
if (startTime) {
parameters.startTime = this._dateDtoConverter.convertToDto(startTime);
}
if (endTime) {
parameters.endTime = this._dateDtoConverter.convertToDto(endTime);
}
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
backtestAssetDtos = _a.sent();
result = backtestAssetDtos.map(function (backtestAssetDto) {
return _this._backtestAssetDtoConveter.convertFromDto(backtestAssetDto);
});
return [2 /*return*/, result];
}
});
});
};
ShrimpyApiClient.prototype.runBacktest = function (exchange, rebalancePeriodHours, fee, startTime, endTime, initialValue, allocations) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, allocationsDto, parameters, resultDto, rebalanceData, holdingData, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "analytics/backtest/" + exchange + "/run";
allocationsDto = allocations.map(function (allocation) {
return _this._allocationDtoConverter.convertToDto(allocation);
});
parameters = {
rebalancePeriod: rebalancePeriodHours,
fee: fee.toString(),
startTime: this._dateDtoConverter.convertToDto(startTime),
endTime: this._dateDtoConverter.convertToDto(endTime),
initialValue: initialValue.toString(),
allocations: allocationsDto,
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'POST', parameters, true)];
case 1:
resultDto = _a.sent();
rebalanceData = resultDto.rebalanceData.map(function (dataPointDto) {
return _this._backtestDataPointDtoConverter.convertFromDto(dataPointDto);
});
holdingData = resultDto.holdingData.map(function (dataPointDto) {
return _this._backtestDataPointDtoConverter.convertFromDto(dataPointDto);
});
result = {
rebalanceData: rebalanceData,
holdingData: holdingData,
};
return [2 /*return*/, result];
}
});
});
};
ShrimpyApiClient.prototype.getPredictions = function (exchange, baseTradingSymbol, quoteTradingSymbol) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, predictionsListDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "analytics/predict";
parameters = {
exchange: exchange,
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
predictionsListDto = _a.sent();
return [2 /*return*/, this._predictionsDtoConverter.convertFromDto(predictionsListDto)];
}
});
});
};
/* Insights */
ShrimpyApiClient.prototype.getAssetDominance = function () {
return __awaiter(this, void 0, void 0, function () {
var endpoint, assetInsightDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "insights/asset_dominance";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
assetInsightDtos = _a.sent();
return [2 /*return*/, assetInsightDtos.map(function (assetInsightDto) {
return _this._assetInsightDtoConverter.convertFromDto(assetInsightDto);
})];
}
});
});
};
ShrimpyApiClient.prototype.getAssetPopularity = function () {
return __awaiter(this, void 0, void 0, function () {
var endpoint, assetInsightDtos;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "insights/asset_popularity";
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', null, true)];
case 1:
assetInsightDtos = _a.sent();
return [2 /*return*/, assetInsightDtos.map(function (assetInsightDto) {
return _this._assetInsightDtoConverter.convertFromDto(assetInsightDto);
})];
}
});
});
};
/* Historical */
ShrimpyApiClient.prototype.getHistoricalTrades = function (exchange, baseTradingSymbol, quoteTradingSymbol, startTime, endTime, limit) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, resultDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "historical/trades";
parameters = {
exchange: exchange,
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol,
startTime: this._dateDtoConverter.convertToDto(startTime),
endTime: this._dateDtoConverter.convertToDto(endTime),
limit: limit,
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
resultDto = _a.sent();
return [2 /*return*/, this._historicalTradesDtoConverter.convertFromDto(resultDto)];
}
});
});
};
ShrimpyApiClient.prototype.getHistoricalOrderBooks = function (exchange, baseTradingSymbol, quoteTradingSymbol, startTime, endTime, limit) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, resultDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "historical/orderbooks";
parameters = {
exchange: exchange,
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol,
startTime: this._dateDtoConverter.convertToDto(startTime),
endTime: this._dateDtoConverter.convertToDto(endTime),
limit: limit,
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
resultDto = _a.sent();
return [2 /*return*/, this._historicalOrderBooksDtoConverter.convertFromDto(resultDto)];
}
});
});
};
ShrimpyApiClient.prototype.getHistoricalCandles = function (exchange, baseTradingSymbol, quoteTradingSymbol, startTime, endTime, limit, interval) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, resultDto, result;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "historical/candles";
parameters = {
exchange: exchange,
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol,
startTime: this._dateDtoConverter.convertToDto(startTime),
endTime: this._dateDtoConverter.convertToDto(endTime),
limit: limit,
interval: interval
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
resultDto = _a.sent();
result = resultDto.map(function (candlestick) {
return _this._historicalCandlestickDtoConverter.convertFromDto(candlestick);
});
return [2 /*return*/, result];
}
});
});
};
ShrimpyApiClient.prototype.getHistoricalInstruments = function (exchange, baseTradingSymbol, quoteTradingSymbol) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, resultDto;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "historical/instruments";
parameters = {
exchange: exchange,
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
resultDto = _a.sent();
return [2 /*return*/, this._historicalInstrumentsDtoConverter.convertFromDto(resultDto)];
}
});
});
};
ShrimpyApiClient.prototype.getHistoricalCount = function (type, exchange, baseTradingSymbol, quoteTradingSymbol, startTime, endTime) {
return __awaiter(this, void 0, void 0, function () {
var endpoint, parameters, countDto, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
endpoint = "historical/count";
parameters = {
type: type,
exchange: exchange,
baseTradingSymbol: baseTradingSymbol,
quoteTradingSymbol: quoteTradingSymbol,
startTime: this._dateDtoConverter.convertToDto(startTime),
endTime: this._dateDtoConverter.convertToDto(endTime)
};
return [4 /*yield*/, this._callEndpoint(endpoint, 'GET', parameters, true)];
case 1:
countDto = _a.sent();
result = {
count: countDto.count
};
return [2 /*return*/, result];
}
});
});
};
/* Management */
ShrimpyApiClient.prototype.getStatus = function () {
return __a