Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sprgn committed Apr 25, 2019
1 parent 8c7ffff commit 8e8d7a7
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 6 deletions.
12 changes: 6 additions & 6 deletions sample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const TastyWorks = require('../lib/index');
const credentials = {
username: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD'
username: process.env.TASTY_USERNAME,
password: process.env.TASTY_PASSWORD
};

// Set the username and password
Expand All @@ -25,22 +25,22 @@ TastyWorks.authorization()
console.log('======= USER OBJECT =======');
console.log(TastyWorks.getUser());
})
.then(() => TastyWorks.balances('ACCOUNT_ID'))
.then(() => TastyWorks.balances(process.env.TASTY_ACCOUNT_ID))
.then(balances => {
console.log('======= ACCOUNT BALANCES =======');
console.log(balances)
})
.then(() => TastyWorks.positions('ACCOUNT_ID'))
.then(() => TastyWorks.positions(process.env.TASTY_ACCOUNT_ID))
.then(positions => {
console.log('======= ACCOUNT POSITIONS =======');
console.log(positions)
})
.then(() => TastyWorks.liveOrders('ACCOUNT_ID'))
.then(() => TastyWorks.liveOrders(process.env.TASTY_ACCOUNT_ID))
.then(liveOrders => {
console.log('======= ACCOUNT LIVEORDERS =======');
console.log(liveOrders)
})
.then(() => TastyWorks.history('ACCOUNT_ID', '01/01/2019', '01/05/2019'))
.then(() => TastyWorks.history(process.env.TASTY_ACCOUNT_ID, '01/01/2019', '01/05/2019'))
.then(history => {
console.log('======= ACCOUNT HISTORY =======');
console.log(history)
Expand Down
26 changes: 26 additions & 0 deletions sample/test-cancelOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const TastyWorks = require('../lib/index');
const credentials = {
username: process.env.TASTY_USERNAME,
password: process.env.TASTY_PASSWORD
};

// Set the username and password
TastyWorks.setUser(credentials);

const args = process.argv.splice(2)

// Before making any calls, get the session-token via the authorization endpoint
TastyWorks.authorization()
.then(token => {
// Set the authorization in the headers
TastyWorks.setAuthorizationToken(token);
console.log('Session is active, continue with other calls.' + token);
return true;
})
.then(() => TastyWorks.cancelOrder(process.env.TASTY_ACCOUNT_ID,args[0]))
.then(executed => {
console.log('======= ORDER CANCELED =======');
console.log(executed)
});
63 changes: 63 additions & 0 deletions sample/test-order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

const TastyWorks = require('../lib/index');
const credentials = {
username: process.env.TASTY_USERNAME,
password: process.env.TASTY_PASSWORD
};

// Set the username and password
TastyWorks.setUser(credentials);

const args = process.argv.splice(2)
var symbol = buildSymbol(args[0])


// Before making any calls, get the session-token via the authorization endpoint
TastyWorks.authorization()
.then(token => {
// Set the authorization in the headers
TastyWorks.setAuthorizationToken(token);
console.log('Session is active, continue with other calls.' + token);
return true;
})
.then(() => TastyWorks.executeOrder(process.env.TASTY_ACCOUNT_ID,symbol, 0.05, 1))
.then(executed => {
console.log('======= ORDER EXECUTED =======');
console.log(executed)
});

/**
*
* @param {string} open
*/
function buildSymbol(open) {

var parsed = open.split(" ")

var firstSpace = open.indexOf(" ")
var lastSpace = open.lastIndexOf(" ")

var wrkUnderlying = parsed[0] //open.substr(0,firstSpace)
// console.log(open.substr(firstSpace + 1))
var wrkDate = new Date(Date.parse(parsed[1] + " " + parsed[2] + " " + parsed[3]))
//new Date(Date.parse(open.substr(firstSpace + 1)))

var optionType = parsed[4]
var wrkStrike = parseFloat(parsed[5]).toFixed(3) //open.substr(lastSpace + 1)
var strike = wrkStrike.toString().replace(".", "").padStart(8,"0")

var iso = wrkDate.toISOString()
var yy = iso.substr(2,2)
var mm = iso.substr(5,2)
var dd = iso.substr(8,2)
var expDate = yy + mm + dd

var underlying = wrkUnderlying.padEnd(6," ")

console.log(open)
var builtSymbol = underlying + expDate + optionType + strike
console.log(builtSymbol)

return builtSymbol
}
43 changes: 43 additions & 0 deletions sample/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

'use strict';

const TastyWorks = require('../lib/index');

const args = process.argv.splice(2)
var open = args[0] + ""

buildSymbol(open)


function buildSymbol(open) {
// const args = process.argv.splice(2)
// var open = args[0]

var parsed = open.split(" ")

var firstSpace = open.indexOf(" ")
var lastSpace = open.lastIndexOf(" ")

var wrkUnderlying = parsed[0] //open.substr(0,firstSpace)
// console.log(open.substr(firstSpace + 1))
let wrkDate = new Date(Date.parse(parsed[1] + " " + parsed[2] + " " + parsed[3]))
//new Date(Date.parse(open.substr(firstSpace + 1)))

var optionType = parsed[4]
var wrkStrike = parseFloat(parsed[5]).toFixed(3) //open.substr(lastSpace + 1)
var strike = wrkStrike.toString().replace(".", "").padStart(8,"0")

var iso = wrkDate.toISOString()
var yy = iso.substr(2,2)
var mm = iso.substr(5,2)
var dd = iso.substr(8,2)
var expDate = yy + mm + dd

var underlying = wrkUnderlying.padEnd(6," ")

console.log(open)
var builtSymbol = underlying + expDate + optionType + strike
console.log(builtSymbol)

return builtSymbol
}

0 comments on commit 8e8d7a7

Please sign in to comment.