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 🙏

© 2024 – Pkg Stats / Ryan Hefner

stockfighter

v0.0.4

Published

node client for the stockfighter game

Downloads

5

Readme

Stockfighter Node

npm tests dependencies js-standard-style

A simple and clean API wrapper for the Stockfighter game.

Installation

npm i stockfighter -S

Usage

This library exports a class which you must initialize with an API key in order to use, as such:

import 'API' from 'stockfighter'

let client = new API({ apiKey: 'xxx' });

Once you have initialized the client, you can call any of the following methods to get back the API response. All responses are returned as promises, because I like promises and the are a much better way to handle asynchronous control flow than callbacks. If you don't use promises, this is ok, they are very easy to handle and can be treated pretty much the same as callbacks if you decide not to use their extra power. A simple example is given below:

client.heartbeat()
  .then((res) => { console.log(res) })
  .catch((err) => { console.error(err) });

Methods

Any method that takes parameters only accepts an object with the options set as key/value pairs. All methods that take options objects are documented fully along with the option names, types, and descriptions below.

client.heartbeat()

Checks if the API is online. (official docs)

client.venue(options)

Checks if a stock exchange is online. (official docs)

Options
  • venue (String): symbol for stock exchange

client.venues()

Returns a list of all venues offered by the stock exchange. (unofficial)

Options
  • None

client.venueStocks(options)

Returns a list of stocks offered by a stock exchange. (official docs)

Options
  • venue (String): symbol for stock exchange

client.orderbook(options)

Gets the order book for a specific stock. (official docs)

Options
  • venue (String): symbol for stock exchange
  • stock (String): symbol for the stock

client.buy(options)

Purchases a specific stock. (official docs)

Options
  • account (String): bank account used to purchase
  • venue (String): symbol for stock exchange
  • stock (String): symbol for the stock
  • price (Integer or String) desired price as decimal, ex. 50.42 == $50.42
  • quantity (Integer or String) number of shares to buy
  • type (String) type of order, can be 'limit', 'market', 'fill-or-kill', or 'immediate-or-cancel'. See the docs for descriptions of each type.

client.sell(options)

Sell a specific stock. (official docs)

Options
  • account (String): bank account used to purchase
  • venue (String): symbol for stock exchange
  • stock (String): symbol for the stock
  • price (Integer or String) desired price as decimal, ex. 50.42 == $50.42
  • quantity (Integer or String) number of shares to buy
  • type (String) type of order, can be 'limit', 'market', 'fill-or-kill', or 'immediate-or-cancel'. See the docs for descriptions of each type.

client.quote(opts)

Get the most recent trading information for a stock. (official docs)

Options
  • venue (String): symbol for stock exchange
  • stock (String): symbol for the stock

client.orderStatus(opts)

Get the updated status of an existing order. (official docs)

Options
  • venue (String): symbol for stock exchange
  • stock (String): symbol for the stock
  • id (Integer): id of the order

client.cancelOrder(opts)

Cancel an existing order. (official docs)

Options
  • venue (String): symbol for stock exchange
  • stock (String): symbol for the stock
  • id (Integer): id of the order

client.allOrders(opts)

See all orders in a given account's history (official docs and this too)

Options
  • venue (String): symbol for stock exchange
  • account (String): account to view orders for
  • stock (String): optional - show only orders for this specific stock

Game Master API

client.startLevel(level)

Start a level instance on stockfighter (unofficial)

Options
  • level (String): the name of the level to start

client.restartLevel(instanceId)

Restart a level instance on stockfighter (unofficial)

Options
  • instanceId (Number): the instance ID of the level to restart

client.stopLevel(instanceId)

Stop a level instance on stockfighter (unofficial)

Options
  • instanceId (Number): the instance ID of the level to stop

client.resumeLevel(instanceId)

Resume a level instance on stockfighter (unofficial)

Options
  • instanceId (Number): the instance ID of the level to resume

client.levelStatus(instanceId)

Check the status of a given level instance (unofficial)

Options
  • instanceId (Number): the instance ID of the level

Websockets

client.openWebsocket(options)

Open a websocket for tickertape or executions. Returns the websocket object if you would like to handle it yourself instead of using the options callbacks. (unofficial)

Options
  • type (String): either tickertape or executions. Defaults to tickertape.
  • venue (String): the venue to filter on. Defaults to none.
  • stock (String): the stock to filter on. Defaults to none.
  • onOpen (Function): optional callback for the open websocket channel
  • onMessage (Function): optional callback for the message websocket channel
  • onClose (Function): optional callback for the close websocket channel
  • onError (Function): optional callback for the error websocket channel
  • reconnect (Boolean): will attempt to reconnect the websocket when closed. Defaults to false.

client.tickertape(options)

Sugar to open a tickertape websocket

client.executions(options)

Sugar to open a tickertape websocket

client.setAccount(id)

Set your account number before opening a websocket. Your account number is set automatically when starting, resuming, or restarting a level.

License and Contributing

Any contributions are welcome, just make a pull request! If you want to check and make sure I'm ok with it, just open an issue and ask. Also make sure you add tests, it's very simple to do so and important to keep things in line. In order to get the tests running, you must make a copy of config.sample.js and rename it as config.js, then add your own API key. Tests are not yet running on travis because I need to do some crazy encryption stuff. I'll do this eventually, in the meantime we will have to be satisfied with locally running tests.

This project is licensed under MIT, and the full license can be found here.