A simple client-side JS client for stockfighter.io ported from jenius's stockfighter node api wrapper. Props to jenius for the great work on the code and the documentation!
This project includes a simple node server that will proxy your client-side AJAX calls and allow you to play the game from chrome's browser console.
- Install node
- Clone or download this repo.
- In your terminal,
cdinto the repo folder (whereverserver.jsis) - Run
npm installto install project dependencies - Run
node server.jsto start the server - Visit 127.0.0.1:8000 in chrome
- Open up the console and start firing commands at the stockfighter api!
This library exposes a class which you must initialize with an API key in order to use, as such:
var client = new ApiClient(your_api_key);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)
- venue (String): symbol for stock exchange
Returns a list of stocks offered by a stock exchange. (official docs)
- venue (String): symbol for stock exchange
Gets the order book for a specific stock. (official docs)
- venue (String): symbol for stock exchange
- stock (String): symbol for the stock
Purchases a specific stock. (official docs)
- 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.
Sell a specific stock. (official docs)
- 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.
Get the most recent trading information for a stock. (official docs)
- venue (String): symbol for stock exchange
- stock (String): symbol for the stock
Get the updated status of an existing order. (official docs)
- venue (String): symbol for stock exchange
- stock (String): symbol for the stock
- id (Integer): id of the order
Cancel an existing order. (official docs)
- venue (String): symbol for stock exchange
- stock (String): symbol for the stock
- id (Integer): id of the order
See all orders in a given account's history (official docs and this too)
- venue (String): symbol for stock exchange
- account (String): account to view orders for
- stock (String): optional - show only orders for this specific stock
Get updated when a stock quote is updated (official docs)
- venue (String): symbol for stock exchange
- account (String): account to view orders for
- cb (Function): callback function for when a new quote comes in
- stock (String): optional - show only quotes for this specific stock
Get updated when a fill goes through (official docs)
- venue (String): symbol for stock exchange
- account (String): account to view orders for
- cb (Function): callback function for when a new fill comes in
- stock (String): optional - show only fills for this specific stock
This project is licensed under MIT.