@tastytrade/api 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/.vscode/launch.json +29 -0
  2. package/CHANGELOG.md +26 -0
  3. package/CODEOWNERS +1 -0
  4. package/README.md +4 -2
  5. package/dist/account-streamer.d.ts +7 -6
  6. package/dist/account-streamer.d.ts.map +1 -0
  7. package/dist/account-streamer.js +145 -228
  8. package/dist/account-streamer.js.map +1 -0
  9. package/dist/market-data-streamer.d.ts +7 -5
  10. package/dist/market-data-streamer.d.ts.map +1 -0
  11. package/dist/market-data-streamer.js +139 -172
  12. package/dist/market-data-streamer.js.map +1 -0
  13. package/dist/models/tastytrade-session.d.ts +1 -0
  14. package/dist/models/tastytrade-session.d.ts.map +1 -0
  15. package/dist/models/tastytrade-session.js +10 -20
  16. package/dist/models/tastytrade-session.js.map +1 -0
  17. package/dist/services/account-status-service.d.ts +2 -1
  18. package/dist/services/account-status-service.d.ts.map +1 -0
  19. package/dist/services/account-status-service.js +12 -61
  20. package/dist/services/account-status-service.js.map +1 -0
  21. package/dist/services/accounts-and-customers-service.d.ts +2 -1
  22. package/dist/services/accounts-and-customers-service.d.ts.map +1 -0
  23. package/dist/services/accounts-and-customers-service.js +29 -112
  24. package/dist/services/accounts-and-customers-service.js.map +1 -0
  25. package/dist/services/balances-and-positions-service.d.ts +2 -1
  26. package/dist/services/balances-and-positions-service.d.ts.map +1 -0
  27. package/dist/services/balances-and-positions-service.js +22 -88
  28. package/dist/services/balances-and-positions-service.js.map +1 -0
  29. package/dist/services/instruments-service.d.ts +2 -1
  30. package/dist/services/instruments-service.d.ts.map +1 -0
  31. package/dist/services/instruments-service.js +130 -365
  32. package/dist/services/instruments-service.js.map +1 -0
  33. package/dist/services/margin-requirements-service.d.ts +2 -1
  34. package/dist/services/margin-requirements-service.d.ts.map +1 -0
  35. package/dist/services/margin-requirements-service.js +16 -73
  36. package/dist/services/margin-requirements-service.js.map +1 -0
  37. package/dist/services/market-metrics-service.d.ts +2 -1
  38. package/dist/services/market-metrics-service.d.ts.map +1 -0
  39. package/dist/services/market-metrics-service.js +21 -88
  40. package/dist/services/market-metrics-service.js.map +1 -0
  41. package/dist/services/net-liquidating-value-history-service.d.ts +2 -1
  42. package/dist/services/net-liquidating-value-history-service.d.ts.map +1 -0
  43. package/dist/services/net-liquidating-value-history-service.js +16 -74
  44. package/dist/services/net-liquidating-value-history-service.js.map +1 -0
  45. package/dist/services/orders-service.d.ts +4 -1
  46. package/dist/services/orders-service.d.ts.map +1 -0
  47. package/dist/services/orders-service.js +76 -205
  48. package/dist/services/orders-service.js.map +1 -0
  49. package/dist/services/risk-parameters-service.d.ts +2 -1
  50. package/dist/services/risk-parameters-service.d.ts.map +1 -0
  51. package/dist/services/risk-parameters-service.js +16 -73
  52. package/dist/services/risk-parameters-service.js.map +1 -0
  53. package/dist/services/session-service.d.ts +2 -1
  54. package/dist/services/session-service.d.ts.map +1 -0
  55. package/dist/services/session-service.js +30 -110
  56. package/dist/services/session-service.js.map +1 -0
  57. package/dist/services/symbol-search-service.d.ts +2 -1
  58. package/dist/services/symbol-search-service.d.ts.map +1 -0
  59. package/dist/services/symbol-search-service.js +11 -60
  60. package/dist/services/symbol-search-service.js.map +1 -0
  61. package/dist/services/tastytrade-http-client.d.ts +2 -2
  62. package/dist/services/tastytrade-http-client.d.ts.map +1 -0
  63. package/dist/services/tastytrade-http-client.js +51 -133
  64. package/dist/services/tastytrade-http-client.js.map +1 -0
  65. package/dist/services/transactions-service.d.ts +2 -1
  66. package/dist/services/transactions-service.d.ts.map +1 -0
  67. package/dist/services/transactions-service.js +22 -87
  68. package/dist/services/transactions-service.js.map +1 -0
  69. package/dist/services/watchlists-service.d.ts +2 -1
  70. package/dist/services/watchlists-service.d.ts.map +1 -0
  71. package/dist/services/watchlists-service.js +51 -165
  72. package/dist/services/watchlists-service.js.map +1 -0
  73. package/dist/tastytrade-api.d.ts +20 -19
  74. package/dist/tastytrade-api.d.ts.map +1 -0
  75. package/dist/tastytrade-api.js +41 -77
  76. package/dist/tastytrade-api.js.map +1 -0
  77. package/dist/utils/constants.d.ts +1 -0
  78. package/dist/utils/constants.d.ts.map +1 -0
  79. package/dist/utils/constants.js +2 -4
  80. package/dist/utils/constants.js.map +1 -0
  81. package/dist/utils/json-util.d.ts +4 -3
  82. package/dist/utils/json-util.d.ts.map +1 -0
  83. package/dist/utils/json-util.js +14 -25
  84. package/dist/utils/json-util.js.map +1 -0
  85. package/dist/utils/response-util.d.ts +1 -0
  86. package/dist/utils/response-util.d.ts.map +1 -0
  87. package/dist/utils/response-util.js +7 -12
  88. package/dist/utils/response-util.js.map +1 -0
  89. package/lib/account-streamer.ts +4 -4
  90. package/lib/market-data-streamer.ts +5 -1
  91. package/lib/services/account-status-service.ts +3 -3
  92. package/lib/services/accounts-and-customers-service.ts +2 -2
  93. package/lib/services/balances-and-positions-service.ts +2 -2
  94. package/lib/services/instruments-service.ts +2 -2
  95. package/lib/services/margin-requirements-service.ts +2 -2
  96. package/lib/services/market-metrics-service.ts +2 -2
  97. package/lib/services/net-liquidating-value-history-service.ts +2 -2
  98. package/lib/services/orders-service.ts +14 -2
  99. package/lib/services/risk-parameters-service.ts +2 -2
  100. package/lib/services/session-service.ts +2 -2
  101. package/lib/services/symbol-search-service.ts +2 -2
  102. package/lib/services/tastytrade-http-client.ts +15 -13
  103. package/lib/services/transactions-service.ts +2 -2
  104. package/lib/services/watchlists-service.ts +2 -2
  105. package/lib/tastytrade-api.ts +19 -19
  106. package/package.json +14 -9
  107. package/tsconfig.json +12 -11
