1.3.8 • Published 7 years ago

trading-post v1.3.8

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Trading Post

NPM module for interacting with the trading-post. Can be used as a library and/or a CLI tool

Build Status npm version

Credentials

To obtain the information you'll need to build a credentials.json, you'll want to visit https://trading-post.club. After login, copy paste just the refresh_token into a credentials.json like so:

{
  "refresh_token": "i-made-this-up"
}

Both the library & CLI tool will automatically exchange the refresh_token for an access_token when necessary and cache it back in the credentials.json file.

CLI

Install

yarn global add trading-post

Example Usage

trading-post buy --quantity 100 goog

Library

Install

yarn add trading-post

Usage

const TradingPost = require('trading-post')
const tradingPost = new TradingPost({
  baseUrl: 'https://trading-post.club',
  credentialsFile: '/path/to/credentials.json',
})

tradingPost.getUser((error, user) => {
  if (error) throw error
  console.log(JSON.stringify(user))
  // =>
  // {
  //   "name": "Roy van de Water",
  //   "riches": 0,
  //   "stocks": [
  //     {
  //       "quantity": 0,
  //       "ticker": "goog"
  //     }
  //   ]
  // }

Functions

Constructor

ParameterTypeRequiredDescription
optionsobjectyes
options.baseUrlstringyesURL where the trading-post API can be found.
options.credentialsFilestringyesMust point to a JSON file and contain a refresh_token. access_token will automatically be retrieved and cached here.

const tradingPost  = new TradingPost({
  baseUrl: 'https://trading-post.club',
  credentialsFile: './credentials.json'
})

createBuyOrder

ParameterTypeRequiredDescription
optionsobjectyes
options.quantitystringyesQuantity of stock to purchase
options.tickerstringyesStock ticker name to purchase (case insensitive)
callbackfunctionyesWill be called with error or buyOrder when the request is complete

tradingPost.createBuyOrder({ quantity: 1, ticker: 'goog' }, (error, buyOrder) => {
  if (error) throw error
  console.log(JSON.stringify(buyOrder, null, 2))
  // =>
  // {
  //   "id": "8c5989bb-400f-4232-877b-86b5de7ff5bb",
  //   "price": 920.29,
  //   "quantity": 1,
  //   "ticker": "goog",
  //   "timestamp": "2017-09-16T14:02:33.907049934Z"
  // }
})

createSellOrder

ParameterTypeRequiredDescription
optionsobjectyes
options.quantitystringyesQuantity of stock to sell
options.tickerstringyesStock ticker name to sell (case insensitive)
callbackfunctionyesWill be called with error or sellOrder when the request is complete

tradingPost.createSellOrder({ quantity: 1, ticker: 'goog' }, (error, sellOrder) => {
  if (error) throw error
  console.log(JSON.stringify(buyOrder, null, 2))
  // =>
  // {
  //   "id": "e85d1724-2e84-48cc-8d4a-331f4fbd8477",
  //   "price": 920.29,
  //   "quantity": 1,
  //   "ticker": "goog",
  //   "timestamp": "2017-09-16T14:03:32.312353738Z"
  // }
})

getUser

ParameterTypeRequiredDescription
callbackfunctionyesWill be called with error or user when the request is complete

tradingPost.getUser((error, user) => {
  if (error) throw error
  console.log(JSON.stringify(user, null, 2))
  // =>
  // {
  //   "name": "Roy van de Water",
  //   "riches": 0,
  //   "stocks": [
  //     {
  //       "quantity": 0,
  //       "ticker": "goog"
  //     }
  //   ]
  // }
})
1.3.8

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago