npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@slowclap/tastytrade-api

v0.0.4

Published

Typescript impelementation of tastytrade api

Readme

Tastytrade Api Javascript SDK

Installation

npm: npm i @tastytrade/api

yarn: yarn add @tastytrade/api

Quickstart

import TastytradeClient from "@tastytrade/api"

const tastytradeApi = new TastytradeClient({ baseUrl, accountStreamerUrl })
const loginResponse = await tastytradeApi.sessionService.login(usernameOrEmail, password)
const accounts = await tastytradeApi.accountsAndCustomersService.getCustomerAccounts()
const accountPositions = await tastytradeApi.balancesAndPositionsService.getPositionsList(accounts[0].account['account-number'])

Market Data

The MarketDataStreamer in this package is deprecated. We recommend using DxFeed's @dxfeed/dxlink-api instead.

Here's a node example of how you can subscribe to some future option quotes using @dxfeed/dxlink-api:

/**
 * Below code assumes you've hit GET /api-quote-tokens and received a token
 * You should also hit GET /futures-option-chains/{future_contract_code}/nested to get the future options you want to subscribe to
 * There is an equivalent GET /option-chains/{underlying_ticker_symbol}/nested for equity options
 */

const WebSocket = require('isomorphic-ws')
const { DXLinkWebSocketClient, DXLinkFeed, FeedDataFormat } = require('@dxfeed/dxlink-api')
global.WebSocket = WebSocket

const token = '<api quote token>'
const client = new DXLinkWebSocketClient()
client.connect('wss://tasty-openapi-ws.dxfeed.com/realtime')
client.setAuthToken(token)

const feed = new DXLinkFeed(client, 'AUTO')

// Note: Calling feed.configure is optional - omitting it means DxLink will return all fields
feed.configure({
  acceptAggregationPeriod: 10,
  acceptDataFormat: FeedDataFormat.COMPACT,
  acceptEventFields: {
    Quote: ['eventSymbol', 'askPrice', 'bidPrice']
  },
})

feed.addEventListener((events) => {
  events.map(event => {
    console.log(event)
  })
})

feed.addSubscriptions({
  type: 'Quote',
  symbol: './EW4Q24C5750:XCME', // Please note: we don't update this README daily. This symbol may be expired. You'll have to find an unexpired symbol.
})

To run the above code, save it to a file and run node <filename>.js in a terminal.

When adding a subscription, the symbol value should be the put-streamer-symbol or call-streamer-symbol returned by the GET /futures-option-chains/{future_contract_code}/nested endpoint. For example:

// GET /futures-option-chains/ES/nested response:
{
  "strike-price": "5750.0",
  "call": "./ESU4 EW4Q4 240823C5750",
  "call-streamer-symbol": "./EW4Q24C5750:XCME", <-- use this value
  "put": "./ESU4 EW4Q4 240823P5750",
  "put-streamer-symbol": "./EW4Q24P5750:XCME" <-- or this value
}

To subscribe to equities quotes, the symbol is just the ticker symbol, like AAPL.

Account Streamer

import TastytradeClient from "@tastytrade/api"
import _ from 'lodash'

function handleStreamerMessage(json) {
  console.log('streamer message received: ', json)
}

function handleStreamerStateChange(streamerState) {
  console.log('streamer state changed: ', streamerState)
}

const tastytradeClient = new TastytradeClient({ baseUrl, accountStreamerUrl })
const accountStreamer = tastytradeClient.accountStreamer
const loginResponse = await tastytradeClient.sessionService.login(usernameOrEmail, password)
const accounts = await tastytradeClient.accountsAndCustomersService.getCustomerAccounts()
const accountNumbers = _.map(accounts, account => _.get(account, 'account.account-number'))
await accountStreamer.start()
await accountStreamer.subscribeToAccounts(accountNumbers)
accountStreamer.addMessageObserver(handleStreamerMessage)
accountStreamer.addStreamerStateObserver(handleStreamerStateChange)

You should then be able to place a trade and see live status updates for the order come through via handleStreamerMessage.

Running in Node

The cometd package has an explicit reference to window, so there's not a perfect way to run this code in a NodeJs. You could fake the window object to get it running. You'll have to npm install ws and do this:

const WebSocket = require('ws')

global.WebSocket = WebSocket
global.window = { WebSocket, setTimeout, clearTimeout }

Building Locally

npm run build Outputs everything to dist/

Running tests locally

Add a .env file with the following keys (you'll have to fill in the values yourself):

BASE_URL=https://api.cert.tastyworks.com
API_USERNAME=<your cert username>
API_PASSWORD=<your cert password>
API_ACCOUNT_NUMBER=<your cert account number>

These values should match whatever username/password/account you set up in the tastytrade sandbox environment. Head to developer.tastyworks.com to get that set up.

Running example app

npm run build
cd examples/
npm install
npm run dev

Open http://localhost:3000 with your browser to see the result.

Tests

Unit tests are for specific pieces of code and should not make any external calls (http requests). If needed, you can mock out an http response in your unit test.

For testing actual api requests, use the tests/integration folder.

Directory structure should match the lib structure. Service tests will go in tests/unit/service/<servicefilename>.test.ts