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-client

v1.0.5

Published

stockfighter client. For more information, visit https://www.stockfighter.io

Downloads

3

Readme

stockfighter-client

Instructions

> npm install stockfighter-client

Then, in your code:

var sf = require('stockfighter-client')(apiKey);

Supported methods

Unless otherwise stated, all API methods return a Promise which resolves to an object.

  • sf.heartbeat() => Promise
  • sf.heartbeat(venue) => Promise
  • sf.stocks(venue) => Promise
  • sf.orderbook(venue, stock) => Promise
  • sf.quote(venue, stock) => Promise
  • sf.orders.create(params) => Promise
  • sf.orders.status(venue, stock, id) => Promise
  • sf.orders.all(venue, account) => Promise
  • sf.orders.stock(venue, account, stock) => Promise
  • sf.orders.cancel(venue, stock, id) => Promise
  • sf.orders.cancelPost(venue, stock, id) => Promise

Socket methods return an event emitter which emits a stream of 'message' events.

  • sf.sockets.tickertape(account, venue) => EventEmitter
  • sf.sockets.tickertape(account, venue, stock) => EventEmitter
  • sf.sockets.executions(account, venue) => EventEmitter
  • sf.sockets.executions(account, venue, stock) => EventEmitter

GameMaster (GM) API for starting/stopping levels

  • sf.gm.create(name) => Promise
  • sf.gm.status(id) => Promise
  • sf.gm.restart(id) => Promise
  • sf.gm.stop(id) => Promise
  • sf.gm.resume(id) => Promise

Calling the API from a Coroutine

'use strict';
var API_KEY = 'XXXXXXXXX(replace this value)XXXXXXXXXXX';
var sf = require('stockfighter-client')(API_KEY);
var Promise = require('bluebird');

// We like coroutines because it allows very clean control flow
// using the yield keyword.
Promise.coroutine(function*() {
	try {
		let result;
		// *** heartbeat
		result = yield sf.heartbeat();
		console.log(result);
		// *** orderbook
		result = yield sf.orderbook('TESTEX', 'FOOBAR');
		console.log(result);
		// *** place order
		result = yield sf.orders.create({
			account: 'ACCOUNT123',
			venue: 'TESTEX',
			stock: 'FOOBAR',
			qty: 100,
			direction: 'buy',
			orderType: 'market'
		});
		// *** capture 5 seconds of tickertape from WebSockets API
		let tickertape = sf.sockets.tickertape('ACCOUNT123', 'TESTEX');
		tickertape.on('message', (e) => console.log('tickertape:', e));
		setTimeout(() => tickertape.close(), 5000);
	}
	catch(err) {
		console.error(err.stack);
	}
})();

Using Promises

var API_KEY = 'XXXXXXXXX(replace this value)XXXXXXXXXXX';
var sf = require('stockfighter-client')(API_KEY);
// *** heartbeat
sf.heartbeat().then(function (res) {
	console.log('heartbeat:', res);
	// *** stock quote
	return sf.quote('TESTEX', 'FOOBAR');
})
.then(function (res) {
	console.log('quote:', res);
	// *** create order
	return sf.orders.create({
		account: 'ACCOUNT123',
		venue: 'TESTEX',
		stock: 'FOOBAR',
		qty: 100,
		direction: 'buy',
		orderType: 'market'
	});
})
.then(function (order) {
	console.log('created:', order);
	// *** cancel order
	return sf.orders.cancel('TESTEX', 'FOOBAR', order.id);
});
// *** now, let's use the websocket api:
var tickertape = sf.sockets.tickertape('ACCOUNT123', 'TESTEX');
tickertape.on('message', function (message) {
	console.log('tickertape:', message);
});
var executions = sf.sockets.executions('ACCOUNT123', 'TESTEX');
exectutions.on('message', function (message) {
	console.log('executions:', message);
})
// *** shut down websockets after 5 seconds of activity
setTimeout(function () {
	tickertape.close();
	executions.close();
}, 5000);