Skip to content

Commit

Permalink
Merge pull request #8 from sujansaundara/feat/expiry_time
Browse files Browse the repository at this point in the history
Add getExpiry_Time Feature
  • Loading branch information
abmohan committed Jul 25, 2016
2 parents 427efde + 192545e commit 9d1fa30
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/account-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ coinut.getPositions()
console.log('Positions:', positions);
})
.catch(errorHandler);


31 changes: 31 additions & 0 deletions examples/trans-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const assert = require('assert');
const Coinut = require('../dist');

// import environment variables
const username = process.env.COINUT_USERNAME || '';
const apiKey = process.env.COINUT_API_KEY || '';

// ensure environment variables are defined
assert(username, 'Missing environment variable COINUT_USERNAME. Type ' +
'`export COINUT_USERNAME=<your username>` in the terminal and try again.');

assert(apiKey, 'Missing environment variable COINUT_API_KEY. Type ' +
'`export COINUT_API_KEY=<your api key>` in the terminal and try again.');

const coinut = new Coinut(username, apiKey);

const errorHandler = (error) => {
console.error('Error connecting to Coinut:', error.message);
};

coinut.getExpiry_Time('VANILLA_OPTION', 'BTCUSD', 'CALL' )
.then(expiry_time => {
console.log('Expiry Time:', expiry_time);
})
.catch(errorHandler);

coinut.getAssets()
.then(assets => {
console.log('Assets:', assets);
})
.catch(errorHandler);
32 changes: 31 additions & 1 deletion lib/Coinut.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,25 @@ function coinutApiRequest(endpoint, username, apiKey, data) {
.then(JSON.parse);
}

function coinutApiRequestNoAuth(endpoint, data) {
const uri = `${coinutApiBaseUrl}/${endpoint}`;
const requestContent = Object.assign({ nonce: encryption.getNonce() }, data);
const body = JSON.stringify(requestContent);
const headers = {};

const requestOptions = { uri, headers, body};
return rp.post(requestOptions)
.then(JSON.parse);

}



class Coinut {
constructor(username, apiKey) {
constructor(username, apiKey, data) {
this.username = username;
this.apiKey = apiKey;
this.data = data;
}

getBalance() {
Expand All @@ -40,6 +54,22 @@ class Coinut {
return coinutApiRequest('positions', this.username, this.apiKey);
}

getExpiry_Time(derivativeType, assetType, putcallType) {
const data = { 'deriv_type' : derivativeType,
'asset' : assetType,
'put_call' : putcallType
};
// payload data for request
return coinutApiRequestNoAuth('expiry_time', data)
}

getAssets() {
return coinutApiRequestNoAuth('assets')
}




}

exports.default = module.exports = Coinut;
30 changes: 30 additions & 0 deletions test/Coinut.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,35 @@ describe('Coinut', () => {
});
});

describe('Coinut.getExpiry_Time', () => {
const mockResponseData = [1423656000, 1423670400, 1423684800, 1423699200, 1423713600, 1423728000];

let expiry_timeP;
let rpStub;

beforeEach(() => {
// return stubbed response instead of actual POST call to Coinut
rpStub = sinon.stub(rp, 'post');
rpStub.returns(Promise.resolve(JSON.stringify(mockResponseData)));

// make API request call
expiry_timeP = coinut.getExpiry_Time();
});

afterEach(() => {
// restore stubbed function
rp.post.restore();
});

it('should be a function', () => {
expect(coinut.getExpiry_Time).to.exist;
expect(coinut.getExpiry_Time).to.be.a('function');
});

it('should return an array of Expiry Times', () => {
return expect(expiry_timeP).to.eventually.deep.equal(mockResponseData);
});
});


});

0 comments on commit 9d1fa30

Please sign in to comment.