@@ -1,43 +1,32 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.dasherize = exports.recursiveDasherizeKeys = exports.JsonBuilder = void 0;
7
- var lodash_1 = __importDefault(require("lodash"));
8
- var JsonBuilder = /** @class */ (function () {
9
- function JsonBuilder(json) {
10
- if (json === void 0) { json = {}; }
1
+ import _ from 'lodash';
2
+ export class JsonBuilder {
3
+ constructor(json = {}) {
11
4
  this.json = json;
12
5
  }
13
- JsonBuilder.prototype.add = function (key, value, serializeEmpty) {
14
- if (serializeEmpty === void 0) { serializeEmpty = false; }
15
- if ((lodash_1.default.isNil(value) || value === '') && !serializeEmpty) {
6
+ add(key, value, serializeEmpty = false) {
7
+ if ((_.isNil(value) || value === '') && !serializeEmpty) {
16
8
  return this;
17
9
  }
18
10
  this.json[key] = value;
19
11
  return this;
20
- };
21
- return JsonBuilder;
22
- }());
23
- exports.JsonBuilder = JsonBuilder;
12
+ }
13
+ }
24
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- function recursiveDasherizeKeys(body) {
26
- var dasherized = lodash_1.default.mapKeys(body, function (_value, key) { return dasherize(key); });
15
+ export function recursiveDasherizeKeys(body) {
16
+ let dasherized = _.mapKeys(body, (_value, key) => dasherize(key));
27
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- dasherized = lodash_1.default.mapValues(dasherized, function (value) {
29
- if (lodash_1.default.isPlainObject(value)) {
18
+ dasherized = _.mapValues(dasherized, (value) => {
19
+ if (_.isPlainObject(value)) {
30
20
  return recursiveDasherizeKeys(value);
31
21
  }
32
22
  return value;
33
23
  });
34
24
  return dasherized;
35
25
  }
36
- exports.recursiveDasherizeKeys = recursiveDasherizeKeys;
37
- function dasherize(target) {
26
+ export function dasherize(target) {
38
27
  // prettier-ignore
39
28
  return target
40
- .replace(/([A-Z])/g, function (_match, p1, _offset, _whole) { return "-".concat(p1.toLowerCase()); })
29
+ .replace(/([A-Z])/g, (_match, p1, _offset, _whole) => `-${p1.toLowerCase()}`)
41
30
  .replace(/\s/g, '-');
42
31
  }
43
- exports.dasherize = dasherize;
32
+ //# sourceMappingURL=json-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-util.js","sourceRoot":"","sources":["../../lib/utils/json-util.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAA;AAStB,MAAM,OAAO,WAAW;IACtB,YAAmC,OAAgB,EAAE;QAAlB,SAAI,GAAJ,IAAI,CAAc;IAAG,CAAC;IAElD,GAAG,CAAC,GAAW,EAAE,KAAgB,EAAE,cAAc,GAAG,KAAK;QAC9D,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACxD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,8DAA8D;AAC9D,MAAM,UAAU,sBAAsB,CAAC,IAAS;IAC9C,IAAI,UAAU,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAEjE,8DAA8D;IAC9D,UAAU,GAAG,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,KAAU,EAAE,EAAE;QAClD,IAAI,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAA;QACtC,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,kBAAkB;IAClB,OAAO,MAAM;SACV,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,EAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;SACpF,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACxB,CAAC"}
@@ -1 +1,2 @@
1
1
  export default function extractResponseData(httpResponse: any): any;
2
+ //# sourceMappingURL=response-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-util.d.ts","sourceRoot":"","sources":["../../lib/utils/response-util.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,YAAY,EAAE,GAAG,OAQ5D"}
@@ -1,21 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var lodash_1 = __importDefault(require("lodash"));
1
+ import _ from 'lodash';
7
2
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- function extractResponseData(httpResponse) {
9
- if (lodash_1.default.has(httpResponse, 'data.data.items')) {
10
- return lodash_1.default.get(httpResponse, 'data.data.items');
3
+ export default function extractResponseData(httpResponse) {
4
+ if (_.has(httpResponse, 'data.data.items')) {
5
+ return _.get(httpResponse, 'data.data.items');
11
6
  }
12
- else if (lodash_1.default.has(httpResponse, 'data.data')) {
13
- return lodash_1.default.get(httpResponse, 'data.data');
7
+ else if (_.has(httpResponse, 'data.data')) {
8
+ return _.get(httpResponse, 'data.data');
14
9
  }
15
10
  else {
16
11
  return httpResponse;
17
12
  }
18
13
  }
19
- exports.default = extractResponseData;
20
14
  // add login parser here
21
15
  // create unit tests for login parser, extractreponsedata
16
+ //# sourceMappingURL=response-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-util.js","sourceRoot":"","sources":["../../lib/utils/response-util.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAA;AAEtB,8DAA8D;AAC9D,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,YAAiB;IAC3D,IAAI,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,iBAAiB,CAAC,EAAE,CAAC;QAC3C,OAAO,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAA;IAC/C,CAAC;SAAM,IAAI,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,EAAC,CAAC;QAC3C,OAAO,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;IACzC,CAAC;SAAI,CAAC;QACJ,OAAO,YAAY,CAAA;IACrB,CAAC;AACH,CAAC;AAED,wBAAwB;AACxB,yDAAyD"}
@@ -1,9 +1,9 @@
1
1
  import WebSocket from 'isomorphic-ws'
2
2
  import _ from 'lodash'
3
- import type { JsonMap, JsonValue } from './utils/json-util'
4
- import { JsonBuilder } from './utils/json-util'
5
- import TastytradeSession from './models/tastytrade-session'
6
- import { MinTlsVersion } from './utils/constants'
3
+ import type { JsonMap, JsonValue } from './utils/json-util.js'
4
+ import { JsonBuilder } from './utils/json-util.js'
5
+ import TastytradeSession from './models/tastytrade-session.js'
6
+ import { MinTlsVersion } from './utils/constants.js'
7
7
 
8
8
  export enum STREAMER_STATE {
9
9
  Open = 0,
@@ -1,7 +1,7 @@
1
1
  import WebSocket from 'isomorphic-ws'
2
2
  import _ from 'lodash'
3
3
  import { v4 as uuidv4 } from 'uuid'
4
- import { MinTlsVersion } from './utils/constants'
4
+ import { MinTlsVersion } from './utils/constants.js'
5
5
 
6
6
  export enum MarketDataSubscriptionType {
7
7
  Candle = 'Candle',
@@ -54,6 +54,10 @@ export default class MarketDataStreamer {
54
54
  private errorListeners = new Map()
55
55
  private authStateListeners = new Map()
56
56
 
57
+ constructor() {
58
+ console.warn('MarketDataStreamer is deprecated and will be removed in a future release of @tastytrade/api. Use @dxfeed/dxlink-api instead.')
59
+ }
60
+
57
61
  addDataListener(dataListener: MarketDataListener, channelId: number | null = null): Remover {
58
62
  if (_.isNil(dataListener)) {
59
63
  return _.noop
@@ -1,7 +1,7 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
- // create the central class that aggregates all services from dmoss
4
+ // create the central class that aggregates all services
5
5
  export default class AccountStatusService {
6
6
  constructor(private httpClient: TastytradeHttpClient) {
7
7
  }
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class AccountsAndCustomersService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class BalancesAndPositionsService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
  import _ from 'lodash'
4
4
 
5
5
  export default class InstrumentsService {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class MarginRequirementsService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class MarketMetricsService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class NetLiquidatingValueHistoryService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class OrderService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -30,6 +30,12 @@ export default class OrderService {
30
30
  return extractResponseData(order)
31
31
  }
32
32
 
33
+ async cancelComplexOrder(accountNumber: string, orderId: number){
34
+ //Requests order cancellation
35
+ const order = await this.httpClient.deleteData(`/accounts/${accountNumber}/complex-orders/${orderId}`, {})
36
+ return extractResponseData(order)
37
+ }
38
+
33
39
  async replaceOrder(accountNumber: string, orderId: number, replacementOrder : object){
34
40
  //Replaces a live order with a new one. Subsequent fills of the original order will abort the replacement.
35
41
  const order = await this.httpClient.putData(`/accounts/${accountNumber}/orders/${orderId}`, replacementOrder , {})
@@ -60,6 +66,12 @@ export default class OrderService {
60
66
  return extractResponseData(orderResponse)
61
67
  }
62
68
 
69
+ async createComplexOrder(accountNumber: string, order: object){
70
+ //Accepts a json document containing parameters to create an order for the client.
71
+ const orderResponse = await this.httpClient.postData(`/accounts/${accountNumber}/complex-orders`, order , {})
72
+ return extractResponseData(orderResponse)
73
+ }
74
+
63
75
  async postOrderDryRun(accountNumber: string, order: object){
64
76
  //Accepts a json document containing parameters to create an order and then runs the prefights without placing the order.
65
77
  const orderDryRun = await this.httpClient.postData(`/accounts/${accountNumber}/orders/dry-run`, order , {})
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class RiskParametersService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class SessionService {
5
5
  constructor(public httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class SymbolSearchService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,10 +1,8 @@
1
- import TastytradeSession from "../models/tastytrade-session"
1
+ import TastytradeSession from "../models/tastytrade-session.js"
2
2
  import axios from "axios"
3
3
  import qs from 'qs'
4
- import { recursiveDasherizeKeys } from "../utils/json-util"
4
+ import { recursiveDasherizeKeys } from "../utils/json-util.js"
5
5
  import _ from 'lodash'
6
- import https from 'https'
7
- import { MinTlsVersion } from "../utils/constants"
8
6
 
9
7
  const ParamsSerializer = {
10
8
  serialize: function (queryParams: object) {
@@ -14,19 +12,24 @@ const ParamsSerializer = {
14
12
 
15
13
  export default class TastytradeHttpClient{
16
14
  public readonly session: TastytradeSession
17
- private readonly httpsAgent: https.Agent
18
15
 
19
16
  constructor(private readonly baseUrl: string) {
20
17
  this.session = new TastytradeSession()
21
- this.httpsAgent = new https.Agent({ minVersion: MinTlsVersion })
22
18
  }
23
19
 
24
20
  private getDefaultHeaders(): any {
25
- return {
26
- "Content-Type": "application/json",
27
- "Accept": "application/json",
28
- "Authorization": this.session.authToken,
29
- };
21
+ const headers: { [key: string]: any } = {
22
+ "Content-Type": "application/json",
23
+ "Accept": "application/json",
24
+ "Authorization": this.session.authToken
25
+ };
26
+
27
+ // Only set user agent if running in node
28
+ if (typeof window === 'undefined') {
29
+ headers["User-Agent"] = 'tastytrade-sdk-js'
30
+ }
31
+
32
+ return headers
30
33
  }
31
34
 
32
35
  private async executeRequest(method: string, url: string, data: object = {}, headers: object = {}, params: object = {}) {
@@ -41,8 +44,7 @@ export default class TastytradeHttpClient{
41
44
  data: dasherizedData,
42
45
  headers: mergedHeaders,
43
46
  params: dasherizedParams,
44
- paramsSerializer: ParamsSerializer,
45
- httpsAgent: this.httpsAgent
47
+ paramsSerializer: ParamsSerializer
46
48
  }, _.isEmpty)
47
49
 
48
50
  return axios.request(config)
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class TransactionsService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,5 +1,5 @@
1
- import extractResponseData from "../utils/response-util";
2
- import TastytradeHttpClient from "./tastytrade-http-client";
1
+ import extractResponseData from "../utils/response-util.js";
2
+ import TastytradeHttpClient from "./tastytrade-http-client.js";
3
3
 
4
4
  export default class WatchlistsService {
5
5
  constructor(private httpClient: TastytradeHttpClient) {
@@ -1,22 +1,22 @@
1
- import TastytradeHttpClient from "./services/tastytrade-http-client"
2
- import { AccountStreamer, STREAMER_STATE, Disposer, StreamerStateObserver } from './account-streamer'
3
- import MarketDataStreamer, { CandleSubscriptionOptions, CandleType, MarketDataSubscriptionType, MarketDataListener } from "./market-data-streamer"
1
+ import TastytradeHttpClient from "./services/tastytrade-http-client.js"
2
+ import { AccountStreamer, STREAMER_STATE, type Disposer, type StreamerStateObserver } from './account-streamer.js'
3
+ import MarketDataStreamer, { type CandleSubscriptionOptions, CandleType, MarketDataSubscriptionType, type MarketDataListener } from "./market-data-streamer.js"
4
4
 
5
5
  //Services:
6
- import SessionService from "./services/session-service"
7
- import AccountStatusService from "./services/account-status-service"
8
- import AccountsAndCustomersService from "./services/accounts-and-customers-service"
9
- import BalancesAndPositionsService from "./services/balances-and-positions-service"
10
- import InstrumentsService from "./services/instruments-service"
11
- import MarginRequirementsService from "./services/margin-requirements-service"
12
- import MarketMetricsService from "./services/market-metrics-service"
13
- import NetLiquidatingValueHistoryService from "./services/net-liquidating-value-history-service"
14
- import OrderService from "./services/orders-service"
15
- import RiskParametersService from "./services/risk-parameters-service"
16
- import SymbolSearchService from "./services/symbol-search-service"
17
- import TransactionsService from "./services/transactions-service"
18
- import WatchlistsService from "./services/watchlists-service"
19
- import TastytradeSession from "./models/tastytrade-session"
6
+ import SessionService from "./services/session-service.js"
7
+ import AccountStatusService from "./services/account-status-service.js"
8
+ import AccountsAndCustomersService from "./services/accounts-and-customers-service.js"
9
+ import BalancesAndPositionsService from "./services/balances-and-positions-service.js"
10
+ import InstrumentsService from "./services/instruments-service.js"
11
+ import MarginRequirementsService from "./services/margin-requirements-service.js"
12
+ import MarketMetricsService from "./services/market-metrics-service.js"
13
+ import NetLiquidatingValueHistoryService from "./services/net-liquidating-value-history-service.js"
14
+ import OrderService from "./services/orders-service.js"
15
+ import RiskParametersService from "./services/risk-parameters-service.js"
16
+ import SymbolSearchService from "./services/symbol-search-service.js"
17
+ import TransactionsService from "./services/transactions-service.js"
18
+ import WatchlistsService from "./services/watchlists-service.js"
19
+ import TastytradeSession from "./models/tastytrade-session.js"
20
20
 
21
21
  export default class TastytradeClient {
22
22
  public readonly httpClient: TastytradeHttpClient
@@ -61,5 +61,5 @@ export default class TastytradeClient {
61
61
  }
62
62
  }
63
63
 
64
- export { MarketDataStreamer, MarketDataSubscriptionType, MarketDataListener, CandleSubscriptionOptions, CandleType }
65
- export { AccountStreamer, STREAMER_STATE, Disposer, StreamerStateObserver }
64
+ export { MarketDataStreamer, MarketDataSubscriptionType, type MarketDataListener, type CandleSubscriptionOptions, CandleType }
65
+ export { AccountStreamer, STREAMER_STATE, type Disposer, type StreamerStateObserver }
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@tastytrade/api",
3
- "version": "3.0.0",
4
- "main": "dist/tastytrade-api.js",
5
- "typings": "dist/tastytrade-api.d.ts",
3
+ "version": "4.0.0",
4
+ "type": "module",
5
+ "module": "dist/tastytrade-api.js",
6
+ "types": "dist/tastytrade-api.d.ts",
7
+ "exports": {
8
+ "types": "./dist/tastytrade-api.d.ts",
9
+ "default": "./dist/tastytrade-api.js"
10
+ },
6
11
  "repository": "https://github.com/tastytrade/tastytrade-api-js",
7
12
  "license": "MIT",
8
13
  "description": "Typescript impelementation of tastytrade api",
@@ -13,8 +18,8 @@
13
18
  "scripts": {
14
19
  "build": "tsc -p tsconfig.json",
15
20
  "test": "jest -i --restoreMocks",
16
- "unit-test": "jest --testPathPattern=tests/unit",
17
- "integration-test": "jest --testPathPattern=tests/integration",
21
+ "unit-test": "node --experimental-vm-modules ./node_modules/.bin/jest tests/unit",
22
+ "integration-test": "node --experimental-vm-modules ./node_modules/.bin/jest tests/integration",
18
23
  "lint": "eslint lib/** tests/**",
19
24
  "prepublishOnly": "npm run unit-test && npm run build",
20
25
  "postpack": "git tag -a $npm_package_version -m $npm_package_version && git push origin $npm_package_version"
@@ -30,7 +35,6 @@
30
35
  "ws": "^8.13.0"
31
36
  },
32
37
  "devDependencies": {
33
- "@types/axios": "^0.14.0",
34
38
  "@types/jest": "^29.5.0",
35
39
  "@types/node": "20.9.0",
36
40
  "@types/uuid": "^9.0.2",
@@ -39,8 +43,9 @@
39
43
  "@typescript-eslint/parser": "^5.57.1",
40
44
  "dotenv": "^16.0.3",
41
45
  "eslint": "^8.14.0",
42
- "jest": "^29.5.0",
43
- "ts-jest": "^29.0.5",
44
- "typescript": "4.6.3"
46
+ "jest": "^29.7.0",
47
+ "nock": "^13.5.4",
48
+ "ts-jest": "^29.1.2",
49
+ "typescript": "^5.4.2"
45
50
  }
46
51
  }
package/tsconfig.json CHANGED
@@ -4,18 +4,18 @@
4
4
 
5
5
  /* Basic Options */
6
6
  // "incremental": true, /* Enable incremental compilation */
7
- "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
7
+ "target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
+ "module": "node16", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
9
  // "lib": [], /* Specify library files to be included in the compilation. */
10
- "allowJs": true, /* Allow javascript files to be compiled. */
10
+ "allowJs": true, /* Allow javascript files to be compiled. */
11
11
  // "checkJs": true, /* Report errors in .js files. */
12
12
  // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
- "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- // "sourceMap": true, /* Generates corresponding '.map' file. */
13
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
14
+ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
+ "sourceMap": true, /* Generates corresponding '.map' file. */
16
16
  // "outFile": "./", /* Concatenate and emit output to single file. */
17
- "outDir": "./dist", /* Redirect output structure to the directory. */
18
- // "rootDir": "./lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17
+ "outDir": "./dist", /* Redirect output structure to the directory. */
18
+ // "rootDir": "./lib", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
19
  // "composite": true, /* Enable project compilation */
20
20
  // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
21
  // "removeComments": true, /* Do not emit comments to output. */
@@ -41,14 +41,14 @@
41
41
  // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
42
 
43
43
  /* Module Resolution Options */
44
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
44
+ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45
45
  // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46
46
  // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47
47
  // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48
48
  // "typeRoots": [], /* List of folders to include type definitions from. */
49
49
  // "types": [], /* Type declaration files to be included in compilation. */
50
50
  // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
51
+ // "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52
52
  // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53
53
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54
54
 
@@ -64,7 +64,8 @@
64
64
 
65
65
  /* Advanced Options */
66
66
  "skipLibCheck": true, /* Skip type checking of declaration files. */
67
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
67
+ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
68
+ "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
68
69
  },
69
70
  "include": ["lib/**/*"],
70
71
  "exclude": ["node_modules", "dist", "tests/**/*", "examples", ".env", ".env.sample"]