Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/examples/postcss-8…
Browse files Browse the repository at this point in the history
….4.31
  • Loading branch information
dmoss18 authored Nov 10, 2023
2 parents 49388e8 + a495ca0 commit 871f0c9
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [20.x, 21.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -17,7 +17,7 @@ jobs:
cache: 'npm'
- run: npm install
- run: npm run lint
- run: npm run test
- run: npm run unit-test
env:
BASE_URL: ${{ secrets.BASE_URL }}
API_USERNAME: ${{ secrets.API_USERNAME }}
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
14 changes: 9 additions & 5 deletions lib/account-streamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _ from 'lodash'
import type { JsonMap, JsonValue } from './utils/json-util'
import { JsonBuilder } from './utils/json-util'
import TastytradeSession from './models/tastytrade-session'
import { MinTlsVersion } from './utils/constants'

export enum STREAMER_STATE {
Open = 0,
Expand Down Expand Up @@ -123,7 +124,10 @@ export class AccountStreamer {
return this.startPromise
}

const websocket = (this.websocket = new WebSocket(this.url))
this.websocket = new WebSocket(this.url, [], {
minVersion: MinTlsVersion // TLS Config
})
const websocket = this.websocket
this.lastCloseEvent = null
this.lastErrorEvent = null
websocket.addEventListener('open', this.handleOpen)
Expand Down Expand Up @@ -300,7 +304,7 @@ export class AccountStreamer {
this.queued = []
}

private readonly handleOpen = (event: Event) => {
private readonly handleOpen = (event: WebSocket.Event) => {
if (this.startResolve === null) {
return
}
Expand All @@ -315,7 +319,7 @@ export class AccountStreamer {
this.scheduleHeartbeatTimer()
}

private readonly handleClose = (event: CloseEvent) => {
private readonly handleClose = (event: WebSocket.CloseEvent) => {
this.logger.info('AccountStreamer closed', event)
if (this.websocket === null) {
return
Expand All @@ -326,7 +330,7 @@ export class AccountStreamer {
this.teardown()
}

private readonly handleError = (event: Event) => {
private readonly handleError = (event: WebSocket.ErrorEvent) => {
if (this.websocket === null) {
return
}
Expand All @@ -344,7 +348,7 @@ export class AccountStreamer {
this.teardown()
}

private readonly handleMessage = (event: MessageEvent) => {
private readonly handleMessage = (event: WebSocket.MessageEvent) => {
const json = JSON.parse(event.data as string) as JsonMap

if (json.results !== undefined) {
Expand Down
11 changes: 7 additions & 4 deletions lib/market-data-streamer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import WebSocket from 'isomorphic-ws'
import _ from 'lodash'
import { v4 as uuidv4 } from 'uuid'
import { MinTlsVersion } from './utils/constants'

export enum MarketDataSubscriptionType {
Candle = 'Candle',
Expand Down Expand Up @@ -89,7 +90,9 @@ export default class MarketDataStreamer {
}

this.token = token
this.webSocket = new WebSocket(url)
this.webSocket = new WebSocket(url, [], {
minVersion: MinTlsVersion // TLS Config
})
this.webSocket.onopen = this.onOpen.bind(this)
this.webSocket.onerror = this.onError.bind(this)
this.webSocket.onmessage = this.handleMessageReceived.bind(this)
Expand Down Expand Up @@ -343,9 +346,9 @@ export default class MarketDataStreamer {
this.errorListeners.forEach(listener => listener(error))
}

private handleMessageReceived(data: string) {
const messageData = _.get(data, 'data', data)
const jsonData = JSON.parse(messageData)
private handleMessageReceived(data: WebSocket.MessageEvent) {
const messageData = _.get(data, 'data', '{}')
const jsonData = JSON.parse(messageData as string)
switch (jsonData.type) {
case 'AUTH_STATE':
this.handleAuthStateMessage(jsonData)
Expand Down
7 changes: 6 additions & 1 deletion lib/services/tastytrade-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import axios from "axios"
import qs from 'qs'
import { recursiveDasherizeKeys } from "../utils/json-util"
import _ from 'lodash'
import https from 'https'
import { MinTlsVersion } from "../utils/constants"

const ParamsSerializer = {
serialize: function (queryParams: object) {
Expand All @@ -12,9 +14,11 @@ const ParamsSerializer = {

export default class TastytradeHttpClient{
public readonly session: TastytradeSession
private readonly httpsAgent: https.Agent

constructor(private readonly baseUrl: string) {
this.session = new TastytradeSession()
this.httpsAgent = new https.Agent({ minVersion: MinTlsVersion })
}

private getDefaultHeaders(): any {
Expand All @@ -37,7 +41,8 @@ export default class TastytradeHttpClient{
data: dasherizedData,
headers: mergedHeaders,
params: dasherizedParams,
paramsSerializer: ParamsSerializer
paramsSerializer: ParamsSerializer,
httpsAgent: this.httpsAgent
}, _.isEmpty)

return axios.request(config)
Expand Down
1 change: 1 addition & 0 deletions lib/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MinTlsVersion = 'TLSv1.2'
83 changes: 72 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"name": "@tastytrade/api",
"version": "2.1.1",
"version": "3.0.0",
"main": "dist/tastytrade-api.js",
"typings": "dist/tastytrade-api.d.ts",
"repository": "https://github.com/tastytrade/tastytrade-api-js",
"license": "MIT",
"description": "Typescript impelementation of tastytrade api",
"engines": {
"npm": ">=9.0.0",
"node": ">=20.0.0"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "jest -i --restoreMocks",
"unit-test": "jest --testPathPattern=tests/unit",
"integration-test": "jest --testPathPattern=tests/integration",
"lint": "eslint lib/** tests/**",
"prepublishOnly": "npm run test && npm run build",
"prepublishOnly": "npm run unit-test && npm run build",
"postpack": "git tag -a $npm_package_version -m $npm_package_version && git push origin $npm_package_version"
},
"dependencies": {
Expand All @@ -26,9 +30,11 @@
"ws": "^8.13.0"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/jest": "^29.5.0",
"@types/node": "17.0.27",
"@types/node": "20.9.0",
"@types/uuid": "^9.0.2",
"@types/ws": "^8.5.9",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"dotenv": "^16.0.3",
Expand Down

0 comments on commit 871f0c9

Please sign in to comment.