├── .gitignore ├── LICENSE ├── README.md ├── lib ├── client │ ├── authentication-provider.ts │ ├── index.ts │ ├── shrimpy-api-client.ts │ └── shrimpy-ws-client.ts ├── dto-converters │ ├── account-balance-dto-converter.ts │ ├── allocation-dto-converter.ts │ ├── asset-balance-dto-converter.ts │ ├── asset-insight-dto-converter.ts │ ├── backtest-asset-dto-converter.ts │ ├── backtest-data-point-dto-converter.ts │ ├── balance-change-dto-converter.ts │ ├── candlestick-dto-converter.ts │ ├── date-dto-converter.ts │ ├── decimal-dto-converter.ts │ ├── dynamic-strategy-dto-converter.ts │ ├── exchange-order-book-dto-converter.ts │ ├── historical-candlestick-dto-converter.ts │ ├── historical-instruments-dto-converter.ts │ ├── historical-orderbooks-dto-converter.ts │ ├── historical-trades-dto-converter.ts │ ├── index.ts │ ├── limit-order-dto-converter.ts │ ├── limit-order-status-dto-converter.ts │ ├── market-order-books-dto-converter.ts │ ├── nullable-date-dto-converter.ts │ ├── nullable-decimal-dto-converter.ts │ ├── order-book-dto-converter.ts │ ├── order-book-item-dto-converter.ts │ ├── prediction-item-dto-converter.ts │ ├── predictions-dto-converter.ts │ ├── static-strategy-dto-converter.ts │ ├── strategy-dto-converter.ts │ ├── ticker-dto-converter.ts │ ├── total-balance-history-item-dto-converter.ts │ ├── trade-changes-dto-converter.ts │ ├── trade-dto-converter.ts │ ├── trade-fill-dto-converter.ts │ ├── trend-dto-converter.ts │ └── user-dto-converter.ts ├── dtos │ ├── iaccount-balance-dto.ts │ ├── iaccount-dto.ts │ ├── iallocation-dto.ts │ ├── iapi-key-permissions-dto.ts │ ├── iapi-keys-dto.ts │ ├── iasset-balance-dto.ts │ ├── iasset-insight-dto.ts │ ├── ibacktest-asset-dto.ts │ ├── ibacktest-data-point-dto.ts │ ├── ibacktest-result-dto.ts │ ├── ibalance-change-dto.ts │ ├── icandlestick-dto.ts │ ├── idynamic-strategy-dto.ts │ ├── iexchange-api-error-dto.ts │ ├── iexchange-asset-dto.ts │ ├── iexchange-info-dto.ts │ ├── iexchange-order-book-dto.ts │ ├── iguid-id-result-dto.ts │ ├── ihistorical-candlestick-dto.ts │ ├── ihistorical-count-dto.ts │ ├── ihistorical-instrument-dto.ts │ ├── ihistorical-order-book-dto.ts │ ├── ihistorical-trade-dto.ts │ ├── ilimit-order-dto.ts │ ├── ilimit-order-status-dto.ts │ ├── imarket-order-books-dto.ts │ ├── index.ts │ ├── inumber-id-result-dto.ts │ ├── iorder-book-dto.ts │ ├── iorder-book-item-dto.ts │ ├── iprediction-item-dto.ts │ ├── ipredictions-dto.ts │ ├── irebalance-period-result-dto.ts │ ├── istatic-strategy-dto.ts │ ├── istrategy-dto.ts │ ├── iticker-dto.ts │ ├── itotal-balance-history-item-dto.ts │ ├── itrade-changes-dto.ts │ ├── itrade-dto.ts │ ├── itrade-fill-dto.ts │ ├── itrading-pair-dto.ts │ ├── itrend-dto.ts │ ├── iuser-dto.ts │ └── iwebsocket-token-dto.ts ├── enums │ ├── exchange-enum.ts │ ├── index.ts │ └── subscription-type-enum.ts ├── index.ts ├── interfaces │ ├── idto-converter.ts │ └── index.ts ├── models │ ├── iaccount-balance.ts │ ├── iaccount.ts │ ├── iallocation.ts │ ├── iapi-key-permissions.ts │ ├── iapi-keys.ts │ ├── iasset-balance.ts │ ├── iasset-insight.ts │ ├── ibacktest-asset.ts │ ├── ibacktest-data-point.ts │ ├── ibacktest-result.ts │ ├── ibalance-change.ts │ ├── icandlestick.ts │ ├── idynamic-strategy.ts │ ├── iexchange-api-error.ts │ ├── iexchange-asset.ts │ ├── iexchange-info.ts │ ├── iexchange-order-book.ts │ ├── ihistorical-candlestick.ts │ ├── ihistorical-count.ts │ ├── ihistorical-instrument.ts │ ├── ihistorical-order-book.ts │ ├── ihistorical-trade.ts │ ├── ilimit-order-status.ts │ ├── ilimit-order.ts │ ├── imanagement-credits.ts │ ├── imanagement-status.ts │ ├── imanagement-usage.ts │ ├── imarket-order-books.ts │ ├── index.ts │ ├── iorder-book-item.ts │ ├── iorder-book.ts │ ├── iprediction-item.ts │ ├── ipredictions.ts │ ├── istatic-strategy.ts │ ├── istrategy.ts │ ├── isubscription-request.ts │ ├── iticker.ts │ ├── itotal-balance-history-item.ts │ ├── itrade-changes.ts │ ├── itrade-fill.ts │ ├── itrade-item.ts │ ├── itrade.ts │ ├── itrading-pair.ts │ ├── itrend.ts │ ├── iuser.ts │ └── iwebsocket-message.ts └── public-api.ts ├── package-lock.json ├── package.json └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | #compiled folders 64 | dist/ 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Benthos Labs, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [DEPRECATED] shrimpy-node 2 | The official Node.js library for the Shrimpy Developer API https://developers.shrimpy.io/docs 3 | 4 | ## Installation 5 | 6 | ```bash 7 | npm install shrimpy-node 8 | ``` 9 | 10 | You can learn about the API responses of each endpoint [by reading our documentation](https://developers.shrimpy.io/docs). 11 | 12 | ## Quick Start 13 | 14 | All asynchronous methods return promises. 15 | 16 | ### Promise Example 17 | 18 | ```js 19 | client 20 | .getTicker('kucoin') 21 | .then(data => { 22 | // do something with the data 23 | }) 24 | .catch(error => { 25 | // handle the error 26 | }); 27 | ``` 28 | 29 | ### Async Example 30 | 31 | The promises can be used as expected in `async` functions in ES2017+ environments: 32 | 33 | ```js 34 | async function yourFunction() { 35 | try { 36 | const ticker = await client.getTicker('kucoin'); 37 | // do something with the data 38 | } catch (error) { 39 | // handle the error 40 | } 41 | } 42 | ``` 43 | 44 | ### Public Client 45 | 46 | ```js 47 | const Shrimpy = require('shrimpy-node'); 48 | const publicClient = new Shrimpy.ShrimpyApiClient(); 49 | ``` 50 | 51 | The public client can only use public methods. 52 | 53 | ### Private Client 54 | 55 | ```js 56 | const publicKey = 'your_public_key'; // e.g. 12326758a39a720e15d064cab3c1f0a9332d107de453bd41926bb3acd565059e 57 | const privateKey = 'your_private_key'; // e.g. 6991cf4c9b518293429db0df6085d1731074bed8abccd7f0279a52fac5b0c1a8a2f6d28e11a50fbb1c6575d1407e637f9ad7c73fbddfa87c5d418fd58971f829 58 | const Shrimpy = require('shrimpy-node'); 59 | const privateClient = new Shrimpy.ShrimpyApiClient(publicKey, privateKey); 60 | ``` 61 | 62 | The private client can use public and private methods. 63 | 64 | ### Public Methods 65 | 66 | * [`getSupportedExchanges`](https://developers.shrimpy.io/docs/#get-supported-exchanges) 67 | 68 | ```js 69 | const supportedExchanges = await client.getSupportedExchanges(); 70 | ``` 71 | 72 | * [`getExchangeAssets`](https://developers.shrimpy.io/docs/#get-exchange-assets) 73 | 74 | ```js 75 | const exchangeAssets = await client.getExchangeAssets( 76 | 'coinbasepro' // exchange 77 | ); 78 | ``` 79 | 80 | * [`getTradingPairs`](https://developers.shrimpy.io/docs/#get-trading-pairs) 81 | 82 | ```js 83 | const tradingPairs = await client.getTradingPairs( 84 | 'coinbasepro' // exchange 85 | ); 86 | ``` 87 | 88 | ### Market Data Methods 89 | 90 | * [`getTicker`](https://developers.shrimpy.io/docs/#get-ticker) 91 | 92 | ```js 93 | const ticker = await client.getTicker( 94 | 'kucoin' // exchange 95 | ); 96 | ``` 97 | 98 | * [`getOrderBooks`](https://developers.shrimpy.io/docs/#get-order-books) 99 | 100 | ```js 101 | const orderBooks = await client.getOrderBooks( 102 | 'bittrex', // exchange 103 | 'XLM', // baseSymbol 104 | 'BTC', // quoteSymbol 105 | 10 // limit 106 | ); 107 | ``` 108 | 109 | * [`getCandles`](https://developers.shrimpy.io/docs/#get-candles) 110 | 111 | ```js 112 | const candles = await client.getCandles( 113 | 'bittrex', // exchange 114 | 'XLM', // baseTradingSymbol 115 | 'BTC', // quoteTradingSymbol 116 | '15m' // interval 117 | ); 118 | ``` 119 | 120 | ### User Methods 121 | 122 | * [`getUsers`](https://developers.shrimpy.io/docs/#list-users) 123 | ```js 124 | const users = await client.getUsers(); 125 | ``` 126 | 127 | * [`getUser`](https://developers.shrimpy.io/docs/#get-a-user) 128 | ```js 129 | const user = await client.getUser( 130 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' //userId 131 | ); 132 | ``` 133 | 134 | * [`createUser`](https://developers.shrimpy.io/docs/#creating-a-user) 135 | ```js 136 | const userId = await client.createUser(); 137 | ``` 138 | 139 | * [`setUserName`](https://developers.shrimpy.io/docs/#naming-a-user) 140 | ```js 141 | await client.setUserName( 142 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', //userId 143 | 'mycustomname' // name 144 | ); 145 | ``` 146 | 147 | * [`removeUser`](https://developers.shrimpy.io/docs/#removing-a-user) 148 | ```js 149 | await client.removeUser( 150 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', //userId 151 | ); 152 | ``` 153 | 154 | * [`enableUser`](https://developers.shrimpy.io/docs/#enabling-a-user) 155 | ```js 156 | await client.enableUser( 157 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' //userId 158 | ); 159 | ``` 160 | 161 | * [`disableUser`](https://developers.shrimpy.io/docs/#disabling-a-user) 162 | ```js 163 | await client.disableUser( 164 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' //userId 165 | ); 166 | ``` 167 | 168 | ### User API Keys Methods 169 | 170 | * [`getApiKeys`](https://developers.shrimpy.io/docs/#get-api-keys) 171 | ```js 172 | const publicKeys = await client.getApiKeys( 173 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' //userId 174 | ); 175 | ``` 176 | 177 | * [`createApiKeys`](https://developers.shrimpy.io/docs/#create-api-keys) 178 | ```js 179 | const apiKeys = await client.createApiKeys( 180 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' // userId 181 | ); 182 | ``` 183 | 184 | * [`deleteApiKeys`](https://developers.shrimpy.io/docs/#delete-api-keys) 185 | ```js 186 | const apiKeys = await client.deleteApiKeys( 187 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 188 | '51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80' // publicKey 189 | ); 190 | ``` 191 | 192 | * [`getPermissions`](https://developers.shrimpy.io/docs/#get-api-key-permissions) 193 | ```js 194 | const permissions = await client.getPermissions( 195 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 196 | '51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80' // publicKey 197 | ); 198 | ``` 199 | 200 | * [`setPermissions`](https://developers.shrimpy.io/docs/#set-api-key-permissions) 201 | ```js 202 | await client.setPermissions( 203 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 204 | '51ac18b7d208f59b3c88acbb1ecefe6ba6be6ea4edc07e7a2450307ddc27ab80', // publicKey 205 | true, // enable account methods 206 | false // enable trading methods 207 | ); 208 | ``` 209 | 210 | ### Account Methods 211 | 212 | * [`getAccounts`](https://developers.shrimpy.io/docs/#list-accounts) 213 | ```js 214 | const accounts = await client.getAccounts( 215 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' // userId 216 | ); 217 | ``` 218 | 219 | * [`getAccount`](https://developers.shrimpy.io/docs/#get-an-account) 220 | ```js 221 | const account = await client.getAccount( 222 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 223 | 123 // accountId 224 | ); 225 | ``` 226 | 227 | * [`createAccount`](https://developers.shrimpy.io/docs/#link-an-exchange-account) 228 | ```js 229 | const accountId = await client.createAccount( 230 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 231 | 'binance', // exchange 232 | 'GOelL5FT6TklPxAzICIQK25aqct52T2lHoKvtcwsFla5sbVXmeePqVJaoXmXI6Qd', // publicKey (a.k.a. apiKey) 233 | 'SelUuFq1sF2zGd97Lmfbb4ghITeziKo9IvM5NltjEdffatRN1N5vfHXIU6dsqRQw' // privateKey (a.k.a. secretKey 234 | ); 235 | ``` 236 | Note: The `createAccount` method accepts a fifth optional parameter: **passphrase**. The passphrase is only required for some exchanges, such as Coinbase Pro. 237 | 238 | * [`deleteAccount`](https://developers.shrimpy.io/docs/#unlink-an-exchange-account) 239 | ```js 240 | await client.deleteAccount( 241 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 242 | 456 // accountId 243 | ); 244 | ``` 245 | 246 | * [`getIpWhitelistAddresses`](https://developers.shrimpy.io/docs/#get-ip-whitelist-addresses) 247 | ```js 248 | const IpAddresses = await client.getIpWhitelistAddresses( 249 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8' // userId 250 | ); 251 | ``` 252 | 253 | ### Trading Methods 254 | 255 | * [`createTrade`](https://developers.shrimpy.io/docs/#creating-a-trade) 256 | ```js 257 | const tradeId = await client.createTrade( 258 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 259 | 123, // accountId 260 | 'BTC', // fromSymbol 261 | 'ETH', // toSymbol 262 | new Decimal('0.01') // amount of fromSymbol 263 | ); 264 | ``` 265 | 266 | * [`getTrade`](https://developers.shrimpy.io/docs/#get-trade-status) 267 | ```js 268 | const trade = await client.getTrade( 269 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 270 | 123, // exchangeAccountId 271 | '72dff099-54c0-4a32-b046-5c19d4f55758' // tradeId 272 | ); 273 | ``` 274 | 275 | * [`getActiveTrades`](https://developers.shrimpy.io/docs/#list-active-trades) 276 | ```js 277 | const activeTrades = await client.getActiveTrades( 278 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 279 | 123, // exchangeAccountId 280 | ); 281 | ``` 282 | 283 | ### Balance Methods 284 | 285 | * [`getBalance`](https://developers.shrimpy.io/docs/#get-balance) 286 | ```js 287 | const balance = await client.getBalance( 288 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 289 | 123 // accountId 290 | ); 291 | ``` 292 | 293 | * [`getTotalBalanceHistory`](https://developers.shrimpy.io/docs/#get-total-balance-history) 294 | ```js 295 | const totalBalanceHistory = await client.getTotalBalanceHistory( 296 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 297 | 123 // accountId 298 | ); 299 | ``` 300 | 301 | ### Asset Management Methods 302 | 303 | * [`rebalance`](https://developers.shrimpy.io/docs/#rebalancing) 304 | ```js 305 | await client.rebalance( 306 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 307 | 123 // accountId 308 | ); 309 | ``` 310 | 311 | * [`getRebalancePeriod`](https://developers.shrimpy.io/docs/#get-the-rebalance-period) 312 | ```js 313 | const rebalancePeriodHours = await client.getRebalancePeriod( 314 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 315 | 123 // accountId 316 | ); 317 | ``` 318 | 319 | * [`setRebalancePeriod`](https://developers.shrimpy.io/docs/#set-the-rebalance-period) 320 | ```js 321 | await client.setRebalancePeriod( 322 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 323 | 123, // accountId 324 | 24 // rebalancePeriod in hours 325 | ); 326 | ``` 327 | 328 | * [`getStrategy`](https://developers.shrimpy.io/docs/#get-the-strategy) 329 | ```js 330 | const strategy = await client.getStrategy( 331 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 332 | 123 // accountId 333 | ); 334 | ``` 335 | 336 | * [`setStrategy`](https://developers.shrimpy.io/docs/#set-the-strategy) 337 | ```js 338 | await client.setStrategy( 339 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 340 | 123, // accountId 341 | { 342 | isDynamic: false, 343 | allocations: [ 344 | { symbol: 'BTC', percent: '50' }, 345 | { symbol: 'ETH', percent: '50' } 346 | ] 347 | } // strategy 348 | ); 349 | ``` 350 | 351 | * [`clearStrategy`](https://developers.shrimpy.io/docs/#clear-the-strategy) 352 | ```js 353 | await client.clearStrategy( 354 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 355 | 123 // accountId 356 | ); 357 | ``` 358 | 359 | * [`allocate`](https://developers.shrimpy.io/docs/#allocating) 360 | ```js 361 | await client.allocate( 362 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 363 | 123, // accountId 364 | { 365 | isDynamic: false, 366 | allocations: [ 367 | { symbol: 'USDT', percent: '100' } 368 | ] 369 | } // strategy 370 | ); 371 | ``` 372 | 373 | ### Limit Order Methods 374 | 375 | * [`createOrder`](https://developers.shrimpy.io/docs/#place-a-limit-order) 376 | ```js 377 | const orderId = await client.createOrder( 378 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 379 | 123, // accountId 380 | 'ETH', // baseSymbol 381 | 'BTC', // quoteSymbol 382 | new Decimal('0.01'), // quantity of baseSymbol 383 | new Decimal('0.026'), // price 384 | 'SELL', // side 385 | 'IOC', // timeInForce 386 | ); 387 | ``` 388 | 389 | * [`getOrder`](https://developers.shrimpy.io/docs/#get-limit-order-status) 390 | ```js 391 | const order = await client.getOrder( 392 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 393 | 123, // accountId 394 | '8c2a9401-eb5b-48eb-9ae2-e9e02c174058' // orderId 395 | ); 396 | ``` 397 | 398 | * [`getOrders`](https://developers.shrimpy.io/docs/#list-open-orders) 399 | ```js 400 | const order = await client.getOrders( 401 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 402 | 123 // accountId 403 | ); 404 | ``` 405 | 406 | * [`cancelOrder`](https://developers.shrimpy.io/docs/#cancel-a-limit-order) 407 | ```js 408 | const order = await client.cancelOrder( 409 | '701e0d16-1e9e-42c9-b6a1-4cada1f395b8', // userId 410 | 123, // accountId 411 | '8c2a9401-eb5b-48eb-9ae2-e9e02c174058' // orderId 412 | ); 413 | ``` 414 | 415 | ### Analytics Methods 416 | 417 | * [`getBacktestAssets`](https://developers.shrimpy.io/docs/#get-backtest-assets) 418 | ```js 419 | const backtestAssets = await client.getBacktestAssets( 420 | 'kucoin' // exchange 421 | ); 422 | ``` 423 | 424 | * [`runBacktest`](https://developers.shrimpy.io/docs/#run-backtest) 425 | ```js 426 | const backtestResults = await client.runBacktest( 427 | 'binance', // exchange 428 | 10, // rebalancePeriod in hours 429 | new Decimal(0.1), // fee in percent 430 | new Date("2018-05-19T00:00:00.000Z"), // startTime 431 | new Date("2018-11-02T00:00:00.000Z"), // endTime 432 | new Decimal(5000), // initialValue in USD 433 | [ 434 | { symbol: "BTC", percent: new Decimal(50) }, 435 | { symbol: "ETH", percent: new Decimal(50) } 436 | ] // allocations 437 | ); 438 | ``` 439 | 440 | * [`predictions`](https://developers.shrimpy.io/docs/#get-predictions) 441 | ```js 442 | const predictions = await client.getPredictions( 443 | 'bittrex', // exchange 444 | 'LTC', // baseSymbol 445 | 'BTC' // quoteSymbol 446 | ) 447 | ``` 448 | 449 | * [`getTrend`](https://developers.shrimpy.io/docs/#trend) 450 | ```js 451 | const trendResults = await client.getTrend( 452 | 'binance', # exchange 453 | 'BTC', # base_symbol 454 | 'BIDR', # quote_symbol 455 | ); 456 | ``` 457 | 458 | ### Insight Methods 459 | 460 | * [`getAssetDominance`](https://developers.shrimpy.io/docs/#get-asset-dominance) 461 | ```js 462 | const assetDominance = await client.getAssetDominance(); 463 | ``` 464 | 465 | * [`getAssetPopularity`](https://developers.shrimpy.io/docs/#get-asset-popularity) 466 | ```js 467 | const assetPopularity = await client.getAssetPopularity(); 468 | ``` 469 | 470 | ### Historical Methods 471 | 472 | * [`getHistoricalCount`](https://developers.shrimpy.io/docs/#get-historical-count) 473 | ```js 474 | const count = await client.getHistoricalCount( 475 | 'trade', // type 476 | 'binance', // exchange 477 | 'LTC', // baseTradingSymbol 478 | 'BTC', // quoteTradingSymbol 479 | new Date("2018-05-19T01:00:00.000Z"), // startTime 480 | new Date("2018-11-02T02:00:00.000Z") // endTime 481 | ); 482 | ``` 483 | 484 | * [`getHistoricalInstruments`](https://developers.shrimpy.io/docs/#get-historical-instruments) 485 | ```js 486 | const instruments = await client.getHistoricalInstruments(); 487 | const bittrexInstruments = await client.getHistoricalInstruments('bittrex'); 488 | ``` 489 | 490 | * [`getHistoricalTrades`](https://developers.shrimpy.io/docs/#get-historical-trades) 491 | ```js 492 | const trades = await client.getHistoricalTrades( 493 | 'binance', // exchange 494 | 'LTC', // baseTradingSymbol 495 | 'BTC', // quoteTradingSymbol 496 | new Date("2018-05-19T00:00:00.000Z"), // startTime 497 | new Date("2018-11-02T00:00:00.000Z"), // endTime 498 | 100 // limit 499 | ); 500 | ``` 501 | 502 | * [`getHistoricalOrderBooks`](https://developers.shrimpy.io/docs/#get-historical-orderbooks) 503 | ```js 504 | const orderbooks = await client.getHistoricalOrderBooks( 505 | 'binance', // exchange 506 | 'LTC', // baseTradingSymbol 507 | 'BTC', // quoteTradingSymbol 508 | new Date("2018-05-19T00:00:00.000Z"), // startTime 509 | new Date("2018-11-02T00:00:00.000Z"), // endTime 510 | 100 // limit 511 | ); 512 | ``` 513 | 514 | ### API Management Methods 515 | 516 | * [`getStatus`](https://developers.shrimpy.io/docs/#get-status) 517 | ```js 518 | const status = await client.getStatus(); 519 | ``` 520 | 521 | * [`getCredits`](https://developers.shrimpy.io/docs/#get-credits) 522 | ```js 523 | const usage = await client.getCredits(); 524 | ``` 525 | 526 | ## Websocket 527 | 528 | Users can access the Shrimpy websocket feed using the [`ShrimpyWsClient`](https://github.com/shrimpy-dev/shrimpy-node/blob/master/lib/client/shrimpy-ws-client.ts) class. A handler must be passed in on subscription 529 | that is responsible for processing incoming messages from the websocket stream. It is recommended that you simply send the message 530 | to another processing thread from your custom handler to prevent blocking the incoming message stream. 531 | 532 | The client handles pings to the Shrimpy server based on the [`API Documentation`](https://developers.shrimpy.io/docs/#websocket) 533 | 534 | 535 | ```js 536 | const Shrimpy = require('shrimpy-node'); 537 | let apiClient = null; 538 | let wsClient = null; 539 | let token = null; 540 | 541 | const publicKey = ""; 542 | const privateKey = ""; 543 | 544 | function handler(msg){ 545 | console.log(msg); 546 | }; 547 | 548 | function subscribeWhenConnected(oData){ 549 | 550 | if (wsClient.getReadyState() === 1) { 551 | console.log("Subcribing to the order book for ETH-BTC"); 552 | wsClient.subscribe(oData, handler); 553 | } else { 554 | console.log("waiting for ws connection..."); 555 | setTimeout(subscribeWhenConnected.bind(null, oData), 1000); 556 | } 557 | 558 | }; 559 | 560 | function unsubscribe(oData){ 561 | console.log("Unsubcribing now"); 562 | wsClient.unsubscribe(oData); 563 | console.log("Stopping the application"); 564 | process.exit(1); 565 | }; 566 | 567 | (async () => { 568 | 569 | apiClient = new Shrimpy.ShrimpyApiClient(publicKey, privateKey); 570 | token = await apiClient.getToken(); 571 | wsClient = new Shrimpy.ShrimpyWsClient(function (error) { 572 | console.error(error); 573 | }, token); 574 | 575 | wsClient.connect(); 576 | subscribeWhenConnected({ 577 | "type": "subscribe", 578 | "pair": "ETH-BTC", 579 | "exchange": "coinbasepro", 580 | "channel": "orderbook" 581 | }); 582 | 583 | setTimeout(unsubscribe.bind(null, { 584 | "type": "unsubscribe", 585 | "pair": "ETH-BTC", 586 | "exchange": "coinbasepro", 587 | "channel": "orderbook" 588 | }), 10000); 589 | 590 | })() 591 | 592 | ``` 593 | -------------------------------------------------------------------------------- /lib/client/authentication-provider.ts: -------------------------------------------------------------------------------- 1 | import * as crypto from 'crypto'; 2 | 3 | export class AuthenticationProvider { 4 | 5 | public readonly publicKey: string; 6 | private _privateKey: Buffer; 7 | 8 | constructor( 9 | publicKey: string, 10 | privateKey: string, 11 | ) { 12 | this.publicKey = publicKey; 13 | // decode the base64 secret 14 | this._privateKey = new Buffer(privateKey, 'base64'); 15 | } 16 | 17 | public sign(prehashString: string): string { 18 | // create a sha256 hmac with the secret 19 | const hmac = crypto.createHmac('sha256', this._privateKey); 20 | 21 | // hash the prehash string and base64 encode the result 22 | return hmac.update(prehashString).digest('base64'); 23 | } 24 | } -------------------------------------------------------------------------------- /lib/client/index.ts: -------------------------------------------------------------------------------- 1 | export * from './authentication-provider'; 2 | export * from './shrimpy-api-client'; 3 | export * from './shrimpy-ws-client'; -------------------------------------------------------------------------------- /lib/client/shrimpy-api-client.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | import * as querystring from 'querystring'; 3 | import * as rp from 'request-promise-native'; 4 | import { AuthenticationProvider } from "./authentication-provider"; 5 | import { 6 | IAccount, 7 | IAccountBalance, 8 | IAllocation, 9 | IApiKeyPermissions, 10 | IApiKeys, 11 | IAssetInsight, 12 | IBacktestAsset, 13 | IBacktestResult, 14 | ICandlestick, 15 | IExchangeAsset, 16 | IExchangeInfo, 17 | IHistoricalCandlestick, 18 | IHistoricalCount, 19 | IHistoricalOrderBook, 20 | IHistoricalInstrument, 21 | IHistoricalTrade, 22 | ILimitOrder, 23 | ILimitOrderStatus, 24 | IManagementCredits, 25 | IManagementStatus, 26 | IManagementUsage, 27 | IMarketOrderBooks, 28 | IPredictions, 29 | IStrategy, 30 | ITicker, 31 | ITotalBalanceHistoryItem, 32 | ITrade, 33 | ITradeChanges, 34 | ITradingPair, 35 | ITrend, 36 | IUser, 37 | } from "../models"; 38 | import { 39 | IAccountBalanceDto, 40 | IAccountDto, 41 | IAllocationDto, 42 | IApiKeyPermissionsDto, 43 | IApiKeysDto, 44 | IAssetInsightDto, 45 | IBacktestResultDto, 46 | IBacktestAssetDto, 47 | ICandlestickDto, 48 | IExchangeAssetDto, 49 | IExchangeInfoDto, 50 | IGuidIdResultDto, 51 | IHistoricalCandlestickDto, 52 | IHistoricalCountDto, 53 | IHistoricalOrderBookDto, 54 | IHistoricalInstrumentDto, 55 | IHistoricalTradeDto, 56 | ILimitOrderDto, 57 | ILimitOrderStatusDto, 58 | IMarketOrderBooksDto, 59 | INumberIdResultDto, 60 | IPredictionsDto, 61 | IRebalancePeriodResultDto, 62 | IStrategyDto, 63 | ITickerDto, 64 | ITotalBalanceHistoryItemDto, 65 | ITradeChangesDto, 66 | ITradeDto, 67 | ITradingPairDto, 68 | ITrendDto, 69 | IUserDto, 70 | IWebsocketTokenDto, 71 | } from "../dtos"; 72 | import { 73 | AccountBalanceDtoConverter, 74 | AllocationDtoConverter, 75 | AssetInsightDtoConverter, 76 | BacktestAssetDtoConverter, 77 | BacktestDataPointDtoConverter, 78 | CandlestickDtoConverter, 79 | DateDtoConverter, 80 | DecimalDtoConverter, 81 | HistoricalCandlestickDtoConverter, 82 | HistoricalOrderBooksDtoConverter, 83 | HistoricalInstrumentsDtoConverter, 84 | HistoricalTradesDtoConverter, 85 | LimitOrderDtoConverter, 86 | LimitOrderStatusDtoConverter, 87 | MarketOrderBooksDtoConverter, 88 | PredictionsDtoConverter, 89 | StrategyDtoConverter, 90 | TickerDtoConverter, 91 | TotalBalanceHistoryItemDtoConverter, 92 | TradeChangesDtoConverter, 93 | TradeDtoConverter, 94 | UserDtoConverter, 95 | TrendDtoConverter, 96 | } from "../dto-converters"; 97 | 98 | export class ShrimpyApiClient { 99 | private _accountBalanceDtoConverter = new AccountBalanceDtoConverter(); 100 | private _allocationDtoConverter = new AllocationDtoConverter(); 101 | private _assetInsightDtoConverter = new AssetInsightDtoConverter(); 102 | private _backtestAssetDtoConveter = new BacktestAssetDtoConverter(); 103 | private _backtestDataPointDtoConverter = new BacktestDataPointDtoConverter(); 104 | private _candlestickDtoConverter = new CandlestickDtoConverter(); 105 | private _dateDtoConverter = new DateDtoConverter(); 106 | private _decimalDtoConverter = new DecimalDtoConverter(); 107 | private _historicalCandlestickDtoConverter = new HistoricalCandlestickDtoConverter(); 108 | private _historicalOrderBooksDtoConverter = new HistoricalOrderBooksDtoConverter(); 109 | private _historicalInstrumentsDtoConverter = new HistoricalInstrumentsDtoConverter(); 110 | private _historicalTradesDtoConverter = new HistoricalTradesDtoConverter(); 111 | private _limitOrderDtoConverter = new LimitOrderDtoConverter(); 112 | private _limitOrderStatusDtoConverter = new LimitOrderStatusDtoConverter(); 113 | private _marketOrderBooksDtoConverter = new MarketOrderBooksDtoConverter(); 114 | private _predictionsDtoConverter = new PredictionsDtoConverter(); 115 | private _strategyDtoConverter = new StrategyDtoConverter(); 116 | private _tickerDtoConverter = new TickerDtoConverter(); 117 | private _totalBalanceHistoryItemDtoConverter = new TotalBalanceHistoryItemDtoConverter(); 118 | private _tradeChangesDtoConverter = new TradeChangesDtoConverter(); 119 | private _tradeDtoConverter = new TradeDtoConverter(); 120 | private _trendDtoConverter = new TrendDtoConverter(); 121 | private _userDtoConverter = new UserDtoConverter(); 122 | 123 | private _authenticationProvider: AuthenticationProvider | null = null; 124 | 125 | constructor( 126 | publicKey?: string, 127 | privateKey?: string, 128 | ) { 129 | if (publicKey && privateKey) { 130 | // keys were supplied, use them 131 | this._setApiCredentials(publicKey, privateKey); 132 | } 133 | } 134 | 135 | /* Public */ 136 | 137 | public async getSupportedExchanges(): Promise { 138 | const endpoint = `list_exchanges`; 139 | return await this._callEndpoint(endpoint, 'GET', null, false); 140 | } 141 | 142 | public async getExchangeAssets(exchange: string): Promise { 143 | const endpoint = `exchanges/${exchange}/assets`; 144 | return await this._callEndpoint(endpoint, 'GET', null, false); 145 | } 146 | 147 | public async getTradingPairs(exchange: string): Promise { 148 | const endpoint = `exchanges/${exchange}/trading_pairs`; 149 | return await this._callEndpoint(endpoint, 'GET', null, false); 150 | } 151 | 152 | /* Market Data */ 153 | 154 | public async getTicker(exchange: string): Promise { 155 | const endpoint = `exchanges/${exchange}/ticker`; 156 | const tickerDtos = await this._callEndpoint(endpoint, 'GET', null, false); 157 | return tickerDtos.map((tickerDto) => { 158 | return this._tickerDtoConverter.convertFromDto(tickerDto); 159 | }); 160 | } 161 | 162 | public async getOrderBooks( 163 | exchange: string | string[], 164 | baseSymbol?: string | string[], 165 | quoteSymbol?: string | string[], 166 | limit?: number 167 | ): Promise { 168 | const endpoint = `orderbooks`; 169 | let exchangeString: string; 170 | if (Array.isArray(exchange)) { 171 | exchangeString = exchange.join(','); 172 | } else { 173 | exchangeString = exchange; 174 | } 175 | const parameters: { exchange: string, baseSymbol?: string, quoteSymbol?: string, limit?: number } = { 176 | exchange: exchangeString 177 | }; 178 | if (baseSymbol) { 179 | if (Array.isArray(baseSymbol)) { 180 | parameters.baseSymbol = baseSymbol.join(','); 181 | } else { 182 | parameters.baseSymbol = baseSymbol; 183 | } 184 | } 185 | if (quoteSymbol) { 186 | if (Array.isArray(quoteSymbol)) { 187 | parameters.quoteSymbol = quoteSymbol.join(','); 188 | } else { 189 | parameters.quoteSymbol = quoteSymbol; 190 | } 191 | } 192 | if (limit) { 193 | parameters.limit = limit; 194 | } 195 | const orderBooksListDto = await this._callEndpoint(endpoint, 'GET', parameters, false); 196 | return orderBooksListDto.map((orderBooksDto) => { 197 | return this._marketOrderBooksDtoConverter.convertFromDto(orderBooksDto); 198 | }); 199 | } 200 | 201 | public async getCandles( 202 | exchange: string, 203 | baseTradingSymbol: string, 204 | quoteTradingSymbol: string, 205 | interval: '1m' | '5m' | '15m' | '1h' | '6h' | '1d', 206 | startTime?: Date, 207 | ): Promise { 208 | const endpoint = `exchanges/${exchange}/candles`; 209 | const parameters: { 210 | baseTradingSymbol: string, 211 | quoteTradingSymbol: string, 212 | interval: string, 213 | startTime?: string, 214 | } = { 215 | baseTradingSymbol: baseTradingSymbol, 216 | quoteTradingSymbol: quoteTradingSymbol, 217 | interval: interval, 218 | }; 219 | if (startTime) { 220 | parameters.startTime = this._dateDtoConverter.convertToDto(startTime); 221 | } 222 | const candlestickDtos = await this._callEndpoint(endpoint, 'GET', parameters, false); 223 | const result: ICandlestick[] = candlestickDtos.map((candlestickDto) => { 224 | return this._candlestickDtoConverter.convertFromDto(candlestickDto); 225 | }); 226 | return result; 227 | } 228 | 229 | /* Users */ 230 | 231 | public async getUsers(): Promise { 232 | const endpoint = 'users'; 233 | const userDtos = await this._callEndpoint(endpoint, 'GET', null, true); 234 | return userDtos.map((userDto) => { 235 | return this._userDtoConverter.convertFromDto(userDto); 236 | }); 237 | } 238 | 239 | public async getUser(userId: string): Promise { 240 | const endpoint = `users/${userId}`; 241 | const userDto = await this._callEndpoint(endpoint, 'GET', null, true); 242 | return this._userDtoConverter.convertFromDto(userDto); 243 | } 244 | 245 | public async createUser(name?: string): Promise { 246 | const endpoint = 'users'; 247 | let parameters: { [key: string]: any } | null = null; 248 | if (name) { 249 | parameters = { name: name }; 250 | } 251 | const result = await this._callEndpoint(endpoint, 'POST', parameters, true); 252 | return result.id; 253 | } 254 | 255 | public async setUserName(userId: string, name: string): Promise { 256 | const endpoint = `users/${userId}/name`; 257 | const parameters: { [key: string]: any } = { 258 | name: name 259 | }; 260 | await this._callEndpoint(endpoint, 'POST', parameters, true); 261 | } 262 | 263 | public async removeUser(userId: string): Promise { 264 | const endpoint = `users/${userId}`; 265 | await this._callEndpoint(endpoint, 'DELETE', {}, true); 266 | } 267 | 268 | public async enableUser(userId: string): Promise { 269 | // Deprecated, this endpoint no longer has any functionality 270 | // It has been preserved to avoid breaking deployments from library upgrades 271 | const endpoint = `users/${userId}/enable`; 272 | await this._callEndpoint(endpoint, 'POST', null, true); 273 | } 274 | 275 | public async disableUser(userId: string): Promise { 276 | // Deprecated, this endpoint no longer has any functionality 277 | // It has been preserved to avoid breaking deployments from library upgrades 278 | const endpoint = `users/${userId}/disable`; 279 | await this._callEndpoint(endpoint, 'POST', null, true); 280 | } 281 | 282 | /* User API Keys */ 283 | 284 | public async getApiKeys(userId: string): Promise { 285 | const endpoint = `users/${userId}/keys`; 286 | return await this._callEndpoint(endpoint, 'GET', null, true); 287 | } 288 | 289 | public async createApiKeys(userId: string): Promise { 290 | const endpoint = `users/${userId}/keys`; 291 | return await this._callEndpoint(endpoint, 'POST', null, true); 292 | } 293 | 294 | public async deleteApiKeys(userId: string, publicKey: string): Promise { 295 | const endpoint = `users/${userId}/keys/${publicKey}`; 296 | return await this._callEndpoint(endpoint, 'DELETE', null, true); 297 | } 298 | 299 | public async getPermissions(userId: string, publicKey: string): Promise { 300 | const endpoint = `users/${userId}/keys/${publicKey}/permissions`; 301 | return await this._callEndpoint(endpoint, 'GET', null, true); 302 | } 303 | 304 | public async setPermissions( 305 | userId: string, 306 | publicKey: string, 307 | account: boolean, 308 | trade: boolean, 309 | ): Promise { 310 | const endpoint = `users/${userId}/keys/${publicKey}/permissions`; 311 | const parameters: IApiKeyPermissionsDto = { 312 | account: account, 313 | trade: trade 314 | }; 315 | await this._callEndpoint(endpoint, 'POST', parameters, true); 316 | } 317 | 318 | /* Accounts */ 319 | 320 | public async getAccounts(userId: string): Promise { 321 | const endpoint = `users/${userId}/accounts`; 322 | return await this._callEndpoint(endpoint, 'GET', null, true); 323 | } 324 | 325 | public async getAccount(userId: string, accountId: number): Promise { 326 | const endpoint = `users/${userId}/accounts/${accountId}`; 327 | return await this._callEndpoint(endpoint, 'GET', null, true); 328 | } 329 | 330 | public async createAccount( 331 | userId: string, 332 | exchange: string, 333 | publicKey: string, 334 | privateKey: string, 335 | passphrase?: string, 336 | ): Promise { 337 | const endpoint = `users/${userId}/accounts`; 338 | const parameters: { [key: string]: any } = { 339 | exchange: exchange, 340 | publicKey: publicKey, 341 | privateKey: privateKey, 342 | passphrase: passphrase, 343 | }; 344 | const result = await this._callEndpoint(endpoint, 'POST', parameters, true); 345 | return result.id; 346 | } 347 | 348 | public async deleteAccount(userId: string, accountId: number): Promise { 349 | const endpoint = `users/${userId}/accounts/${accountId}`; 350 | await this._callEndpoint(endpoint, 'DELETE', null, true); 351 | } 352 | 353 | public async getIpWhitelistAddresses(userId: string): Promise { 354 | const endpoint = `users/${userId}/whitelist`; 355 | return await this._callEndpoint(endpoint, 'GET', null, true); 356 | } 357 | 358 | /* Trading */ 359 | 360 | public async createTrade( 361 | userId: string, 362 | accountId: number, 363 | fromSymbol: string, 364 | toSymbol: string, 365 | amount: Decimal, 366 | smartRouting?: boolean, 367 | maxSpreadPercent?: Decimal, 368 | maxSlippagePercent?: Decimal, 369 | ): Promise { 370 | const endpoint = `users/${userId}/accounts/${accountId}/trades`; 371 | let parameters: { 372 | fromSymbol: string, 373 | toSymbol: string, 374 | amount: string, 375 | smartRouting?: boolean, 376 | maxSpreadPercent?: string, 377 | maxSlippagePercent?: string, 378 | } = { 379 | fromSymbol: fromSymbol, 380 | toSymbol: toSymbol, 381 | amount: this._decimalDtoConverter.convertToDto(amount), 382 | }; 383 | if (smartRouting) { 384 | parameters.smartRouting = smartRouting; 385 | } 386 | if (maxSpreadPercent) { 387 | parameters.maxSpreadPercent = this._decimalDtoConverter.convertToDto(maxSpreadPercent); 388 | } 389 | if (maxSlippagePercent) { 390 | parameters.maxSlippagePercent = this._decimalDtoConverter.convertToDto(maxSlippagePercent); 391 | } 392 | const result = await this._callEndpoint(endpoint, 'POST', parameters, true); 393 | return result.id; 394 | } 395 | 396 | public async getTrade( 397 | userId: string, 398 | accountId: number, 399 | tradeId: string, 400 | ): Promise { 401 | const endpoint = `users/${userId}/accounts/${accountId}/trades/${tradeId}`; 402 | const tradeChangesDto = await this._callEndpoint(endpoint, 'GET', null, true); 403 | return this._tradeChangesDtoConverter.convertFromDto(tradeChangesDto); 404 | } 405 | 406 | public async getActiveTrades(userId: string, accountId: number): Promise { 407 | const endpoint = `users/${userId}/accounts/${accountId}/trades`; 408 | const tradeDtos = await this._callEndpoint(endpoint, 'GET', null, true); 409 | return tradeDtos.map((tradeDto) => { 410 | return this._tradeDtoConverter.convertFromDto(tradeDto); 411 | }); 412 | } 413 | 414 | /* Balances */ 415 | 416 | public async getBalance( 417 | userId: string, 418 | accountId: number, 419 | date?: Date 420 | ): Promise { 421 | const endpoint = `users/${userId}/accounts/${accountId}/balance`; 422 | let parameters: { date: string } | null = null; 423 | if (date) { 424 | parameters = { date: this._dateDtoConverter.convertToDto(date) }; 425 | } 426 | const accountBalanceDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 427 | return this._accountBalanceDtoConverter.convertFromDto(accountBalanceDto); 428 | } 429 | 430 | public async getTotalBalanceHistory( 431 | userId: string, 432 | accountId: number, 433 | startTime: Date | null, 434 | endTime: Date | null 435 | ): Promise { 436 | const endpoint = `users/${userId}/accounts/${accountId}/total_balance_history`; 437 | let parameters: { 438 | startTime?: string, 439 | endTime?: string 440 | } | null = null; 441 | if (startTime || endTime) { 442 | parameters = {}; 443 | if (startTime) { 444 | parameters.startTime = this._dateDtoConverter.convertToDto(startTime); 445 | } 446 | if (endTime) { 447 | parameters.endTime = this._dateDtoConverter.convertToDto(endTime); 448 | } 449 | } 450 | const totalBalanceHistoryDtos = await this._callEndpoint(endpoint, 'GET', parameters, true); 451 | return totalBalanceHistoryDtos.map((totalBalanceHistoryDto) => { 452 | return this._totalBalanceHistoryItemDtoConverter.convertFromDto(totalBalanceHistoryDto); 453 | }); 454 | } 455 | 456 | /* Asset Management */ 457 | 458 | public async rebalance(userId: string, accountId: number): Promise { 459 | const endpoint = `users/${userId}/accounts/${accountId}/rebalance`; 460 | await this._callEndpoint(endpoint, 'POST', null, true); 461 | } 462 | 463 | public async getRebalancePeriod(userId: string, accountId: number): Promise { 464 | const endpoint = `users/${userId}/accounts/${accountId}/rebalance_period`; 465 | const result = await this._callEndpoint(endpoint, 'GET', null, true); 466 | return result.rebalancePeriod; 467 | } 468 | 469 | public async setRebalancePeriod( 470 | userId: string, 471 | accountId: number, 472 | rebalancePeriodHours: number 473 | ): Promise { 474 | // verify rebalancePeriodHours is an integer 475 | if (!Number.isInteger(rebalancePeriodHours)) { 476 | throw new Error("Invalid rebalance period. Rebalance period must be an integer"); 477 | } 478 | const endpoint = `users/${userId}/accounts/${accountId}/rebalance_period`; 479 | const parameters: { rebalancePeriod: number } = { 480 | rebalancePeriod: rebalancePeriodHours 481 | }; 482 | await this._callEndpoint(endpoint, 'POST', parameters, true); 483 | } 484 | 485 | public async getStrategy( 486 | userId: string, 487 | accountId: number, 488 | ): Promise { 489 | const endpoint = `users/${userId}/accounts/${accountId}/strategy`; 490 | const strategyDto = await this._callEndpoint(endpoint, 'GET', null, true); 491 | return this._strategyDtoConverter.convertFromDto(strategyDto); 492 | } 493 | 494 | public async setStrategy( 495 | userId: string, 496 | accountId: number, 497 | strategy: IStrategy, 498 | ): Promise { 499 | const endpoint = `users/${userId}/accounts/${accountId}/strategy`; 500 | let parameters: IStrategyDto = this._strategyDtoConverter.convertToDto(strategy); 501 | await this._callEndpoint(endpoint, 'POST', parameters, true); 502 | } 503 | 504 | public async clearStrategy( 505 | userId: string, 506 | accountId: number, 507 | ): Promise { 508 | const endpoint = `users/${userId}/accounts/${accountId}/strategy`; 509 | await this._callEndpoint(endpoint, 'DELETE', null, true); 510 | } 511 | 512 | public async allocate( 513 | userId: string, 514 | accountId: number, 515 | strategy: IStrategy, 516 | ): Promise { 517 | const endpoint = `users/${userId}/accounts/${accountId}/allocate`; 518 | let parameters: IStrategyDto = this._strategyDtoConverter.convertToDto(strategy); 519 | await this._callEndpoint(endpoint, 'POST', parameters, true); 520 | } 521 | 522 | /* Limit Orders */ 523 | 524 | public async createOrder( 525 | userId: string, 526 | accountId: number, 527 | baseSymbol: string, 528 | quoteSymbol: string, 529 | quantity: Decimal, 530 | price: Decimal, 531 | side: "BUY" | "SELL", 532 | timeInForce: "GTC" | "IOC" 533 | ): Promise { 534 | const endpoint = `users/${userId}/accounts/${accountId}/orders`; 535 | let parameters: { baseSymbol: string, quoteSymbol: string, quantity: string, price: string, side: string, timeInForce: string } = { 536 | baseSymbol: baseSymbol, 537 | quoteSymbol: quoteSymbol, 538 | quantity: this._decimalDtoConverter.convertToDto(quantity), 539 | price: this._decimalDtoConverter.convertToDto(price), 540 | side: side, 541 | timeInForce: timeInForce 542 | }; 543 | const result = await this._callEndpoint(endpoint, 'POST', parameters, true); 544 | return result.id; 545 | } 546 | 547 | public async getOrder( 548 | userId: string, 549 | accountId: number, 550 | orderId: string 551 | ): Promise { 552 | const endpoint = `users/${userId}/accounts/${accountId}/orders/${orderId}`; 553 | const limitOrderStatusDto = await this._callEndpoint(endpoint, 'GET', null, true); 554 | return this._limitOrderStatusDtoConverter.convertFromDto(limitOrderStatusDto); 555 | } 556 | 557 | public async getOrders( 558 | userId: string, 559 | accountId: number 560 | ): Promise { 561 | const endpoint = `users/${userId}/accounts/${accountId}/orders`; 562 | const limitOrderDtos = await this._callEndpoint(endpoint, 'GET', null, true); 563 | return limitOrderDtos.map((limitOrderDto) => { 564 | return this._limitOrderDtoConverter.convertFromDto(limitOrderDto); 565 | }); 566 | } 567 | 568 | public async cancelOrder( 569 | userId: string, 570 | accountId: number, 571 | orderId: string 572 | ): Promise { 573 | const endpoint = `users/${userId}/accounts/${accountId}/orders/${orderId}`; 574 | await this._callEndpoint(endpoint, 'DELETE', null, true); 575 | } 576 | 577 | /* Analytics */ 578 | 579 | public async getBacktestAssets( 580 | exchange: string, 581 | startTime?: Date, 582 | endTime?: Date 583 | ): Promise { 584 | const endpoint = `analytics/backtest/${exchange}/assets`; 585 | const parameters: { startTime?: string, endTime?: string } = {}; 586 | if (startTime) { 587 | parameters.startTime = this._dateDtoConverter.convertToDto(startTime); 588 | } 589 | if (endTime) { 590 | parameters.endTime = this._dateDtoConverter.convertToDto(endTime); 591 | } 592 | const backtestAssetDtos = await this._callEndpoint(endpoint, 'GET', parameters, true); 593 | const result: IBacktestAsset[] = backtestAssetDtos.map((backtestAssetDto) => { 594 | return this._backtestAssetDtoConveter.convertFromDto(backtestAssetDto); 595 | }); 596 | return result; 597 | } 598 | 599 | public async runBacktest( 600 | exchange: string, 601 | rebalancePeriodHours: number, 602 | fee: Decimal, 603 | startTime: Date, 604 | endTime: Date, 605 | initialValue: Decimal, 606 | allocations: IAllocation[] 607 | ): Promise { 608 | const endpoint = `analytics/backtest/${exchange}/run`; 609 | const allocationsDto = allocations.map((allocation) => { 610 | return this._allocationDtoConverter.convertToDto(allocation); 611 | }); 612 | const parameters: { 613 | rebalancePeriod: number, 614 | fee: string, 615 | startTime: string, 616 | endTime: string, 617 | initialValue: string, 618 | allocations: IAllocationDto[] 619 | } = { 620 | rebalancePeriod: rebalancePeriodHours, 621 | fee: fee.toString(), 622 | startTime: this._dateDtoConverter.convertToDto(startTime), 623 | endTime: this._dateDtoConverter.convertToDto(endTime), 624 | initialValue: initialValue.toString(), 625 | allocations: allocationsDto, 626 | }; 627 | const resultDto = await this._callEndpoint(endpoint, 'POST', parameters, true); 628 | const rebalanceData = resultDto.rebalanceData.map((dataPointDto) => { 629 | return this._backtestDataPointDtoConverter.convertFromDto(dataPointDto); 630 | }); 631 | const holdingData = resultDto.holdingData.map((dataPointDto) => { 632 | return this._backtestDataPointDtoConverter.convertFromDto(dataPointDto); 633 | }); 634 | const result: IBacktestResult = { 635 | rebalanceData: rebalanceData, 636 | holdingData: holdingData, 637 | }; 638 | return result; 639 | } 640 | 641 | public async getPredictions( 642 | exchange: string, 643 | baseTradingSymbol: string, 644 | quoteTradingSymbol: string 645 | ): Promise { 646 | const endpoint = `analytics/predict`; 647 | const parameters: { 648 | exchange: string, 649 | baseTradingSymbol: string, 650 | quoteTradingSymbol: string 651 | } = { 652 | exchange: exchange, 653 | baseTradingSymbol: baseTradingSymbol, 654 | quoteTradingSymbol: quoteTradingSymbol 655 | } 656 | 657 | const predictionsListDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 658 | return this._predictionsDtoConverter.convertFromDto(predictionsListDto); 659 | } 660 | 661 | public async getTrend( 662 | exchange: string, 663 | baseTradingSymbol: string, 664 | quoteTradingSymbol: string 665 | ): Promise { 666 | const endpoint = `analytics/trend`; 667 | const parameters: { 668 | exchange: string, 669 | baseTradingSymbol: string, 670 | quoteTradingSymbol: string 671 | } = { 672 | exchange: exchange, 673 | baseTradingSymbol: baseTradingSymbol, 674 | quoteTradingSymbol: quoteTradingSymbol 675 | } 676 | 677 | const trendDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 678 | return this._trendDtoConverter.convertFromDto(trendDto); 679 | } 680 | 681 | /* Insights */ 682 | 683 | public async getAssetDominance(): Promise { 684 | const endpoint = `insights/asset_dominance`; 685 | const assetInsightDtos = await this._callEndpoint(endpoint, 'GET', null, true); 686 | return assetInsightDtos.map((assetInsightDto) => { 687 | return this._assetInsightDtoConverter.convertFromDto(assetInsightDto); 688 | }); 689 | } 690 | 691 | public async getAssetPopularity(): Promise { 692 | const endpoint = `insights/asset_popularity`; 693 | const assetInsightDtos = await this._callEndpoint(endpoint, 'GET', null, true); 694 | return assetInsightDtos.map((assetInsightDto) => { 695 | return this._assetInsightDtoConverter.convertFromDto(assetInsightDto); 696 | }); 697 | } 698 | 699 | /* Historical */ 700 | 701 | public async getHistoricalTrades( 702 | exchange: string, 703 | baseTradingSymbol: string, 704 | quoteTradingSymbol: string, 705 | startTime: Date, 706 | endTime: Date, 707 | limit: number 708 | ): Promise { 709 | const endpoint = `historical/trades`; 710 | const parameters: { 711 | exchange: string, 712 | baseTradingSymbol: string, 713 | quoteTradingSymbol: string, 714 | startTime: string, 715 | endTime: string, 716 | limit: number, 717 | } = { 718 | exchange: exchange, 719 | baseTradingSymbol: baseTradingSymbol, 720 | quoteTradingSymbol: quoteTradingSymbol, 721 | startTime: this._dateDtoConverter.convertToDto(startTime), 722 | endTime: this._dateDtoConverter.convertToDto(endTime), 723 | limit: limit, 724 | }; 725 | const resultDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 726 | 727 | return this._historicalTradesDtoConverter.convertFromDto(resultDto); 728 | } 729 | 730 | public async getHistoricalOrderBooks( 731 | exchange: string, 732 | baseTradingSymbol: string, 733 | quoteTradingSymbol: string, 734 | startTime: Date, 735 | endTime: Date, 736 | limit: number 737 | ): Promise { 738 | const endpoint = `historical/orderbooks`; 739 | const parameters: { 740 | exchange: string, 741 | baseTradingSymbol: string, 742 | quoteTradingSymbol: string, 743 | startTime: string, 744 | endTime: string, 745 | limit: number, 746 | } = { 747 | exchange: exchange, 748 | baseTradingSymbol: baseTradingSymbol, 749 | quoteTradingSymbol: quoteTradingSymbol, 750 | startTime: this._dateDtoConverter.convertToDto(startTime), 751 | endTime: this._dateDtoConverter.convertToDto(endTime), 752 | limit: limit, 753 | }; 754 | const resultDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 755 | 756 | return this._historicalOrderBooksDtoConverter.convertFromDto(resultDto); 757 | } 758 | 759 | public async getHistoricalCandles( 760 | exchange: string, 761 | baseTradingSymbol: string, 762 | quoteTradingSymbol: string, 763 | startTime: Date, 764 | endTime: Date, 765 | limit: number, 766 | interval: '1m' | '5m' | '15m' | '1h' | '6h' | '1d' 767 | ): Promise { 768 | const endpoint = `historical/candles`; 769 | const parameters: { 770 | exchange: string, 771 | baseTradingSymbol: string, 772 | quoteTradingSymbol: string, 773 | startTime: string, 774 | endTime: string, 775 | limit: number, 776 | interval: '1m' | '5m' | '15m' | '1h' | '6h' | '1d' 777 | } = { 778 | exchange: exchange, 779 | baseTradingSymbol: baseTradingSymbol, 780 | quoteTradingSymbol: quoteTradingSymbol, 781 | startTime: this._dateDtoConverter.convertToDto(startTime), 782 | endTime: this._dateDtoConverter.convertToDto(endTime), 783 | limit: limit, 784 | interval: interval 785 | }; 786 | const resultDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 787 | const result = resultDto.map((candlestick) => { 788 | return this._historicalCandlestickDtoConverter.convertFromDto(candlestick); 789 | }); 790 | 791 | return result; 792 | } 793 | 794 | public async getHistoricalInstruments( 795 | exchange?: string, 796 | baseTradingSymbol?: string, 797 | quoteTradingSymbol?: string 798 | ): Promise { 799 | const endpoint = `historical/instruments`; 800 | const parameters: { 801 | exchange?: string, 802 | baseTradingSymbol?: string, 803 | quoteTradingSymbol?: string 804 | } = { 805 | exchange: exchange, 806 | baseTradingSymbol: baseTradingSymbol, 807 | quoteTradingSymbol: quoteTradingSymbol 808 | }; 809 | 810 | const resultDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 811 | 812 | return this._historicalInstrumentsDtoConverter.convertFromDto(resultDto); 813 | } 814 | 815 | public async getHistoricalCount( 816 | type: 'trade' | 'orderbook', 817 | exchange: string, 818 | baseTradingSymbol: string, 819 | quoteTradingSymbol: string, 820 | startTime: Date, 821 | endTime: Date 822 | ): Promise { 823 | const endpoint = `historical/count`; 824 | const parameters: { 825 | type: string, 826 | exchange: string, 827 | baseTradingSymbol: string, 828 | quoteTradingSymbol: string, 829 | startTime: string, 830 | endTime: string 831 | } = { 832 | type: type, 833 | exchange: exchange, 834 | baseTradingSymbol: baseTradingSymbol, 835 | quoteTradingSymbol: quoteTradingSymbol, 836 | startTime: this._dateDtoConverter.convertToDto(startTime), 837 | endTime: this._dateDtoConverter.convertToDto(endTime) 838 | }; 839 | const countDto = await this._callEndpoint(endpoint, 'GET', parameters, true); 840 | const result: IHistoricalCount = { 841 | count: countDto.count 842 | }; 843 | 844 | return result; 845 | } 846 | 847 | /* Management */ 848 | 849 | public async getStatus(): Promise { 850 | const endpoint = `management/status`; 851 | return await this._callEndpoint(endpoint, 'GET', null, true); 852 | } 853 | 854 | public async getCredits(): Promise { 855 | const endpoint = `management/credits`; 856 | return await this._callEndpoint(endpoint, 'GET', null, true); 857 | } 858 | 859 | public async getUsage(): Promise { 860 | // Deprecated, this endpoint no longer has any functionality 861 | // It has been preserved to avoid breaking deployments from library upgrades 862 | const endpoint = `management/usage`; 863 | return await this._callEndpoint(endpoint, 'GET', null, true); 864 | } 865 | 866 | /* WebSocket */ 867 | 868 | public async getToken(): Promise { 869 | const endpoint = `ws/token`; 870 | const websocketTokenResult = await this._callEndpoint(endpoint, 'GET', null, true); 871 | 872 | return websocketTokenResult.token; 873 | } 874 | 875 | /* private methods */ 876 | 877 | private _setApiCredentials(publicKey: string, privateKey: string): void { 878 | this._authenticationProvider = new AuthenticationProvider(publicKey, privateKey); 879 | } 880 | 881 | private async _callEndpoint( 882 | endPoint: string, 883 | method: 'GET' | 'POST' | 'DELETE', 884 | parameters: { [key: string]: any } | null, 885 | isSignRequired: boolean 886 | ): Promise { 887 | let requestPath = "/v1/" + endPoint; 888 | let options: rp.OptionsWithUri & { headers: { [key: string]: any }} = { 889 | uri: "https://dev-api.shrimpy.io" + requestPath, 890 | headers: { 891 | 'content-type': 'application/json', 892 | }, 893 | method: method 894 | }; 895 | 896 | if (method === 'GET' && parameters && Object.keys(parameters).length > 0) { 897 | const qs = '?' + querystring.stringify(parameters); 898 | options.uri += qs; 899 | requestPath += qs; 900 | } 901 | 902 | if (method === 'POST') { 903 | if (parameters) { 904 | // only attach the body if there are parameters 905 | // no parameters, send empty body 906 | options.body = JSON.stringify(parameters); 907 | } else { 908 | options.body = ""; 909 | } 910 | } 911 | 912 | if (isSignRequired && !this._authenticationProvider) { 913 | throw new Error(`Cannot send a request to ${endPoint} without api keys. Make sure to pass api keys to the ShrimpyApiClient constructor.`); 914 | } 915 | 916 | if (this._authenticationProvider) { 917 | const nonce = Date.now(); 918 | const bodyString = options.body ? options.body : ""; 919 | const prehashString = requestPath + method + nonce + bodyString; 920 | const signature = this._authenticationProvider.sign(prehashString); 921 | options.headers['DEV-SHRIMPY-API-KEY'] = this._authenticationProvider.publicKey; 922 | options.headers['DEV-SHRIMPY-API-NONCE'] = nonce; 923 | options.headers['DEV-SHRIMPY-API-SIGNATURE'] = signature; 924 | } 925 | 926 | const response: string = await rp(options); 927 | return JSON.parse(response); 928 | } 929 | } 930 | -------------------------------------------------------------------------------- /lib/client/shrimpy-ws-client.ts: -------------------------------------------------------------------------------- 1 | import * as WebSocket from 'ws'; 2 | import { ISubscriptionRequest, IWebsocketMessage, IPingMessage, IErrorMessage } from '../models'; 3 | 4 | 5 | export class ShrimpyWsClient { 6 | private _baseUrl = 'wss://ws-feed.shrimpy.io'; 7 | private _token = ""; 8 | 9 | private _websocket: WebSocket | undefined = undefined; 10 | 11 | private _subscriptionCallbacks: { 12 | [subscription: string]: (data: IWebsocketMessage) => void 13 | } = {}; 14 | private _websocketErrorCallback: (error: IErrorMessage) => void; 15 | 16 | constructor (errorCallback: (error: IErrorMessage) => void, token: string = "") { 17 | let url = this._baseUrl; 18 | if (token) { 19 | this._token = token; 20 | url = this._baseUrl + "?token=" + this._token; 21 | } 22 | this._websocketErrorCallback = errorCallback; 23 | this._websocket = new WebSocket(url); 24 | } 25 | 26 | public connect() { 27 | 28 | if (this._websocket == undefined) { 29 | return; 30 | } 31 | 32 | this._websocket.on('open', function open() { 33 | // Open the connection 34 | }); 35 | 36 | this._websocket.on('error', (error: Error) => { 37 | const wsError : IErrorMessage = { 38 | 'type' : 'WebsocketClientError', 39 | 'code' : 2404, 40 | 'message' : error.message 41 | }; 42 | this._websocketErrorCallback(wsError); 43 | }); 44 | 45 | this._websocket.on('message', (message) => { 46 | const parsedMessage: IWebsocketMessage = JSON.parse(message.toString()); 47 | const topic = this._getTopic(parsedMessage); 48 | 49 | if (topic === 'ping') { 50 | // Handle Ping 51 | this._pong(parsedMessage as IPingMessage); 52 | return; 53 | } 54 | 55 | if (topic === 'error') { 56 | this._websocketErrorCallback(parsedMessage as IErrorMessage); 57 | return; 58 | } 59 | 60 | const successCallback = this._subscriptionCallbacks[topic]; 61 | if (successCallback !== undefined) { 62 | successCallback(parsedMessage); 63 | } 64 | }); 65 | 66 | this._websocket.on('close', () => { 67 | // Connection has been closed, delete all callbacks 68 | this._subscriptionCallbacks = {}; 69 | }); 70 | } 71 | 72 | public disconnect() { 73 | if (this._websocket !== undefined) { 74 | this._websocket.close(); 75 | } 76 | } 77 | 78 | public forceDisconnect() { 79 | if (this._websocket !== undefined) { 80 | this._websocket.terminate(); 81 | } 82 | } 83 | 84 | public reconnect(token: string = "") { 85 | let url = this._baseUrl; 86 | if (token) { 87 | this._token = token; 88 | url = this._baseUrl + "?token=" + this._token; 89 | } 90 | this.forceDisconnect(); 91 | this._websocket = new WebSocket(url); 92 | this.connect(); 93 | } 94 | 95 | public subscribe( 96 | subscriptionRequest: ISubscriptionRequest, 97 | successCallback: (data: IWebsocketMessage) => void, 98 | ) { 99 | if (this._websocket == undefined) { 100 | return; 101 | } 102 | 103 | if (this._websocket.OPEN == this._websocket.readyState) { 104 | const topic = this._getTopic(subscriptionRequest); 105 | this._subscriptionCallbacks[topic] = successCallback; 106 | this._websocket.send(JSON.stringify(subscriptionRequest)); 107 | } 108 | } 109 | 110 | public unsubscribe( 111 | unsubscriptionRequest: ISubscriptionRequest 112 | ) { 113 | const topic = this._getTopic(unsubscriptionRequest); 114 | delete this._subscriptionCallbacks[topic]; 115 | 116 | if (this._websocket == undefined) { 117 | return; 118 | } 119 | 120 | if (this._websocket.OPEN == this._websocket.readyState) { 121 | this._websocket.send(JSON.stringify(unsubscriptionRequest)); 122 | } 123 | } 124 | 125 | public getReadyState(): number { 126 | if (this._websocket == undefined) { 127 | return WebSocket.CLOSED; 128 | } 129 | 130 | return this._websocket.readyState; 131 | } 132 | 133 | private _getTopic(message: any): string { 134 | 135 | if (message.hasOwnProperty('type')) { 136 | const messageType = message['type']; 137 | if (messageType.indexOf('subscribe') === -1) { 138 | return messageType.toLowerCase(); 139 | } 140 | } 141 | 142 | const exchange = message['exchange']; 143 | const pair = message['pair']; 144 | const channel = message['channel']; 145 | 146 | const rawKeys = [exchange.toLowerCase(), pair.toLowerCase(), channel.toLowerCase()]; 147 | const nonNullKeys = rawKeys.filter((k) => { 148 | return k !== undefined; 149 | }); 150 | 151 | return nonNullKeys.join('-'); 152 | } 153 | 154 | private _pong(parsedData: IPingMessage) { 155 | 156 | if (this._websocket == undefined) { 157 | return; 158 | } 159 | 160 | const pong = { 161 | 'type': 'pong', 162 | 'data': parsedData.data 163 | }; 164 | this._websocket.send(JSON.stringify(pong)); 165 | } 166 | } -------------------------------------------------------------------------------- /lib/dto-converters/account-balance-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IAccountBalanceDto } from "../dtos"; 3 | import { IAccountBalance } from "../models"; 4 | import { AssetBalanceDtoConverter } from "./asset-balance-dto-converter"; 5 | import { NullableDateDtoConverter } from "./nullable-date-dto-converter"; 6 | 7 | export class AccountBalanceDtoConverter implements IDtoConverter { 8 | private _assetBalanceDtoConverter = new AssetBalanceDtoConverter(); 9 | private _nullableDateDtoConverter = new NullableDateDtoConverter(); 10 | 11 | public convertFromDto(dto: IAccountBalanceDto): IAccountBalance { 12 | const balances = dto.balances.map((assetBalancDto) => { 13 | return this._assetBalanceDtoConverter.convertFromDto(assetBalancDto); 14 | }); 15 | const result: IAccountBalance = { 16 | balances: balances, 17 | retrievedAt: this._nullableDateDtoConverter.convertFromDto(dto.retrievedAt), 18 | }; 19 | return result; 20 | } 21 | 22 | public convertToDto(model: IAccountBalance): IAccountBalanceDto { 23 | const balanceDtos = model.balances.map((assetBalance) => { 24 | return this._assetBalanceDtoConverter.convertToDto(assetBalance); 25 | }); 26 | const result: IAccountBalanceDto = { 27 | balances: balanceDtos, 28 | retrievedAt: this._nullableDateDtoConverter.convertToDto(model.retrievedAt), 29 | }; 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/dto-converters/allocation-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IAllocationDto } from "../dtos"; 3 | import { IAllocation } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | 6 | export class AllocationDtoConverter implements IDtoConverter { 7 | private _decimalDtoConverter = new DecimalDtoConverter(); 8 | 9 | public convertFromDto(dto: IAllocationDto): IAllocation { 10 | const result: IAllocation = { 11 | percent: this._decimalDtoConverter.convertFromDto(dto.percent), 12 | symbol: dto.symbol, 13 | }; 14 | return result; 15 | } 16 | 17 | public convertToDto(model: IAllocation): IAllocationDto { 18 | const result: IAllocationDto = { 19 | percent: this._decimalDtoConverter.convertToDto(model.percent), 20 | symbol: model.symbol, 21 | }; 22 | return result; 23 | } 24 | } -------------------------------------------------------------------------------- /lib/dto-converters/asset-balance-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IAssetBalanceDto } from "../dtos"; 3 | import { IAssetBalance } from "../models"; 4 | 5 | export class AssetBalanceDtoConverter implements IDtoConverter { 6 | 7 | public convertFromDto(dto: IAssetBalanceDto): IAssetBalance { 8 | const result: IAssetBalance = { 9 | btcValue: dto.btcValue, 10 | nativeValue: dto.nativeValue, 11 | symbol: dto.symbol, 12 | usdValue: dto.usdValue, 13 | }; 14 | return result; 15 | } 16 | 17 | public convertToDto(model: IAssetBalance): IAssetBalanceDto { 18 | const result: IAssetBalanceDto = { 19 | btcValue: model.btcValue, 20 | nativeValue: model.nativeValue, 21 | symbol: model.symbol, 22 | usdValue: model.usdValue, 23 | }; 24 | return result; 25 | } 26 | } -------------------------------------------------------------------------------- /lib/dto-converters/asset-insight-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IAssetInsightDto } from "../dtos"; 3 | import { IAssetInsight } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | import { NullableDecimalDtoConverter } from "./nullable-decimal-dto-converter"; 6 | 7 | export class AssetInsightDtoConverter implements IDtoConverter { 8 | private _nullableDecimalDtoConverter = new NullableDecimalDtoConverter(); 9 | private _decimalDtoConverter = new DecimalDtoConverter(); 10 | 11 | public convertFromDto(dto: IAssetInsightDto): IAssetInsight { 12 | const result: IAssetInsight = { 13 | id: dto.id, 14 | percent: this._decimalDtoConverter.convertFromDto(dto.percent), 15 | change24h: this._nullableDecimalDtoConverter.convertFromDto(dto.change24h), 16 | change7d: this._nullableDecimalDtoConverter.convertFromDto(dto.change7d), 17 | change30d: this._nullableDecimalDtoConverter.convertFromDto(dto.change30d), 18 | }; 19 | return result; 20 | } 21 | 22 | public convertToDto(model: IAssetInsight): IAssetInsightDto { 23 | const result: IAssetInsightDto = { 24 | id: model.id, 25 | percent: this._decimalDtoConverter.convertToDto(model.percent), 26 | change24h: this._nullableDecimalDtoConverter.convertToDto(model.change24h), 27 | change7d: this._nullableDecimalDtoConverter.convertToDto(model.change7d), 28 | change30d: this._nullableDecimalDtoConverter.convertToDto(model.change30d), 29 | }; 30 | return result; 31 | } 32 | } -------------------------------------------------------------------------------- /lib/dto-converters/backtest-asset-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IBacktestAssetDto } from "../dtos"; 3 | import { IBacktestAsset } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | 6 | export class BacktestAssetDtoConverter implements IDtoConverter { 7 | private _dateDtoConverter: DateDtoConverter = new DateDtoConverter(); 8 | 9 | public convertFromDto(dto: IBacktestAssetDto): IBacktestAsset { 10 | const result: IBacktestAsset = { 11 | symbol: dto.symbol, 12 | endTime: this._dateDtoConverter.convertFromDto(dto.endTime), 13 | startTime: this._dateDtoConverter.convertFromDto(dto.startTime), 14 | }; 15 | return result; 16 | } 17 | 18 | public convertToDto(model: IBacktestAsset): IBacktestAssetDto { 19 | const result: IBacktestAssetDto = { 20 | symbol: model.symbol, 21 | endTime: this._dateDtoConverter.convertToDto(model.endTime), 22 | startTime: this._dateDtoConverter.convertToDto(model.startTime), 23 | }; 24 | return result; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/dto-converters/backtest-data-point-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IBacktestDataPointDto } from "../dtos"; 3 | import { IBacktestDataPoint } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | 6 | export class BacktestDataPointDtoConverter implements IDtoConverter { 7 | private _dateDtoConverter: DateDtoConverter = new DateDtoConverter(); 8 | 9 | public convertFromDto(dto: IBacktestDataPointDto): IBacktestDataPoint { 10 | const result: IBacktestDataPoint = { 11 | time: this._dateDtoConverter.convertFromDto(dto.time), 12 | usdValue: dto.usdValue, 13 | }; 14 | return result; 15 | } 16 | 17 | public convertToDto(model: IBacktestDataPoint): IBacktestDataPointDto { 18 | const result: IBacktestDataPointDto = { 19 | time: this._dateDtoConverter.convertToDto(model.time), 20 | usdValue: model.usdValue, 21 | }; 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/dto-converters/balance-change-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IBalanceChangeDto } from "../dtos"; 3 | import { IBalanceChange } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | 6 | export class BalanceChangeDtoConverter implements IDtoConverter { 7 | private _decimalDtoConverter = new DecimalDtoConverter(); 8 | 9 | public convertFromDto(dto: IBalanceChangeDto): IBalanceChange { 10 | const result: IBalanceChange = { 11 | btcValue: dto.btcValue, 12 | nativeValue: this._decimalDtoConverter.convertFromDto(dto.nativeValue), 13 | symbol: dto.symbol, 14 | usdValue: dto.usdValue, 15 | }; 16 | return result; 17 | } 18 | 19 | public convertToDto(model: IBalanceChange): IBalanceChangeDto { 20 | const result: IBalanceChangeDto = { 21 | btcValue: model.btcValue, 22 | nativeValue: this._decimalDtoConverter.convertToDto(model.nativeValue), 23 | symbol: model.symbol, 24 | usdValue: model.usdValue, 25 | }; 26 | return result; 27 | } 28 | } -------------------------------------------------------------------------------- /lib/dto-converters/candlestick-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ICandlestickDto } from "../dtos"; 3 | import { ICandlestick } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 6 | 7 | export class CandlestickDtoConverter implements IDtoConverter { 8 | private _dateDtoConverter: DateDtoConverter = new DateDtoConverter(); 9 | private _decimalDtoConverter: DecimalDtoConverter = new DecimalDtoConverter(); 10 | 11 | public convertFromDto(dto: ICandlestickDto): ICandlestick { 12 | const result: ICandlestick = { 13 | open: this._decimalDtoConverter.convertFromDto(dto.open), 14 | high: this._decimalDtoConverter.convertFromDto(dto.high), 15 | low: this._decimalDtoConverter.convertFromDto(dto.low), 16 | close: this._decimalDtoConverter.convertFromDto(dto.close), 17 | volume: this._decimalDtoConverter.convertFromDto(dto.volume), 18 | quoteVolume: dto.quoteVolume, 19 | btcVolume: dto.btcVolume, 20 | usdVolume: dto.usdVolume, 21 | time: this._dateDtoConverter.convertFromDto(dto.time), 22 | }; 23 | return result; 24 | } 25 | 26 | public convertToDto(model: ICandlestick): ICandlestickDto { 27 | const result: ICandlestickDto = { 28 | open: this._decimalDtoConverter.convertToDto(model.open), 29 | high: this._decimalDtoConverter.convertToDto(model.high), 30 | low: this._decimalDtoConverter.convertToDto(model.low), 31 | close: this._decimalDtoConverter.convertToDto(model.close), 32 | volume: this._decimalDtoConverter.convertToDto(model.volume), 33 | quoteVolume: model.quoteVolume, 34 | btcVolume: model.btcVolume, 35 | usdVolume: model.usdVolume, 36 | time: this._dateDtoConverter.convertToDto(model.time), 37 | }; 38 | return result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/dto-converters/date-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | 3 | export class DateDtoConverter implements IDtoConverter { 4 | 5 | public convertFromDto(dto: string): Date { 6 | return new Date(dto); 7 | } 8 | 9 | public convertToDto(model: Date): string { 10 | return model.toISOString(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/dto-converters/decimal-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import Decimal from "decimal.js"; 3 | 4 | export class DecimalDtoConverter implements IDtoConverter { 5 | 6 | public convertFromDto(dto: string): Decimal { 7 | return new Decimal(dto); 8 | } 9 | 10 | public convertToDto(model: Decimal): string { 11 | return model.toString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/dto-converters/dynamic-strategy-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IDynamicStrategyDto } from "../dtos"; 3 | import { IDynamicStrategy } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | 6 | export class DynamicStrategyDtoConverter implements IDtoConverter { 7 | 8 | private _decimalDtoConveter = new DecimalDtoConverter(); 9 | 10 | public convertFromDto(dto: IDynamicStrategyDto): IDynamicStrategy { 11 | const result: IDynamicStrategy = { 12 | excludedSymbols: dto.excludedSymbols.slice(0), 13 | isDynamic: dto.isDynamic, 14 | isEqualWeight: dto.isEqualWeight, 15 | maxPercent: this._decimalDtoConveter.convertFromDto(dto.maxPercent), 16 | minPercent: this._decimalDtoConveter.convertFromDto(dto.minPercent), 17 | topAssetCount: dto.topAssetCount, 18 | }; 19 | return result; 20 | } 21 | 22 | public convertToDto(model: IDynamicStrategy): IDynamicStrategyDto { 23 | const result: IDynamicStrategyDto = { 24 | excludedSymbols: model.excludedSymbols.slice(0), 25 | isDynamic: model.isDynamic, 26 | isEqualWeight: model.isEqualWeight, 27 | maxPercent: this._decimalDtoConveter.convertToDto(model.maxPercent), 28 | minPercent: this._decimalDtoConveter.convertToDto(model.minPercent), 29 | topAssetCount: model.topAssetCount, 30 | }; 31 | return result; 32 | } 33 | } -------------------------------------------------------------------------------- /lib/dto-converters/exchange-order-book-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IExchangeOrderBookDto, IOrderBookDto } from "../dtos"; 3 | import { IExchangeOrderBook, IOrderBook } from "../models"; 4 | import { OrderBookDtoConverter } from "./order-book-dto-converter"; 5 | 6 | export class ExchangeOrderBookDtoConverter implements IDtoConverter { 7 | private _orderBookDtoConverter: OrderBookDtoConverter = new OrderBookDtoConverter(); 8 | 9 | public convertFromDto(dto: IExchangeOrderBookDto): IExchangeOrderBook { 10 | let orderBookDto: IOrderBook | null = null; 11 | if (dto.orderBook) { 12 | orderBookDto = this._orderBookDtoConverter.convertFromDto(dto.orderBook); 13 | } 14 | const result: IExchangeOrderBook = { 15 | exchange: dto.exchange, 16 | orderBook: orderBookDto 17 | }; 18 | return result; 19 | } 20 | 21 | public convertToDto(model: IExchangeOrderBook): IExchangeOrderBookDto { 22 | let orderBookDto: IOrderBookDto | null = null; 23 | if (model.orderBook) { 24 | orderBookDto = this._orderBookDtoConverter.convertToDto(model.orderBook); 25 | } 26 | const result: IExchangeOrderBookDto = { 27 | exchange: model.exchange, 28 | orderBook: orderBookDto 29 | }; 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/dto-converters/historical-candlestick-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IHistoricalCandlestickDto } from "../dtos"; 3 | import { IHistoricalCandlestick } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 6 | 7 | export class HistoricalCandlestickDtoConverter implements IDtoConverter { 8 | private _dateDtoConverter: DateDtoConverter = new DateDtoConverter(); 9 | private _decimalDtoConverter: DecimalDtoConverter = new DecimalDtoConverter(); 10 | 11 | public convertFromDto(dto: IHistoricalCandlestickDto): IHistoricalCandlestick { 12 | const result: IHistoricalCandlestick = { 13 | open: this._decimalDtoConverter.convertFromDto(dto.open), 14 | high: this._decimalDtoConverter.convertFromDto(dto.high), 15 | low: this._decimalDtoConverter.convertFromDto(dto.low), 16 | close: this._decimalDtoConverter.convertFromDto(dto.close), 17 | volume: this._decimalDtoConverter.convertFromDto(dto.volume), 18 | quoteVolume: dto.quoteVolume, 19 | btcVolume: dto.btcVolume, 20 | usdVolume: dto.usdVolume, 21 | time: this._dateDtoConverter.convertFromDto(dto.time), 22 | }; 23 | return result; 24 | } 25 | 26 | public convertToDto(model: IHistoricalCandlestick): IHistoricalCandlestickDto { 27 | const result: IHistoricalCandlestickDto = { 28 | open: this._decimalDtoConverter.convertToDto(model.open), 29 | high: this._decimalDtoConverter.convertToDto(model.high), 30 | low: this._decimalDtoConverter.convertToDto(model.low), 31 | close: this._decimalDtoConverter.convertToDto(model.close), 32 | volume: this._decimalDtoConverter.convertToDto(model.volume), 33 | quoteVolume: model.quoteVolume, 34 | btcVolume: model.btcVolume, 35 | usdVolume: model.usdVolume, 36 | time: this._dateDtoConverter.convertToDto(model.time), 37 | }; 38 | return result; 39 | } 40 | } -------------------------------------------------------------------------------- /lib/dto-converters/historical-instruments-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IHistoricalInstrumentDto } from "../dtos"; 3 | import { IHistoricalInstrument } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | 6 | 7 | export class HistoricalInstrumentsDtoConverter implements IDtoConverter { 8 | 9 | private _dateDtoConverter = new DateDtoConverter(); 10 | 11 | public convertFromDto(dto: IHistoricalInstrumentDto[]): IHistoricalInstrument[] { 12 | 13 | return dto.map((dtoItem) => { 14 | const orderBookStartTime = dtoItem.orderBookStartTime !== null ? this._dateDtoConverter.convertFromDto(dtoItem.orderBookStartTime) : null; 15 | const orderBookEndTime = dtoItem.orderBookEndTime !== null ? this._dateDtoConverter.convertFromDto(dtoItem.orderBookEndTime) : null; 16 | const tradeStartTime = dtoItem.tradeStartTime !== null ? this._dateDtoConverter.convertFromDto(dtoItem.tradeStartTime) : null; 17 | const tradeEndTime = dtoItem.tradeEndTime !== null ? this._dateDtoConverter.convertFromDto(dtoItem.tradeEndTime) : null; 18 | 19 | const result: IHistoricalInstrument = { 20 | exchange: dtoItem.exchange, 21 | baseTradingSymbol: dtoItem.baseTradingSymbol, 22 | quoteTradingSymbol: dtoItem.quoteTradingSymbol, 23 | orderBookStartTime: orderBookStartTime, 24 | orderBookEndTime: orderBookEndTime, 25 | tradeStartTime: tradeStartTime, 26 | tradeEndTime: tradeEndTime 27 | }; 28 | 29 | return result; 30 | }); 31 | } 32 | 33 | public convertToDto(model: IHistoricalInstrument[]): IHistoricalInstrumentDto[] { 34 | 35 | return model.map((model) => { 36 | const orderBookStartTime = model.orderBookStartTime !== null ? this._dateDtoConverter.convertToDto(model.orderBookStartTime) : null; 37 | const orderBookEndTime = model.orderBookEndTime !== null ? this._dateDtoConverter.convertToDto(model.orderBookEndTime) : null; 38 | const tradeStartTime = model.tradeStartTime !== null ? this._dateDtoConverter.convertToDto(model.tradeStartTime) : null; 39 | const tradeEndTime = model.tradeEndTime !== null ? this._dateDtoConverter.convertToDto(model.tradeEndTime) : null; 40 | 41 | const result: IHistoricalInstrumentDto = { 42 | exchange: model.exchange, 43 | baseTradingSymbol: model.baseTradingSymbol, 44 | quoteTradingSymbol: model.quoteTradingSymbol, 45 | orderBookStartTime: orderBookStartTime, 46 | orderBookEndTime: orderBookEndTime, 47 | tradeStartTime: tradeStartTime, 48 | tradeEndTime: tradeEndTime 49 | }; 50 | 51 | return result; 52 | }); 53 | } 54 | } -------------------------------------------------------------------------------- /lib/dto-converters/historical-orderbooks-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IHistoricalOrderBookDto, IHistoricalOrderBookItemDto } from "../dtos"; 3 | import { IHistoricalOrderBook, IHistoricalOrderBookItem } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | import { DateDtoConverter } from "./date-dto-converter"; 6 | 7 | 8 | export class HistoricalOrderBookItemDtoConverter implements IDtoConverter { 9 | private _decimalDtoConverter = new DecimalDtoConverter(); 10 | 11 | public convertFromDto(dto: IHistoricalOrderBookItemDto): IHistoricalOrderBookItem { 12 | return { 13 | price: this._decimalDtoConverter.convertFromDto(dto.price), 14 | size: this._decimalDtoConverter.convertFromDto(dto.size) 15 | }; 16 | } 17 | 18 | public convertToDto(model: IHistoricalOrderBookItem): IHistoricalOrderBookItemDto { 19 | return { 20 | price: this._decimalDtoConverter.convertToDto(model.price), 21 | size: this._decimalDtoConverter.convertToDto(model.size) 22 | }; 23 | } 24 | } 25 | 26 | 27 | export class HistoricalOrderBooksDtoConverter implements IDtoConverter { 28 | 29 | private _dateDtoConverter = new DateDtoConverter(); 30 | private _historicalOrderBookItemDtoConverter = new HistoricalOrderBookItemDtoConverter(); 31 | 32 | public convertFromDto(dto: IHistoricalOrderBookDto[]): IHistoricalOrderBook[] { 33 | 34 | return dto.map((historicalDepthDto) => { 35 | const historicalDepth: IHistoricalOrderBook = { 36 | time: this._dateDtoConverter.convertFromDto(historicalDepthDto.time), 37 | bids: historicalDepthDto.bids.map((depthItemDto) => { 38 | return this._historicalOrderBookItemDtoConverter.convertFromDto(depthItemDto); 39 | }), 40 | asks: historicalDepthDto.asks.map((depthItemDto) => { 41 | return this._historicalOrderBookItemDtoConverter.convertFromDto(depthItemDto); 42 | }) 43 | }; 44 | 45 | return historicalDepth; 46 | }); 47 | } 48 | 49 | public convertToDto(model: IHistoricalOrderBook[]): IHistoricalOrderBookDto[] { 50 | return model.map((historicalDepth) => { 51 | const historicalDepthDto: IHistoricalOrderBookDto = { 52 | time: this._dateDtoConverter.convertToDto(historicalDepth.time), 53 | bids: historicalDepth.bids.map((depthItem) => { 54 | return this._historicalOrderBookItemDtoConverter.convertToDto(depthItem); 55 | }), 56 | asks: historicalDepth.asks.map((depthItem) => { 57 | return this._historicalOrderBookItemDtoConverter.convertToDto(depthItem); 58 | }) 59 | }; 60 | 61 | return historicalDepthDto; 62 | }); 63 | } 64 | } -------------------------------------------------------------------------------- /lib/dto-converters/historical-trades-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IHistoricalTradeDto } from "../dtos"; 3 | import { IHistoricalTrade } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 6 | 7 | 8 | export class TakerSideDtoConverter implements IDtoConverter { 9 | 10 | public convertFromDto(dto: string): "buyer" | "seller" | "unknown" { 11 | 12 | if (dto == "buyer") { 13 | return "buyer"; 14 | } 15 | else if(dto == "seller") { 16 | return "seller"; 17 | } 18 | 19 | return "unknown"; 20 | } 21 | 22 | public convertToDto(model: "buyer" | "seller" | "unknown"): string { 23 | return model.toString(); 24 | } 25 | } 26 | 27 | 28 | export class HistoricalTradesDtoConverter implements IDtoConverter { 29 | 30 | private _dateDtoConverter = new DateDtoConverter(); 31 | private _decimalDtoConverter = new DecimalDtoConverter(); 32 | private _takerSideDtoConverter = new TakerSideDtoConverter(); 33 | 34 | public convertFromDto(dto: IHistoricalTradeDto[]): IHistoricalTrade[] { 35 | return dto.map((historicalTradeDto) => { 36 | const historicalTrade: IHistoricalTrade = { 37 | time: this._dateDtoConverter.convertFromDto(historicalTradeDto.time), 38 | price: this._decimalDtoConverter.convertFromDto(historicalTradeDto.price), 39 | size: this._decimalDtoConverter.convertFromDto(historicalTradeDto.size), 40 | takerSide: this._takerSideDtoConverter.convertFromDto(historicalTradeDto.takerSide) 41 | } 42 | 43 | return historicalTrade; 44 | }); 45 | } 46 | 47 | public convertToDto(model: IHistoricalTrade[]): IHistoricalTradeDto[] { 48 | return model.map((historicalTrade) => { 49 | const historicalTradeDto: IHistoricalTradeDto = { 50 | time: this._dateDtoConverter.convertToDto(historicalTrade.time), 51 | price: this._decimalDtoConverter.convertToDto(historicalTrade.price), 52 | size: this._decimalDtoConverter.convertToDto(historicalTrade.size), 53 | takerSide: this._takerSideDtoConverter.convertToDto(historicalTrade.takerSide) 54 | } 55 | 56 | return historicalTradeDto; 57 | }); 58 | } 59 | } -------------------------------------------------------------------------------- /lib/dto-converters/index.ts: -------------------------------------------------------------------------------- 1 | export * from './account-balance-dto-converter'; 2 | export * from './allocation-dto-converter'; 3 | export * from './asset-balance-dto-converter'; 4 | export * from './asset-insight-dto-converter'; 5 | export * from './backtest-asset-dto-converter'; 6 | export * from './backtest-data-point-dto-converter'; 7 | export * from './balance-change-dto-converter'; 8 | export * from './candlestick-dto-converter'; 9 | export * from './date-dto-converter'; 10 | export * from './decimal-dto-converter'; 11 | export * from './dynamic-strategy-dto-converter'; 12 | export * from './exchange-order-book-dto-converter'; 13 | export * from './historical-candlestick-dto-converter'; 14 | export * from './historical-orderbooks-dto-converter'; 15 | export * from './historical-instruments-dto-converter'; 16 | export * from './historical-trades-dto-converter'; 17 | export * from './limit-order-dto-converter'; 18 | export * from './limit-order-status-dto-converter'; 19 | export * from './market-order-books-dto-converter'; 20 | export * from './nullable-date-dto-converter'; 21 | export * from './nullable-decimal-dto-converter'; 22 | export * from './order-book-dto-converter'; 23 | export * from './order-book-item-dto-converter'; 24 | export * from './predictions-dto-converter'; 25 | export * from './static-strategy-dto-converter'; 26 | export * from './strategy-dto-converter'; 27 | export * from './ticker-dto-converter'; 28 | export * from './total-balance-history-item-dto-converter'; 29 | export * from './trade-changes-dto-converter'; 30 | export * from './trade-dto-converter'; 31 | export * from './trend-dto-converter'; 32 | export * from './user-dto-converter'; 33 | -------------------------------------------------------------------------------- /lib/dto-converters/limit-order-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ILimitOrderDto } from "../dtos"; 3 | import { ILimitOrder } from "../models"; 4 | import { DecimalDtoConverter } from './decimal-dto-converter'; 5 | 6 | export class LimitOrderDtoConverter implements IDtoConverter { 7 | 8 | private _decimalDtoConverter = new DecimalDtoConverter(); 9 | 10 | public convertFromDto(dto: ILimitOrderDto): ILimitOrder { 11 | const result: ILimitOrder = { 12 | id: dto.id, 13 | baseSymbol: dto.baseSymbol, 14 | quoteSymbol: dto.quoteSymbol, 15 | amount: this._decimalDtoConverter.convertFromDto(dto.amount), 16 | price: this._decimalDtoConverter.convertFromDto(dto.price), 17 | side: dto.side, 18 | timeInForce: dto.timeInForce, 19 | status: dto.status, 20 | cancelRequested: dto.cancelRequested, 21 | success: dto.success, 22 | errorCode: dto.errorCode, 23 | errorMessage: dto.errorMessage, 24 | exchangeApiErrors: dto.exchangeApiErrors, 25 | }; 26 | return result; 27 | } 28 | 29 | public convertToDto(model: ILimitOrder): ILimitOrderDto { 30 | const result: ILimitOrderDto = { 31 | id: model.id, 32 | baseSymbol: model.baseSymbol, 33 | quoteSymbol: model.quoteSymbol, 34 | amount: this._decimalDtoConverter.convertToDto(model.amount), 35 | price: this._decimalDtoConverter.convertToDto(model.price), 36 | side: model.side, 37 | timeInForce: model.timeInForce, 38 | status: model.status, 39 | cancelRequested: model.cancelRequested, 40 | success: model.success, 41 | errorCode: model.errorCode, 42 | errorMessage: model.errorMessage, 43 | exchangeApiErrors: model.exchangeApiErrors, 44 | }; 45 | return result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/dto-converters/limit-order-status-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ILimitOrderStatusDto } from "../dtos"; 3 | import { ILimitOrderStatus } from "../models"; 4 | import { BalanceChangeDtoConverter } from "./balance-change-dto-converter"; 5 | import { LimitOrderDtoConverter } from './limit-order-dto-converter'; 6 | 7 | export class LimitOrderStatusDtoConverter implements IDtoConverter { 8 | 9 | private _limitOrderDtoConverter = new LimitOrderDtoConverter(); 10 | private _balanceChangeDtoConverter = new BalanceChangeDtoConverter(); 11 | 12 | public convertFromDto(dto: ILimitOrderStatusDto): ILimitOrderStatus { 13 | const result: ILimitOrderStatus = { 14 | order: this._limitOrderDtoConverter.convertFromDto(dto.order), 15 | changes: dto.changes.map((change) => { 16 | return this._balanceChangeDtoConverter.convertFromDto(change); 17 | }), 18 | }; 19 | return result; 20 | } 21 | 22 | public convertToDto(model: ILimitOrderStatus): ILimitOrderStatusDto { 23 | const result: ILimitOrderStatusDto = { 24 | order: this._limitOrderDtoConverter.convertToDto(model.order), 25 | changes: model.changes.map((change) => { 26 | return this._balanceChangeDtoConverter.convertToDto(change); 27 | }), 28 | }; 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/dto-converters/market-order-books-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IExchangeOrderBookDto, IMarketOrderBooksDto } from "../dtos"; 3 | import { IExchangeOrderBook, IMarketOrderBooks } from "../models"; 4 | import { ExchangeOrderBookDtoConverter } from "./exchange-order-book-dto-converter"; 5 | 6 | export class MarketOrderBooksDtoConverter implements IDtoConverter { 7 | private _exchangeOrderBookDtoConverter: ExchangeOrderBookDtoConverter = new ExchangeOrderBookDtoConverter(); 8 | 9 | public convertFromDto(dto: IMarketOrderBooksDto): IMarketOrderBooks { 10 | const orderBooks: IExchangeOrderBook[] = dto.orderBooks.map((exchangeOrderBookDto) => { 11 | return this._exchangeOrderBookDtoConverter.convertFromDto(exchangeOrderBookDto); 12 | }); 13 | const result: IMarketOrderBooks = { 14 | baseSymbol: dto.baseSymbol, 15 | orderBooks: orderBooks, 16 | quoteSymbol: dto.quoteSymbol 17 | }; 18 | return result; 19 | } 20 | 21 | public convertToDto(model: IMarketOrderBooks): IMarketOrderBooksDto { 22 | const orderBookDtos: IExchangeOrderBookDto[] = model.orderBooks.map((exchangeOrderBook) => { 23 | return this._exchangeOrderBookDtoConverter.convertToDto(exchangeOrderBook); 24 | }); 25 | const result: IMarketOrderBooksDto = { 26 | baseSymbol: model.baseSymbol, 27 | orderBooks: orderBookDtos, 28 | quoteSymbol: model.quoteSymbol 29 | }; 30 | return result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/dto-converters/nullable-date-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { DateDtoConverter } from "./date-dto-converter"; 2 | import { IDtoConverter } from "../interfaces"; 3 | 4 | export class NullableDateDtoConverter implements IDtoConverter { 5 | private _DateDtoConverter = new DateDtoConverter(); 6 | 7 | public convertFromDto(dto: string | null): Date | null { 8 | if (dto) { 9 | return this._DateDtoConverter.convertFromDto(dto); 10 | } else { 11 | return null; 12 | } 13 | } 14 | 15 | public convertToDto(model: Date | null): string | null { 16 | if (model) { 17 | return this._DateDtoConverter.convertToDto(model); 18 | } else { 19 | return null; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/dto-converters/nullable-decimal-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 3 | import { IDtoConverter } from "../interfaces"; 4 | 5 | export class NullableDecimalDtoConverter implements IDtoConverter { 6 | private _decimalDtoConverter = new DecimalDtoConverter(); 7 | 8 | public convertFromDto(dto: string | null): Decimal | null { 9 | if (dto) { 10 | return this._decimalDtoConverter.convertFromDto(dto); 11 | } else { 12 | return null; 13 | } 14 | } 15 | 16 | public convertToDto(model: Decimal | null): string | null { 17 | if (model) { 18 | return this._decimalDtoConverter.convertToDto(model); 19 | } else { 20 | return null; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/dto-converters/order-book-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IOrderBookDto } from "../dtos"; 3 | import { IOrderBook } from "../models"; 4 | import { OrderBookItemDtoConverter } from "./order-book-item-dto-converter"; 5 | 6 | export class OrderBookDtoConverter implements IDtoConverter { 7 | private _orderBookItemDtoConverter: OrderBookItemDtoConverter = new OrderBookItemDtoConverter(); 8 | 9 | public convertFromDto(dto: IOrderBookDto): IOrderBook { 10 | const asks = dto.asks.map((ask) => { 11 | return this._orderBookItemDtoConverter.convertFromDto(ask); 12 | }); 13 | const bids = dto.bids.map((bid) => { 14 | return this._orderBookItemDtoConverter.convertFromDto(bid); 15 | }); 16 | const result: IOrderBook = { 17 | asks: asks, 18 | bids: bids, 19 | }; 20 | return result; 21 | } 22 | 23 | public convertToDto(model: IOrderBook): IOrderBookDto { 24 | const asks = model.asks.map((ask) => { 25 | return this._orderBookItemDtoConverter.convertToDto(ask); 26 | }); 27 | const bids = model.bids.map((bid) => { 28 | return this._orderBookItemDtoConverter.convertToDto(bid); 29 | }); 30 | const result: IOrderBookDto = { 31 | asks: asks, 32 | bids: bids, 33 | }; 34 | return result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/dto-converters/order-book-item-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IOrderBookItemDto } from "../dtos"; 3 | import { IOrderBookItem } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | 6 | export class OrderBookItemDtoConverter implements IDtoConverter { 7 | private _decimalDtoConverter: DecimalDtoConverter = new DecimalDtoConverter(); 8 | 9 | public convertFromDto(dto: IOrderBookItemDto): IOrderBookItem { 10 | const result: IOrderBookItem = { 11 | price: this._decimalDtoConverter.convertFromDto(dto.price), 12 | quantity: this._decimalDtoConverter.convertFromDto(dto.quantity), 13 | }; 14 | return result; 15 | } 16 | 17 | public convertToDto(model: IOrderBookItem): IOrderBookItemDto { 18 | const result: IOrderBookItemDto = { 19 | price: this._decimalDtoConverter.convertToDto(model.price), 20 | quantity: this._decimalDtoConverter.convertToDto(model.quantity), 21 | }; 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/dto-converters/prediction-item-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IPredictionItemDto } from "../dtos"; 3 | import { IPredictionItem } from "../models"; 4 | 5 | export class PredictionItemDtoConverter implements IDtoConverter { 6 | 7 | public convertFromDto(dto: IPredictionItemDto): IPredictionItem { 8 | const result: IPredictionItem = { 9 | date: dto.date, 10 | updatedAt: dto.updatedAt, 11 | prediction: dto.prediction 12 | }; 13 | return result; 14 | } 15 | 16 | public convertToDto(model: IPredictionItem): IPredictionItemDto { 17 | const result: IPredictionItemDto = { 18 | date: model.date, 19 | updatedAt: model.updatedAt, 20 | prediction: model.prediction 21 | }; 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/dto-converters/predictions-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IPredictionsDto } from "../dtos"; 3 | import { IPredictions } from "../models"; 4 | import { PredictionItemDtoConverter } from "./prediction-item-dto-converter"; 5 | 6 | 7 | export class PredictionsDtoConverter implements IDtoConverter { 8 | private _predictionItemDtoConverter: PredictionItemDtoConverter = new PredictionItemDtoConverter(); 9 | 10 | public convertFromDto(dto: IPredictionsDto): IPredictions { 11 | const predictions = dto.predictions.map((predictionsDto) => { 12 | return this._predictionItemDtoConverter.convertFromDto(predictionsDto); 13 | }); 14 | 15 | const result: IPredictions = { 16 | predictions: predictions, 17 | baseTradingSymbol: dto.baseTradingSymbol, 18 | quoteTradingSymbol: dto.quoteTradingSymbol, 19 | }; 20 | return result 21 | 22 | } 23 | 24 | 25 | public convertToDto(model: IPredictions): IPredictionsDto { 26 | 27 | const predictions = model.predictions.map((predictions) => { 28 | return this._predictionItemDtoConverter.convertToDto(predictions); 29 | }); 30 | 31 | const result: IPredictionsDto = { 32 | baseTradingSymbol: model.baseTradingSymbol, 33 | quoteTradingSymbol: model.quoteTradingSymbol, 34 | predictions: predictions 35 | }; 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/dto-converters/static-strategy-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IStaticStrategyDto } from "../dtos"; 3 | import { IStaticStrategy } from "../models"; 4 | import { AllocationDtoConverter } from "./allocation-dto-converter"; 5 | 6 | export class StaticStrategyDtoConverter implements IDtoConverter { 7 | 8 | private _allocationDtoConverter = new AllocationDtoConverter(); 9 | 10 | public convertFromDto(dto: IStaticStrategyDto): IStaticStrategy { 11 | const allocations = dto.allocations.map((allocationDto) => { 12 | return this._allocationDtoConverter.convertFromDto(allocationDto); 13 | }); 14 | const result: IStaticStrategy = { 15 | allocations: allocations, 16 | isDynamic: false, 17 | }; 18 | return result; 19 | } 20 | 21 | public convertToDto(model: IStaticStrategy): IStaticStrategyDto { 22 | const allocationDtos = model.allocations.map((allocation) => { 23 | return this._allocationDtoConverter.convertToDto(allocation); 24 | }); 25 | const result: IStaticStrategyDto = { 26 | allocations: allocationDtos, 27 | isDynamic: false 28 | }; 29 | return result; 30 | } 31 | } -------------------------------------------------------------------------------- /lib/dto-converters/strategy-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { IStrategyDto } from "../dtos"; 3 | import { IStrategy } from "../models"; 4 | import { DynamicStrategyDtoConverter } from "./dynamic-strategy-dto-converter"; 5 | import { StaticStrategyDtoConverter } from "./static-strategy-dto-converter"; 6 | 7 | export class StrategyDtoConverter implements IDtoConverter { 8 | private _dynamicStrategyDtoConverter = new DynamicStrategyDtoConverter(); 9 | private _staticStrategyDtoConverter = new StaticStrategyDtoConverter(); 10 | 11 | public convertFromDto(dto: IStrategyDto): IStrategy { 12 | if (dto.isDynamic) { 13 | return this._dynamicStrategyDtoConverter.convertFromDto(dto); 14 | } else { 15 | return this._staticStrategyDtoConverter.convertFromDto(dto); 16 | } 17 | } 18 | 19 | public convertToDto(model: IStrategy): IStrategyDto { 20 | if (model.isDynamic) { 21 | return this._dynamicStrategyDtoConverter.convertToDto(model); 22 | } else { 23 | return this._staticStrategyDtoConverter.convertToDto(model); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /lib/dto-converters/ticker-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ITickerDto } from "../dtos"; 3 | import { ITicker } from "../models"; 4 | import { NullableDateDtoConverter } from "./nullable-date-dto-converter"; 5 | import { NullableDecimalDtoConverter } from "./nullable-decimal-dto-converter"; 6 | 7 | export class TickerDtoConverter implements IDtoConverter { 8 | private _nullableDecimalDtoConverter = new NullableDecimalDtoConverter(); 9 | private _nullableDateDtoConverter = new NullableDateDtoConverter(); 10 | 11 | public convertFromDto(dto: ITickerDto): ITicker { 12 | const result: ITicker = { 13 | lastUpdated: this._nullableDateDtoConverter.convertFromDto(dto.lastUpdated), 14 | name: dto.name, 15 | percentChange24hUsd: this._nullableDecimalDtoConverter.convertFromDto(dto.percentChange24hUsd), 16 | priceBtc: this._nullableDecimalDtoConverter.convertFromDto(dto.priceBtc), 17 | priceUsd: this._nullableDecimalDtoConverter.convertFromDto(dto.priceUsd), 18 | symbol: dto.symbol 19 | }; 20 | return result; 21 | } 22 | 23 | public convertToDto(model: ITicker): ITickerDto { 24 | const result: ITickerDto = { 25 | lastUpdated: this._nullableDateDtoConverter.convertToDto(model.lastUpdated), 26 | name: model.name, 27 | percentChange24hUsd: this._nullableDecimalDtoConverter.convertToDto(model.percentChange24hUsd), 28 | priceBtc: this._nullableDecimalDtoConverter.convertToDto(model.priceBtc), 29 | priceUsd: this._nullableDecimalDtoConverter.convertToDto(model.priceUsd), 30 | symbol: model.symbol 31 | }; 32 | return result; 33 | } 34 | } -------------------------------------------------------------------------------- /lib/dto-converters/total-balance-history-item-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ITotalBalanceHistoryItemDto } from "../dtos"; 3 | import { ITotalBalanceHistoryItem } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | 6 | export class TotalBalanceHistoryItemDtoConverter implements IDtoConverter { 7 | private _dateDtoConverter = new DateDtoConverter(); 8 | 9 | public convertFromDto(dto: ITotalBalanceHistoryItemDto): ITotalBalanceHistoryItem { 10 | const result: ITotalBalanceHistoryItem = { 11 | btcValue: dto.btcValue, 12 | date: this._dateDtoConverter.convertFromDto(dto.date), 13 | usdValue: dto.usdValue, 14 | }; 15 | return result; 16 | } 17 | 18 | public convertToDto(model: ITotalBalanceHistoryItem): ITotalBalanceHistoryItemDto { 19 | const result: ITotalBalanceHistoryItemDto = { 20 | btcValue: model.btcValue, 21 | date: this._dateDtoConverter.convertToDto(model.date), 22 | usdValue: model.usdValue, 23 | }; 24 | return result; 25 | } 26 | } -------------------------------------------------------------------------------- /lib/dto-converters/trade-changes-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ITradeChangesDto } from "../dtos"; 3 | import { ITradeChanges } from "../models"; 4 | import { BalanceChangeDtoConverter } from "./balance-change-dto-converter"; 5 | import { TradeDtoConverter } from "./trade-dto-converter"; 6 | import { TradeFillDtoConverter } from "./trade-fill-dto-converter"; 7 | 8 | export class TradeChangesDtoConverter implements IDtoConverter { 9 | private _balanceChangeDtoConverter = new BalanceChangeDtoConverter(); 10 | private _tradeDtoConverter = new TradeDtoConverter(); 11 | private _tradeFillDtoConverter = new TradeFillDtoConverter(); 12 | 13 | public convertFromDto(dto: ITradeChangesDto): ITradeChanges { 14 | const changes = dto.changes.map((tradeChangeDto) => { 15 | return this._balanceChangeDtoConverter.convertFromDto(tradeChangeDto); 16 | }); 17 | const fills = dto.fills.map((tradeFillDto) => { 18 | return this._tradeFillDtoConverter.convertFromDto(tradeFillDto); 19 | }); 20 | const result: ITradeChanges = { 21 | changes: changes, 22 | trade: this._tradeDtoConverter.convertFromDto(dto.trade), 23 | fills: fills, 24 | }; 25 | return result; 26 | } 27 | 28 | public convertToDto(model: ITradeChanges): ITradeChangesDto { 29 | const changes = model.changes.map((tradeChange) => { 30 | return this._balanceChangeDtoConverter.convertToDto(tradeChange); 31 | }); 32 | const fills = model.fills.map((tradeFill) => { 33 | return this._tradeFillDtoConverter.convertToDto(tradeFill); 34 | }); 35 | const result: ITradeChangesDto = { 36 | changes: changes, 37 | trade: this._tradeDtoConverter.convertToDto(model.trade), 38 | fills: fills, 39 | }; 40 | return result; 41 | } 42 | } -------------------------------------------------------------------------------- /lib/dto-converters/trade-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ITradeDto } from "../dtos"; 3 | import { ITrade } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | 6 | export class TradeDtoConverter implements IDtoConverter { 7 | private _decimalDtoConverter = new DecimalDtoConverter(); 8 | 9 | public convertFromDto(dto: ITradeDto): ITrade { 10 | const result: ITrade = { 11 | amount: this._decimalDtoConverter.convertFromDto(dto.amount), 12 | errorCode: dto.errorCode, 13 | errorMessage: dto.errorMessage, 14 | fromSymbol: dto.fromSymbol, 15 | id: dto.id, 16 | status: dto.status, 17 | success: dto.success, 18 | toSymbol: dto.toSymbol, 19 | exchangeApiErrors: dto.exchangeApiErrors, 20 | maxSpreadPercent: this._decimalDtoConverter.convertFromDto(dto.maxSpreadPercent), 21 | maxSlippagePercent: this._decimalDtoConverter.convertFromDto(dto.maxSlippagePercent), 22 | smartRouting: dto.smartRouting, 23 | triggeredMaxSpread: dto.triggeredMaxSpread, 24 | triggeredMaxSlippage: dto.triggeredMaxSlippage, 25 | }; 26 | return result; 27 | } 28 | 29 | public convertToDto(model: ITrade): ITradeDto { 30 | const result: ITradeDto = { 31 | amount: this._decimalDtoConverter.convertToDto(model.amount), 32 | errorCode: model.errorCode, 33 | errorMessage: model.errorMessage, 34 | fromSymbol: model.fromSymbol, 35 | id: model.id, 36 | status: model.status, 37 | success: model.success, 38 | toSymbol: model.toSymbol, 39 | exchangeApiErrors: model.exchangeApiErrors, 40 | maxSpreadPercent: this._decimalDtoConverter.convertToDto(model.maxSpreadPercent), 41 | maxSlippagePercent: this._decimalDtoConverter.convertToDto(model.maxSlippagePercent), 42 | smartRouting: model.smartRouting, 43 | triggeredMaxSpread: model.triggeredMaxSpread, 44 | triggeredMaxSlippage: model.triggeredMaxSlippage, 45 | }; 46 | return result; 47 | } 48 | } -------------------------------------------------------------------------------- /lib/dto-converters/trade-fill-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ITradeFillDto } from "../dtos"; 3 | import { ITradeFill } from "../models"; 4 | import { DecimalDtoConverter } from "./decimal-dto-converter"; 5 | 6 | export class TradeFillDtoConverter implements IDtoConverter { 7 | private _decimalDtoConverter = new DecimalDtoConverter(); 8 | 9 | public convertFromDto(dto: ITradeFillDto): ITradeFill { 10 | const result: ITradeFill = { 11 | baseAmount: this._decimalDtoConverter.convertFromDto(dto.baseAmount), 12 | baseSymbol: dto.baseSymbol, 13 | btcValue: dto.btcValue, 14 | price: this._decimalDtoConverter.convertFromDto(dto.price), 15 | quoteAmount: this._decimalDtoConverter.convertFromDto(dto.quoteAmount), 16 | quoteSymbol: dto.quoteSymbol, 17 | side: dto.side, 18 | usdValue: dto.usdValue, 19 | }; 20 | return result; 21 | } 22 | 23 | public convertToDto(model: ITradeFill): ITradeFillDto { 24 | const result: ITradeFillDto = { 25 | baseAmount: this._decimalDtoConverter.convertToDto(model.baseAmount), 26 | baseSymbol: model.baseSymbol, 27 | btcValue: model.btcValue, 28 | price: this._decimalDtoConverter.convertToDto(model.price), 29 | quoteAmount: this._decimalDtoConverter.convertToDto(model.quoteAmount), 30 | quoteSymbol: model.quoteSymbol, 31 | side: model.side, 32 | usdValue: model.usdValue, 33 | }; 34 | return result; 35 | } 36 | } -------------------------------------------------------------------------------- /lib/dto-converters/trend-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IDtoConverter } from "../interfaces"; 2 | import { ITrendDto } from "../dtos"; 3 | import { ITrend } from "../models"; 4 | 5 | export class TrendDtoConverter implements IDtoConverter { 6 | public convertFromDto(dto: ITrendDto): ITrend { 7 | 8 | const result: ITrend = { 9 | exchange: dto.exchange, 10 | baseTradingSymbol: dto.baseTradingSymbol, 11 | quoteTradingSymbol: dto.quoteTradingSymbol, 12 | trend: dto.trend, 13 | date: dto.date 14 | }; 15 | return result 16 | 17 | } 18 | 19 | public convertToDto(model: ITrend): ITrendDto { 20 | 21 | const result: ITrendDto = { 22 | exchange: model.exchange, 23 | baseTradingSymbol: model.baseTradingSymbol, 24 | quoteTradingSymbol: model.quoteTradingSymbol, 25 | trend: model.trend, 26 | date: model.date 27 | }; 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/dto-converters/user-dto-converter.ts: -------------------------------------------------------------------------------- 1 | import { IUserDto } from "../dtos"; 2 | import { IDtoConverter } from "../interfaces"; 3 | import { IUser } from "../models"; 4 | import { DateDtoConverter } from "./date-dto-converter"; 5 | 6 | export class UserDtoConverter implements IDtoConverter { 7 | private _dateDtoConverter = new DateDtoConverter(); 8 | 9 | public convertFromDto(dto: IUserDto): IUser { 10 | let expirationDate: Date | null; 11 | if (dto.expirationDate) { 12 | expirationDate = this._dateDtoConverter.convertFromDto(dto.expirationDate) 13 | } else { 14 | expirationDate = null; 15 | } 16 | const result: IUser = { 17 | expirationDate: expirationDate, 18 | id: dto.id, 19 | isEnabled: dto.isEnabled, 20 | name: dto.name, 21 | }; 22 | return result; 23 | } 24 | 25 | public convertToDto(model: IUser): IUserDto { 26 | const result: IUserDto = { 27 | id: model.id, 28 | isEnabled: model.isEnabled, 29 | name: model.name, 30 | }; 31 | if (model.expirationDate != null) { 32 | result.expirationDate = this._dateDtoConverter.convertToDto(model.expirationDate); 33 | } 34 | return result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/dtos/iaccount-balance-dto.ts: -------------------------------------------------------------------------------- 1 | import { IAssetBalanceDto } from "./iasset-balance-dto"; 2 | 3 | export interface IAccountBalanceDto { 4 | balances: IAssetBalanceDto[]; 5 | retrievedAt: string | null; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/iaccount-dto.ts: -------------------------------------------------------------------------------- 1 | import { IExchangeApiErrorDto } from './iexchange-api-error-dto'; 2 | 3 | export interface IAccountDto { 4 | exchange: string; 5 | id: number; 6 | isRebalancing: string; 7 | exchangeApiErrors: IExchangeApiErrorDto[]; 8 | } 9 | -------------------------------------------------------------------------------- /lib/dtos/iallocation-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IAllocationDto { 3 | percent: string; 4 | symbol: string; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/iapi-key-permissions-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IApiKeyPermissionsDto { 3 | account: boolean; 4 | trade: boolean; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/iapi-keys-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IApiKeysDto { 3 | privateKey: string; 4 | publicKey: string; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/iasset-balance-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IAssetBalanceDto { 3 | btcValue: number; 4 | nativeValue: number; 5 | symbol: string; 6 | usdValue: number; 7 | } 8 | -------------------------------------------------------------------------------- /lib/dtos/iasset-insight-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IAssetInsightDto { 3 | id: number; 4 | change7d: string | null; 5 | change24h: string | null; 6 | change30d: string | null; 7 | percent: string; 8 | } 9 | -------------------------------------------------------------------------------- /lib/dtos/ibacktest-asset-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IBacktestAssetDto { 3 | symbol: string; 4 | startTime: string; 5 | endTime: string; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/ibacktest-data-point-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IBacktestDataPointDto { 3 | time: string; 4 | usdValue: number; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/ibacktest-result-dto.ts: -------------------------------------------------------------------------------- 1 | import { IBacktestDataPointDto } from './ibacktest-data-point-dto'; 2 | 3 | export interface IBacktestResultDto { 4 | rebalanceData: IBacktestDataPointDto[]; 5 | holdingData: IBacktestDataPointDto[]; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/ibalance-change-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IBalanceChangeDto { 3 | nativeValue: string; 4 | symbol: string; 5 | usdValue: number; 6 | btcValue: number; 7 | } 8 | -------------------------------------------------------------------------------- /lib/dtos/icandlestick-dto.ts: -------------------------------------------------------------------------------- 1 | export interface ICandlestickDto { 2 | open: string; 3 | high: string; 4 | low: string; 5 | close: string; 6 | volume: string; 7 | quoteVolume: number; 8 | btcVolume: number; 9 | usdVolume: number; 10 | time: string; 11 | } 12 | -------------------------------------------------------------------------------- /lib/dtos/idynamic-strategy-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IDynamicStrategyDto { 3 | isDynamic: true; 4 | excludedSymbols: string[]; 5 | topAssetCount: number; 6 | minPercent: string; 7 | maxPercent: string; 8 | isEqualWeight: boolean; 9 | } 10 | -------------------------------------------------------------------------------- /lib/dtos/iexchange-api-error-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IExchangeApiErrorDto { 3 | code: number; 4 | message: string; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/iexchange-asset-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IExchangeAssetDto { 2 | id: number; 3 | name: string; 4 | symbol: string; 5 | tradingSymbol: string; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/iexchange-info-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IExchangeInfoDto { 2 | exchange: string; 3 | bestCaseFee: number; 4 | worstCaseFee: number; 5 | icon: string; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/iexchange-order-book-dto.ts: -------------------------------------------------------------------------------- 1 | import { IOrderBookDto } from './iorder-book-dto'; 2 | 3 | export interface IExchangeOrderBookDto { 4 | exchange: string; 5 | orderBook: IOrderBookDto | null; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/iguid-id-result-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IGuidIdResultDto { 3 | id: string; 4 | } 5 | -------------------------------------------------------------------------------- /lib/dtos/ihistorical-candlestick-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IHistoricalCandlestickDto { 2 | open: string; 3 | high: string; 4 | low: string; 5 | close: string; 6 | volume: string; 7 | quoteVolume: number; 8 | btcVolume: number; 9 | usdVolume: number; 10 | time: string; 11 | } 12 | -------------------------------------------------------------------------------- /lib/dtos/ihistorical-count-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IHistoricalCountDto { 2 | count: number; 3 | } 4 | -------------------------------------------------------------------------------- /lib/dtos/ihistorical-instrument-dto.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface IHistoricalInstrumentDto { 3 | exchange: string; 4 | baseTradingSymbol: string; 5 | quoteTradingSymbol: string; 6 | orderBookStartTime: string | null; 7 | orderBookEndTime: string | null; 8 | tradeStartTime: string | null; 9 | tradeEndTime: string | null; 10 | } 11 | -------------------------------------------------------------------------------- /lib/dtos/ihistorical-order-book-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IHistoricalOrderBookItemDto { 2 | price: string; 3 | size: string; 4 | } 5 | 6 | export interface IHistoricalOrderBookDto { 7 | time: string; 8 | bids: IHistoricalOrderBookItemDto[]; 9 | asks: IHistoricalOrderBookItemDto[]; 10 | } 11 | -------------------------------------------------------------------------------- /lib/dtos/ihistorical-trade-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IHistoricalTradeDto { 2 | time: string; 3 | price: string; 4 | size: string; 5 | takerSide: string; 6 | } -------------------------------------------------------------------------------- /lib/dtos/ilimit-order-dto.ts: -------------------------------------------------------------------------------- 1 | import { IExchangeApiErrorDto } from "./iexchange-api-error-dto"; 2 | 3 | export interface ILimitOrderDto { 4 | id: string; 5 | baseSymbol: string; 6 | quoteSymbol: string; 7 | amount: string; 8 | price: string; 9 | side: 'BUY' | 'SELL', 10 | timeInForce: 'GTC' | 'IOC', 11 | status: 'queued' | 'started' | 'open' | 'closed' | 'completed', 12 | cancelRequested: boolean, 13 | success: boolean, 14 | errorCode: number, 15 | errorMessage: string, 16 | exchangeApiErrors: IExchangeApiErrorDto[] 17 | } 18 | -------------------------------------------------------------------------------- /lib/dtos/ilimit-order-status-dto.ts: -------------------------------------------------------------------------------- 1 | import { IBalanceChangeDto } from "./ibalance-change-dto"; 2 | import { ILimitOrderDto } from "./ilimit-order-dto"; 3 | 4 | export interface ILimitOrderStatusDto { 5 | order: ILimitOrderDto; 6 | changes: IBalanceChangeDto[]; 7 | } 8 | -------------------------------------------------------------------------------- /lib/dtos/imarket-order-books-dto.ts: -------------------------------------------------------------------------------- 1 | import { IExchangeOrderBookDto } from "./iexchange-order-book-dto"; 2 | 3 | export interface IMarketOrderBooksDto { 4 | baseSymbol: string; 5 | quoteSymbol: string; 6 | orderBooks: IExchangeOrderBookDto[]; 7 | } 8 | -------------------------------------------------------------------------------- /lib/dtos/index.ts: -------------------------------------------------------------------------------- 1 | export * from './iaccount-balance-dto'; 2 | export * from './iaccount-dto'; 3 | export * from './iallocation-dto'; 4 | export * from './iapi-key-permissions-dto'; 5 | export * from './iapi-keys-dto'; 6 | export * from './iasset-balance-dto'; 7 | export * from './iasset-insight-dto'; 8 | export * from './ibacktest-asset-dto'; 9 | export * from './ibacktest-data-point-dto'; 10 | export * from './ibacktest-result-dto'; 11 | export * from './ibalance-change-dto'; 12 | export * from './icandlestick-dto'; 13 | export * from './idynamic-strategy-dto'; 14 | export * from './iexchange-api-error-dto'; 15 | export * from './iexchange-asset-dto'; 16 | export * from './iexchange-info-dto'; 17 | export * from './iexchange-order-book-dto'; 18 | export * from './iguid-id-result-dto'; 19 | export * from './ihistorical-candlestick-dto'; 20 | export * from './ihistorical-count-dto'; 21 | export * from './ihistorical-order-book-dto'; 22 | export * from './ihistorical-instrument-dto'; 23 | export * from './ihistorical-trade-dto'; 24 | export * from './ilimit-order-dto'; 25 | export * from './ilimit-order-status-dto'; 26 | export * from './imarket-order-books-dto'; 27 | export * from './inumber-id-result-dto'; 28 | export * from './iorder-book-dto'; 29 | export * from './iorder-book-item-dto'; 30 | export * from './iprediction-item-dto'; 31 | export * from './ipredictions-dto'; 32 | export * from './irebalance-period-result-dto'; 33 | export * from './istatic-strategy-dto'; 34 | export * from './istrategy-dto'; 35 | export * from './iticker-dto'; 36 | export * from './itotal-balance-history-item-dto'; 37 | export * from './itrade-changes-dto'; 38 | export * from './itrade-dto'; 39 | export * from './itrade-fill-dto'; 40 | export * from './itrading-pair-dto'; 41 | export * from './itrend-dto'; 42 | export * from './iuser-dto'; 43 | export * from './iwebsocket-token-dto'; 44 | -------------------------------------------------------------------------------- /lib/dtos/inumber-id-result-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface INumberIdResultDto { 3 | id: number; 4 | } 5 | -------------------------------------------------------------------------------- /lib/dtos/iorder-book-dto.ts: -------------------------------------------------------------------------------- 1 | import { IOrderBookItemDto } from "./iorder-book-item-dto"; 2 | 3 | export interface IOrderBookDto { 4 | asks: IOrderBookItemDto[]; 5 | bids: IOrderBookItemDto[]; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/iorder-book-item-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IOrderBookItemDto { 3 | price: string; 4 | quantity: string; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/iprediction-item-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IPredictionItemDto { 2 | date: Date; 3 | prediction: number 4 | updatedAt: Date; 5 | } 6 | -------------------------------------------------------------------------------- /lib/dtos/ipredictions-dto.ts: -------------------------------------------------------------------------------- 1 | import { IPredictionItemDto } from "./iprediction-item-dto"; 2 | 3 | export interface IPredictionsDto { 4 | baseTradingSymbol: string; 5 | quoteTradingSymbol: string; 6 | predictions: IPredictionItemDto[] 7 | } -------------------------------------------------------------------------------- /lib/dtos/irebalance-period-result-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IRebalancePeriodResultDto { 3 | rebalancePeriod: number; 4 | } 5 | -------------------------------------------------------------------------------- /lib/dtos/istatic-strategy-dto.ts: -------------------------------------------------------------------------------- 1 | import { IAllocationDto } from "./iallocation-dto"; 2 | 3 | export interface IStaticStrategyDto { 4 | isDynamic: false; 5 | allocations: IAllocationDto[]; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/istrategy-dto.ts: -------------------------------------------------------------------------------- 1 | import { IDynamicStrategyDto } from "./idynamic-strategy-dto"; 2 | import { IStaticStrategyDto } from "./istatic-strategy-dto"; 3 | 4 | export type IStrategyDto = IDynamicStrategyDto | IStaticStrategyDto; 5 | -------------------------------------------------------------------------------- /lib/dtos/iticker-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface ITickerDto { 3 | name: string; 4 | symbol: string; 5 | priceUsd: string | null; 6 | priceBtc: string | null; 7 | percentChange24hUsd: string | null; 8 | lastUpdated: string | null; 9 | } -------------------------------------------------------------------------------- /lib/dtos/itotal-balance-history-item-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface ITotalBalanceHistoryItemDto { 3 | date: string; 4 | usdValue: number; 5 | btcValue: number; 6 | } 7 | -------------------------------------------------------------------------------- /lib/dtos/itrade-changes-dto.ts: -------------------------------------------------------------------------------- 1 | import { IBalanceChangeDto } from "./ibalance-change-dto"; 2 | import { ITradeDto } from "./itrade-dto"; 3 | import { ITradeFillDto } from "./itrade-fill-dto"; 4 | 5 | export interface ITradeChangesDto { 6 | trade: ITradeDto; 7 | changes: IBalanceChangeDto[]; 8 | fills: ITradeFillDto[]; 9 | } 10 | -------------------------------------------------------------------------------- /lib/dtos/itrade-dto.ts: -------------------------------------------------------------------------------- 1 | import { IExchangeApiErrorDto } from './iexchange-api-error-dto'; 2 | 3 | export interface ITradeDto { 4 | id: string; 5 | fromSymbol: string; 6 | toSymbol: string; 7 | amount: string; 8 | status: string; 9 | success: boolean; 10 | errorCode: number; 11 | errorMessage: string; 12 | exchangeApiErrors: IExchangeApiErrorDto[]; 13 | maxSpreadPercent: string; 14 | maxSlippagePercent: string; 15 | smartRouting: boolean; 16 | triggeredMaxSpread: boolean; 17 | triggeredMaxSlippage: boolean; 18 | } 19 | -------------------------------------------------------------------------------- /lib/dtos/itrade-fill-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface ITradeFillDto { 3 | baseAmount: string; 4 | baseSymbol: string; 5 | btcValue: number; 6 | price: string; 7 | quoteAmount: string; 8 | quoteSymbol: string; 9 | side: 'BUY' | 'SELL', 10 | usdValue: number; 11 | } 12 | -------------------------------------------------------------------------------- /lib/dtos/itrading-pair-dto.ts: -------------------------------------------------------------------------------- 1 | export interface ITradingPairDto { 2 | baseTradingSymbol: string; 3 | quoteTradingSymbol: string; 4 | } 5 | -------------------------------------------------------------------------------- /lib/dtos/itrend-dto.ts: -------------------------------------------------------------------------------- 1 | export interface ITrendDto { 2 | date: Date; 3 | exchange: String; 4 | baseTradingSymbol: String; 5 | quoteTradingSymbol: String; 6 | trend: String; 7 | } 8 | -------------------------------------------------------------------------------- /lib/dtos/iuser-dto.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IUserDto { 3 | expirationDate?: string; 4 | id: string; 5 | isEnabled: boolean; 6 | name: string; 7 | } 8 | -------------------------------------------------------------------------------- /lib/dtos/iwebsocket-token-dto.ts: -------------------------------------------------------------------------------- 1 | export interface IWebsocketTokenDto { 2 | token: string; 3 | } -------------------------------------------------------------------------------- /lib/enums/exchange-enum.ts: -------------------------------------------------------------------------------- 1 |  2 | 3 | export enum ExchangeEnum { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /lib/enums/index.ts: -------------------------------------------------------------------------------- 1 | export * from './exchange-enum'; -------------------------------------------------------------------------------- /lib/enums/subscription-type-enum.ts: -------------------------------------------------------------------------------- 1 | export enum SubscriptionTypeEnum { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from './public-api'; -------------------------------------------------------------------------------- /lib/interfaces/idto-converter.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IDtoConverter { 3 | convertFromDto(dto: TDto): TModel; 4 | convertToDto(model: TModel): TDto; 5 | } 6 | -------------------------------------------------------------------------------- /lib/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './idto-converter'; -------------------------------------------------------------------------------- /lib/models/iaccount-balance.ts: -------------------------------------------------------------------------------- 1 | import { IAssetBalance } from "./iasset-balance"; 2 | 3 | export interface IAccountBalance { 4 | balances: IAssetBalance[]; 5 | retrievedAt: Date | null; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/iaccount.ts: -------------------------------------------------------------------------------- 1 | import { IExchangeApiError } from './iexchange-api-error'; 2 | 3 | export interface IAccount { 4 | exchange: string; 5 | id: number; 6 | isRebalancing: string; 7 | exchangeApiErrors: IExchangeApiError[]; 8 | } 9 | -------------------------------------------------------------------------------- /lib/models/iallocation.ts: -------------------------------------------------------------------------------- 1 | import { Decimal } from 'decimal.js'; 2 | 3 | export interface IAllocation { 4 | percent: Decimal; 5 | symbol: string; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/iapi-key-permissions.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IApiKeyPermissions { 3 | account: boolean; 4 | trade: boolean; 5 | } 6 | -------------------------------------------------------------------------------- /lib/models/iapi-keys.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IApiKeys { 3 | privateKey: string; 4 | publicKey: string; 5 | } 6 | -------------------------------------------------------------------------------- /lib/models/iasset-balance.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IAssetBalance { 3 | btcValue: number; 4 | nativeValue: number; 5 | symbol: string; 6 | usdValue: number; 7 | } 8 | -------------------------------------------------------------------------------- /lib/models/iasset-insight.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface IAssetInsight { 4 | id: number; 5 | change7d: Decimal | null; 6 | change24h: Decimal | null; 7 | change30d: Decimal | null; 8 | percent: Decimal; 9 | } 10 | -------------------------------------------------------------------------------- /lib/models/ibacktest-asset.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IBacktestAsset { 3 | symbol: string; 4 | startTime: Date; 5 | endTime: Date; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/ibacktest-data-point.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IBacktestDataPoint { 3 | time: Date; 4 | usdValue: number; 5 | } 6 | -------------------------------------------------------------------------------- /lib/models/ibacktest-result.ts: -------------------------------------------------------------------------------- 1 | import { IBacktestDataPoint } from './ibacktest-data-point'; 2 | 3 | export interface IBacktestResult { 4 | rebalanceData: IBacktestDataPoint[]; 5 | holdingData: IBacktestDataPoint[]; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/ibalance-change.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface IBalanceChange { 4 | nativeValue: Decimal; 5 | symbol: string; 6 | usdValue: number; 7 | btcValue: number; 8 | } -------------------------------------------------------------------------------- /lib/models/icandlestick.ts: -------------------------------------------------------------------------------- 1 | import { Decimal } from 'decimal.js'; 2 | 3 | export interface ICandlestick { 4 | open: Decimal; 5 | high: Decimal; 6 | low: Decimal; 7 | close: Decimal; 8 | volume: Decimal; 9 | quoteVolume: number; 10 | btcVolume: number; 11 | usdVolume: number; 12 | time: Date; 13 | } 14 | -------------------------------------------------------------------------------- /lib/models/idynamic-strategy.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface IDynamicStrategy { 4 | isDynamic: true; 5 | excludedSymbols: string[]; 6 | topAssetCount: number; 7 | minPercent: Decimal; 8 | maxPercent: Decimal; 9 | isEqualWeight: boolean; 10 | } 11 | -------------------------------------------------------------------------------- /lib/models/iexchange-api-error.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IExchangeApiError { 3 | code: number; 4 | message: string; 5 | } 6 | -------------------------------------------------------------------------------- /lib/models/iexchange-asset.ts: -------------------------------------------------------------------------------- 1 | export interface IExchangeAsset { 2 | id: number; 3 | name: string; 4 | symbol: string; 5 | tradingSymbol: string; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/iexchange-info.ts: -------------------------------------------------------------------------------- 1 | export interface IExchangeInfo { 2 | exchange: string; 3 | bestCaseFee: number; 4 | worstCaseFee: number; 5 | icon: string; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/iexchange-order-book.ts: -------------------------------------------------------------------------------- 1 | import { IOrderBook } from './iorder-book'; 2 | 3 | export interface IExchangeOrderBook { 4 | exchange: string; 5 | orderBook: IOrderBook | null; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/ihistorical-candlestick.ts: -------------------------------------------------------------------------------- 1 | import { Decimal } from 'decimal.js'; 2 | 3 | export interface IHistoricalCandlestick { 4 | open: Decimal; 5 | high: Decimal; 6 | low: Decimal; 7 | close: Decimal; 8 | volume: Decimal; 9 | quoteVolume: number; 10 | btcVolume: number; 11 | usdVolume: number; 12 | time: Date; 13 | } -------------------------------------------------------------------------------- /lib/models/ihistorical-count.ts: -------------------------------------------------------------------------------- 1 | export interface IHistoricalCount { 2 | count: number; 3 | } -------------------------------------------------------------------------------- /lib/models/ihistorical-instrument.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface IHistoricalInstrument { 3 | exchange: string; 4 | baseTradingSymbol: string; 5 | quoteTradingSymbol: string; 6 | orderBookStartTime: Date | null; 7 | orderBookEndTime: Date | null; 8 | tradeStartTime: Date | null; 9 | tradeEndTime: Date | null; 10 | } -------------------------------------------------------------------------------- /lib/models/ihistorical-order-book.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface IHistoricalOrderBookItem { 4 | price: Decimal; 5 | size: Decimal; 6 | } 7 | 8 | export interface IHistoricalOrderBook { 9 | time: Date; 10 | bids: IHistoricalOrderBookItem[]; 11 | asks: IHistoricalOrderBookItem[]; 12 | } 13 | -------------------------------------------------------------------------------- /lib/models/ihistorical-trade.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface IHistoricalTrade { 4 | time: Date; 5 | price: Decimal; 6 | size: Decimal; 7 | takerSide: 'buyer' | 'seller' | 'unknown'; 8 | } 9 | -------------------------------------------------------------------------------- /lib/models/ilimit-order-status.ts: -------------------------------------------------------------------------------- 1 | import { IBalanceChange } from "./ibalance-change"; 2 | import { ILimitOrder } from "./ilimit-order"; 3 | 4 | export interface ILimitOrderStatus { 5 | order: ILimitOrder; 6 | changes: IBalanceChange[]; 7 | } 8 | -------------------------------------------------------------------------------- /lib/models/ilimit-order.ts: -------------------------------------------------------------------------------- 1 | import { Decimal } from 'decimal.js'; 2 | import { IExchangeApiError } from './iexchange-api-error'; 3 | 4 | export interface ILimitOrder { 5 | id: string; 6 | baseSymbol: string; 7 | quoteSymbol: string; 8 | amount: Decimal; 9 | price: Decimal; 10 | side: 'BUY' | 'SELL', 11 | timeInForce: 'GTC' | 'IOC', 12 | status: 'queued' | 'started' | 'open' | 'closed' | 'completed', 13 | cancelRequested: boolean, 14 | success: boolean, 15 | errorCode: number, 16 | errorMessage: string, 17 | exchangeApiErrors: IExchangeApiError[] 18 | } 19 | -------------------------------------------------------------------------------- /lib/models/imanagement-credits.ts: -------------------------------------------------------------------------------- 1 | export interface IManagementCredits { 2 | credits: number; 3 | } -------------------------------------------------------------------------------- /lib/models/imanagement-status.ts: -------------------------------------------------------------------------------- 1 | export interface IManagementStatus { 2 | apiKeyAccepted: boolean; 3 | apiNonceAccepted: boolean; 4 | apiSignatureAccepted: boolean; 5 | ipAccepted: boolean; 6 | requestsRemaining: number; 7 | } -------------------------------------------------------------------------------- /lib/models/imanagement-usage.ts: -------------------------------------------------------------------------------- 1 | export interface IManagementUsage { 2 | usedUserCredits: number; 3 | maxUserCredits: number; 4 | usedDataCredits: number; 5 | maxDataCredits: number; 6 | } -------------------------------------------------------------------------------- /lib/models/imarket-order-books.ts: -------------------------------------------------------------------------------- 1 | import { IExchangeOrderBook } from "./iexchange-order-book"; 2 | 3 | export interface IMarketOrderBooks { 4 | baseSymbol: string; 5 | quoteSymbol: string; 6 | orderBooks: IExchangeOrderBook[]; 7 | } 8 | -------------------------------------------------------------------------------- /lib/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './iaccount'; 2 | export * from './iaccount-balance'; 3 | export * from './iallocation'; 4 | export * from './iapi-key-permissions'; 5 | export * from './iapi-keys'; 6 | export * from './iasset-balance'; 7 | export * from './iasset-insight'; 8 | export * from './ibacktest-asset'; 9 | export * from './ibacktest-data-point'; 10 | export * from './ibacktest-result'; 11 | export * from './ibalance-change'; 12 | export * from './icandlestick'; 13 | export * from './idynamic-strategy'; 14 | export * from './iexchange-api-error'; 15 | export * from './iexchange-asset'; 16 | export * from './iexchange-info'; 17 | export * from './iexchange-order-book'; 18 | export * from './ihistorical-candlestick'; 19 | export * from './ihistorical-count'; 20 | export * from './ihistorical-order-book'; 21 | export * from './ihistorical-instrument'; 22 | export * from './ihistorical-trade'; 23 | export * from './ilimit-order'; 24 | export * from './ilimit-order-status'; 25 | export * from './imanagement-credits'; 26 | export * from './imanagement-status'; 27 | export * from './imanagement-usage'; 28 | export * from './imarket-order-books'; 29 | export * from './iorder-book'; 30 | export * from './iorder-book-item'; 31 | export * from './iprediction-item'; 32 | export * from './ipredictions'; 33 | export * from './istatic-strategy'; 34 | export * from './istrategy'; 35 | export * from './iticker'; 36 | export * from './itotal-balance-history-item'; 37 | export * from './itrade'; 38 | export * from './itrade-changes'; 39 | export * from './itrade-fill'; 40 | export * from './itrade-item'; 41 | export * from './itrading-pair'; 42 | export * from './itrend'; 43 | export * from './isubscription-request'; 44 | export * from './iuser'; 45 | export * from './iwebsocket-message'; 46 | -------------------------------------------------------------------------------- /lib/models/iorder-book-item.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface IOrderBookItem { 4 | price: Decimal; 5 | quantity: Decimal; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/iorder-book.ts: -------------------------------------------------------------------------------- 1 | import { IOrderBookItem } from "./iorder-book-item"; 2 | 3 | export interface IOrderBook { 4 | asks: IOrderBookItem[]; 5 | bids: IOrderBookItem[]; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/iprediction-item.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface IPredictionItem{ 3 | date: Date; 4 | prediction: number; 5 | updatedAt: Date 6 | } -------------------------------------------------------------------------------- /lib/models/ipredictions.ts: -------------------------------------------------------------------------------- 1 | import { IPredictionItem } from "./iprediction-item"; 2 | 3 | export interface IPredictions { 4 | baseTradingSymbol: string; 5 | quoteTradingSymbol: string; 6 | predictions: IPredictionItem[]; 7 | } -------------------------------------------------------------------------------- /lib/models/istatic-strategy.ts: -------------------------------------------------------------------------------- 1 | import { IAllocation } from "./iallocation"; 2 | 3 | export interface IStaticStrategy { 4 | isDynamic: false; 5 | allocations: IAllocation[]; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/istrategy.ts: -------------------------------------------------------------------------------- 1 | import { IDynamicStrategy } from "./idynamic-strategy"; 2 | import { IStaticStrategy } from "./istatic-strategy"; 3 | 4 | export type IStrategy = IDynamicStrategy | IStaticStrategy; 5 | -------------------------------------------------------------------------------- /lib/models/isubscription-request.ts: -------------------------------------------------------------------------------- 1 | export type ISubscriptionRequest = IExchangeSubscription | IOrderSubscription; 2 | 3 | export interface IExchangeSubscription { 4 | type: 'subscribe' | 'unsubscribe'; 5 | exchange: string; 6 | pair: string; 7 | channel: string; 8 | } 9 | 10 | export interface IOrderSubscription { 11 | channel: string; 12 | } 13 | -------------------------------------------------------------------------------- /lib/models/iticker.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface ITicker { 4 | name: string; 5 | symbol: string; 6 | priceUsd: Decimal | null; 7 | priceBtc: Decimal | null; 8 | percentChange24hUsd: Decimal | null; 9 | lastUpdated: Date | null; 10 | } 11 | -------------------------------------------------------------------------------- /lib/models/itotal-balance-history-item.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface ITotalBalanceHistoryItem { 3 | date: Date; 4 | usdValue: number; 5 | btcValue: number; 6 | } 7 | -------------------------------------------------------------------------------- /lib/models/itrade-changes.ts: -------------------------------------------------------------------------------- 1 | import { IBalanceChange } from "./ibalance-change"; 2 | import { ITrade } from "./itrade"; 3 | import { ITradeFill } from "./itrade-fill"; 4 | 5 | export interface ITradeChanges { 6 | trade: ITrade; 7 | changes: IBalanceChange[]; 8 | fills: ITradeFill[]; 9 | } 10 | -------------------------------------------------------------------------------- /lib/models/itrade-fill.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface ITradeFill { 4 | baseAmount: Decimal; 5 | baseSymbol: string; 6 | btcValue: number; 7 | price: Decimal; 8 | quoteAmount: Decimal; 9 | quoteSymbol: string; 10 | side: 'BUY' | 'SELL', 11 | usdValue: number; 12 | } 13 | -------------------------------------------------------------------------------- /lib/models/itrade-item.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | 3 | export interface ITradeItem { 4 | id: number; 5 | price: Decimal; 6 | quantity: Decimal; 7 | time: Date; 8 | btcValue: Decimal; 9 | usdValue: Decimal; 10 | } -------------------------------------------------------------------------------- /lib/models/itrade.ts: -------------------------------------------------------------------------------- 1 | import Decimal from "decimal.js"; 2 | import { IExchangeApiError } from "./iexchange-api-error"; 3 | 4 | export interface ITrade { 5 | id: string; 6 | fromSymbol: string; 7 | toSymbol: string; 8 | amount: Decimal; 9 | status: string; 10 | success: boolean; 11 | errorCode: number; 12 | errorMessage: string; 13 | exchangeApiErrors: IExchangeApiError[]; 14 | maxSpreadPercent: Decimal; 15 | maxSlippagePercent: Decimal; 16 | smartRouting: boolean; 17 | triggeredMaxSpread: boolean; 18 | triggeredMaxSlippage: boolean; 19 | } 20 | -------------------------------------------------------------------------------- /lib/models/itrading-pair.ts: -------------------------------------------------------------------------------- 1 | export interface ITradingPair { 2 | baseTradingSymbol: string; 3 | quoteTradingSymbol: string; 4 | } 5 | -------------------------------------------------------------------------------- /lib/models/itrend.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface ITrend{ 3 | date: Date; 4 | exchange: String; 5 | baseTradingSymbol: String; 6 | quoteTradingSymbol: String; 7 | trend: String; 8 | 9 | } -------------------------------------------------------------------------------- /lib/models/iuser.ts: -------------------------------------------------------------------------------- 1 |  2 | export interface IUser { 3 | expirationDate: Date | null; 4 | id: string; 5 | isEnabled: boolean; 6 | name: string; 7 | } 8 | -------------------------------------------------------------------------------- /lib/models/iwebsocket-message.ts: -------------------------------------------------------------------------------- 1 | import { IOrderBookItem } from "./iorder-book-item"; 2 | import { ITradeItem } from "./itrade-item"; 3 | 4 | export type IWebsocketMessage = IExchangePairMessage | IOrderMessage | IErrorMessage | IPingMessage; 5 | 6 | export interface IExchangePairMessage { 7 | exchange: string; 8 | pair: string; 9 | channel: 'bbo' | 'orderbook' | 'trades' 10 | content: WebsocketContent 11 | } 12 | 13 | export interface IOrderMessage { 14 | channel: 'orders'; 15 | content: WebsocketContent; 16 | } 17 | 18 | export interface IErrorMessage { 19 | type: string; 20 | code: number; 21 | message: string; 22 | } 23 | 24 | export interface IPingMessage { 25 | type: string; 26 | data: number; 27 | } 28 | 29 | export type WebsocketContent = OrderBookContent | TradeContent | OrdersContent; 30 | 31 | export interface OrderBookContent { 32 | sequence: number; 33 | asks: IOrderBookItem[]; 34 | bids: IOrderBookItem[]; 35 | } 36 | 37 | export interface TradeContent { 38 | trades: ITradeItem[]; 39 | } 40 | 41 | export type OrdersContent = string[]; 42 | -------------------------------------------------------------------------------- /lib/public-api.ts: -------------------------------------------------------------------------------- 1 |  2 | export { ShrimpyApiClient, ShrimpyWsClient } from './client'; 3 | export * from './models'; -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shrimpy-node", 3 | "version": "0.2.15", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/caseless": { 8 | "version": "0.12.1", 9 | "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.1.tgz", 10 | "integrity": "sha512-FhlMa34NHp9K5MY1Uz8yb+ZvuX0pnvn3jScRSNAb75KHGB8d3rEU6hqMs3Z2vjuytcMfRg6c5CHMc3wtYyD2/A==", 11 | "dev": true 12 | }, 13 | "@types/events": { 14 | "version": "3.0.0", 15 | "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", 16 | "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==", 17 | "dev": true 18 | }, 19 | "@types/form-data": { 20 | "version": "2.2.1", 21 | "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz", 22 | "integrity": "sha512-JAMFhOaHIciYVh8fb5/83nmuO/AHwmto+Hq7a9y8FzLDcC1KCU344XDOMEmahnrTFlHjgh4L0WJFczNIX2GxnQ==", 23 | "dev": true, 24 | "requires": { 25 | "@types/node": "*" 26 | } 27 | }, 28 | "@types/node": { 29 | "version": "10.12.21", 30 | "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.21.tgz", 31 | "integrity": "sha512-CBgLNk4o3XMnqMc0rhb6lc77IwShMEglz05deDcn2lQxyXEZivfwgYJu7SMha9V5XcrP6qZuevTHV/QrN2vjKQ==", 32 | "dev": true 33 | }, 34 | "@types/request": { 35 | "version": "2.48.1", 36 | "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.1.tgz", 37 | "integrity": "sha512-ZgEZ1TiD+KGA9LiAAPPJL68Id2UWfeSO62ijSXZjFJArVV+2pKcsVHmrcu+1oiE3q6eDGiFiSolRc4JHoerBBg==", 38 | "dev": true, 39 | "requires": { 40 | "@types/caseless": "*", 41 | "@types/form-data": "*", 42 | "@types/node": "*", 43 | "@types/tough-cookie": "*" 44 | } 45 | }, 46 | "@types/request-promise-native": { 47 | "version": "1.0.15", 48 | "resolved": "https://registry.npmjs.org/@types/request-promise-native/-/request-promise-native-1.0.15.tgz", 49 | "integrity": "sha512-uYPjTChD9TpjlvbBjNpZfNc64TBejBS52u7pbxhQLnlxw+5Em7wLb6DU2wdJVhJ2Mou7v50N0qgL4Gia5mmRYg==", 50 | "dev": true, 51 | "requires": { 52 | "@types/request": "*" 53 | } 54 | }, 55 | "@types/tough-cookie": { 56 | "version": "2.3.5", 57 | "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.5.tgz", 58 | "integrity": "sha512-SCcK7mvGi3+ZNz833RRjFIxrn4gI1PPR3NtuIS+6vMkvmsGjosqTJwRt5bAEFLRz+wtJMWv8+uOnZf2hi2QXTg==", 59 | "dev": true 60 | }, 61 | "@types/ws": { 62 | "version": "6.0.1", 63 | "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.1.tgz", 64 | "integrity": "sha512-EzH8k1gyZ4xih/MaZTXwT2xOkPiIMSrhQ9b8wrlX88L0T02eYsddatQlwVFlEPyEqV0ChpdpNnE51QPH6NVT4Q==", 65 | "dev": true, 66 | "requires": { 67 | "@types/events": "*", 68 | "@types/node": "*" 69 | } 70 | }, 71 | "asn1": { 72 | "version": "0.1.11", 73 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz", 74 | "integrity": "sha1-VZvhg3bQik7E2+gId9J4GGObLfc=", 75 | "optional": true 76 | }, 77 | "assert-plus": { 78 | "version": "0.1.5", 79 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz", 80 | "integrity": "sha1-7nQAlBMALYTOxyGcasgRgS5yMWA=", 81 | "optional": true 82 | }, 83 | "async": { 84 | "version": "0.9.2", 85 | "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", 86 | "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=", 87 | "optional": true 88 | }, 89 | "async-limiter": { 90 | "version": "1.0.0", 91 | "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", 92 | "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" 93 | }, 94 | "aws-sign2": { 95 | "version": "0.5.0", 96 | "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz", 97 | "integrity": "sha1-xXED96F/wDfwLXwuZLYC6iI/fWM=", 98 | "optional": true 99 | }, 100 | "boom": { 101 | "version": "0.4.2", 102 | "resolved": "https://registry.npmjs.org/boom/-/boom-0.4.2.tgz", 103 | "integrity": "sha1-emNune1O/O+xnO9JR6PGffrukRs=", 104 | "optional": true, 105 | "requires": { 106 | "hoek": "0.9.x" 107 | } 108 | }, 109 | "combined-stream": { 110 | "version": "0.0.7", 111 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz", 112 | "integrity": "sha1-ATfmV7qlp1QcV6w3rF/AfXO03B8=", 113 | "optional": true, 114 | "requires": { 115 | "delayed-stream": "0.0.5" 116 | } 117 | }, 118 | "cryptiles": { 119 | "version": "0.2.2", 120 | "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-0.2.2.tgz", 121 | "integrity": "sha1-7ZH/HxetE9N0gohZT4pIoNJvMlw=", 122 | "optional": true, 123 | "requires": { 124 | "boom": "0.4.x" 125 | } 126 | }, 127 | "ctype": { 128 | "version": "0.5.3", 129 | "resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz", 130 | "integrity": "sha1-gsGMJGH3QRTvFsE1IkrQuRRMoS8=", 131 | "optional": true 132 | }, 133 | "decimal.js": { 134 | "version": "10.0.2", 135 | "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.0.2.tgz", 136 | "integrity": "sha512-qL5tUTXAWjB5cSBfm0V2a4jO5FaDLumCfwc/0f7WaTOT3WU8pIeq2HHrd98eXHtbey4qFWlaPzfml1JWIoO9TQ==" 137 | }, 138 | "delayed-stream": { 139 | "version": "0.0.5", 140 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz", 141 | "integrity": "sha1-1LH0OpPoKW3+AmlPRoC8N6MTxz8=", 142 | "optional": true 143 | }, 144 | "forever-agent": { 145 | "version": "0.5.2", 146 | "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz", 147 | "integrity": "sha1-bQ4JxJIflKJ/Y9O0nF/v8epMUTA=" 148 | }, 149 | "form-data": { 150 | "version": "0.1.4", 151 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-0.1.4.tgz", 152 | "integrity": "sha1-kavXiKupcCsaq/qLwBAxoqyeOxI=", 153 | "optional": true, 154 | "requires": { 155 | "async": "~0.9.0", 156 | "combined-stream": "~0.0.4", 157 | "mime": "~1.2.11" 158 | } 159 | }, 160 | "hawk": { 161 | "version": "1.0.0", 162 | "resolved": "https://registry.npmjs.org/hawk/-/hawk-1.0.0.tgz", 163 | "integrity": "sha1-uQuxaYByhUEdp//LjdJZhQLTtS0=", 164 | "optional": true, 165 | "requires": { 166 | "boom": "0.4.x", 167 | "cryptiles": "0.2.x", 168 | "hoek": "0.9.x", 169 | "sntp": "0.2.x" 170 | } 171 | }, 172 | "hoek": { 173 | "version": "0.9.1", 174 | "resolved": "https://registry.npmjs.org/hoek/-/hoek-0.9.1.tgz", 175 | "integrity": "sha1-PTIkYrrfB3Fup+uFuviAec3c5QU=", 176 | "optional": true 177 | }, 178 | "http-signature": { 179 | "version": "0.10.1", 180 | "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", 181 | "integrity": "sha1-T72sEyVZqoMjEh5UB3nAoBKyfmY=", 182 | "optional": true, 183 | "requires": { 184 | "asn1": "0.1.11", 185 | "assert-plus": "^0.1.5", 186 | "ctype": "0.5.3" 187 | } 188 | }, 189 | "json-stringify-safe": { 190 | "version": "5.0.1", 191 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", 192 | "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" 193 | }, 194 | "lodash": { 195 | "version": "4.17.11", 196 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", 197 | "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" 198 | }, 199 | "mime": { 200 | "version": "1.2.11", 201 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz", 202 | "integrity": "sha1-WCA+7Ybjpe8XrtK32evUfwpg3RA=" 203 | }, 204 | "node-uuid": { 205 | "version": "1.4.8", 206 | "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.8.tgz", 207 | "integrity": "sha1-sEDrCSOWivq/jTL7HxfxFn/auQc=" 208 | }, 209 | "oauth-sign": { 210 | "version": "0.3.0", 211 | "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.3.0.tgz", 212 | "integrity": "sha1-y1QPk7srIqfVlBaRoojWDo6pOG4=", 213 | "optional": true 214 | }, 215 | "psl": { 216 | "version": "1.1.31", 217 | "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", 218 | "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==" 219 | }, 220 | "punycode": { 221 | "version": "2.1.1", 222 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", 223 | "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" 224 | }, 225 | "qs": { 226 | "version": "0.6.6", 227 | "resolved": "https://registry.npmjs.org/qs/-/qs-0.6.6.tgz", 228 | "integrity": "sha1-bgFQmP9RlouKPIGQAdXyyJvEsQc=" 229 | }, 230 | "request": { 231 | "version": "2.34.0", 232 | "resolved": "https://registry.npmjs.org/request/-/request-2.34.0.tgz", 233 | "integrity": "sha1-tdi5UmrdSi1GKfTUFxJFc5lkRa4=", 234 | "requires": { 235 | "aws-sign2": "~0.5.0", 236 | "forever-agent": "~0.5.0", 237 | "form-data": "~0.1.0", 238 | "hawk": "~1.0.0", 239 | "http-signature": "~0.10.0", 240 | "json-stringify-safe": "~5.0.0", 241 | "mime": "~1.2.9", 242 | "node-uuid": "~1.4.0", 243 | "oauth-sign": "~0.3.0", 244 | "qs": "~0.6.0", 245 | "tough-cookie": ">=0.12.0", 246 | "tunnel-agent": "~0.3.0" 247 | } 248 | }, 249 | "request-promise-core": { 250 | "version": "1.1.1", 251 | "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz", 252 | "integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=", 253 | "requires": { 254 | "lodash": "^4.13.1" 255 | } 256 | }, 257 | "request-promise-native": { 258 | "version": "1.0.5", 259 | "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.5.tgz", 260 | "integrity": "sha1-UoF3D2jgyXGeUWP9P6tIIhX0/aU=", 261 | "requires": { 262 | "request-promise-core": "1.1.1", 263 | "stealthy-require": "^1.1.0", 264 | "tough-cookie": ">=2.3.3" 265 | } 266 | }, 267 | "sntp": { 268 | "version": "0.2.4", 269 | "resolved": "https://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz", 270 | "integrity": "sha1-+4hfGLDzqtGJ+CSGJTa87ux1CQA=", 271 | "optional": true, 272 | "requires": { 273 | "hoek": "0.9.x" 274 | } 275 | }, 276 | "stealthy-require": { 277 | "version": "1.1.1", 278 | "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", 279 | "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" 280 | }, 281 | "tough-cookie": { 282 | "version": "2.5.0", 283 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", 284 | "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", 285 | "requires": { 286 | "psl": "^1.1.28", 287 | "punycode": "^2.1.1" 288 | } 289 | }, 290 | "tunnel-agent": { 291 | "version": "0.3.0", 292 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.3.0.tgz", 293 | "integrity": "sha1-rWgbaPUyGtKCfEz7G31d8s/pQu4=", 294 | "optional": true 295 | }, 296 | "typescript": { 297 | "version": "3.2.2", 298 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz", 299 | "integrity": "sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==", 300 | "dev": true 301 | }, 302 | "ws": { 303 | "version": "7.1.1", 304 | "resolved": "https://registry.npmjs.org/ws/-/ws-7.1.1.tgz", 305 | "integrity": "sha512-o41D/WmDeca0BqYhsr3nJzQyg9NF5X8l/UdnFNux9cS3lwB+swm8qGWX5rn+aD6xfBU3rGmtHij7g7x6LxFU3A==", 306 | "requires": { 307 | "async-limiter": "^1.0.0" 308 | } 309 | } 310 | } 311 | } 312 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shrimpy-node", 3 | "version": "0.2.15", 4 | "author": "Shrimpy", 5 | "bugs": "https://github.com/shrimpy-dev/shrimpy-node/issues", 6 | "contributors": [ 7 | { 8 | "email": "matt@shrimpy.io", 9 | "name": "Matthew Wesly", 10 | "url": "https://www.shrimpy.io" 11 | } 12 | ], 13 | "dependencies": { 14 | "decimal.js": "^10.0.2", 15 | "request": "^2.34.0", 16 | "request-promise-native": "^1.0.5", 17 | "ws": "^7.1.1" 18 | }, 19 | "description": "Client for the Shrimpy API", 20 | "devDependencies": { 21 | "@types/request-promise-native": "^1.0.15", 22 | "@types/ws": "^6.0.1", 23 | "typescript": "^3.2.2" 24 | }, 25 | "directories": { 26 | "lib": "./lib" 27 | }, 28 | "engines": { 29 | "node": ">=6.0.0" 30 | }, 31 | "homepage": "https://github.com/shrimpy-dev/shrimpy-node", 32 | "keywords": [ 33 | "API", 34 | "shrimpy", 35 | "bitcoin", 36 | "exchange", 37 | "trading", 38 | "bittrex", 39 | "kraken", 40 | "coinbase", 41 | "poloniex", 42 | "binance", 43 | "kucoin" 44 | ], 45 | "license": "MIT", 46 | "main": "dist/index.js", 47 | "peerDependencies": { 48 | "decimal.js": "^10.0.2" 49 | }, 50 | "types": "dist/index.d.ts", 51 | "repository": { 52 | "type": "git", 53 | "url": "git://github.com/shrimpy-dev/shrimpy-node.git" 54 | }, 55 | "scripts": { 56 | "build": "tsc" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "strict": true, 5 | "noImplicitReturns": true, 6 | "noUnusedLocals": true, 7 | "declarationDir": "./dist", 8 | "outDir": "./dist", 9 | "sourceMap": true, 10 | "declaration": true, 11 | "moduleResolution": "node", 12 | "emitDecoratorMetadata": true, 13 | "experimentalDecorators": true, 14 | "baseUrl": "./", 15 | "module": "commonjs", 16 | "types": [ "node" ], 17 | "target": "es5", 18 | "typeRoots": [ 19 | "node_modules/@types" 20 | ], 21 | "lib": [ 22 | "es2016", 23 | "dom" 24 | ] 25 | }, 26 | "include": [ 27 | "lib/**/*" 28 | ], 29 | "exclude": [ 30 | "node_modules", 31 | "dist" 32 | ] 33 | } 34 | --------------------------------------------------------------------------------