Node API wrapper for https://www.stockfighter.io
OTHER License
A simple and clean API wrapper for the Stockfighter game.
npm i stockfighter -S
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) });
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.
Checks if the API is online. (official docs)
Checks if a stock exchange is online. (official docs)
Returns a list of all venues offered by the stock exchange. (unofficial)
Returns a list of stocks offered by a stock exchange. (official docs)
Gets the order book for a specific stock. (official docs)
Purchases a specific stock. (official docs)
Sell a specific stock. (official docs)
Get the most recent trading information for a stock. (official docs)
Get the updated status of an existing order. (official docs)
Cancel an existing order. (official docs)
See all orders in a given account's history (official docs and this too)
Start a level instance on stockfighter (unofficial)
Restart a level instance on stockfighter (unofficial)
Stop a level instance on stockfighter (unofficial)
Resume a level instance on stockfighter (unofficial)
Check the status of a given level instance (unofficial)
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)
tickertape
or executions
. Defaults to tickertape
.open
websocket channelmessage
websocket channelclose
websocket channelerror
websocket channelfalse
.Sugar to open a tickertape websocket
Sugar to open a tickertape websocket
Set your account number before opening a websocket. Your account number is set automatically when starting, resuming, or restarting a level.
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.