Creating update extensions
Update extensions are used to update commodity prices in Prudent. It is quite similar to import extensions in terms of structure with the exception of four differences:
@require/update-addon
start()
's processing function receivesparams
instead ofcontent
start()
expects a second , example object. Look out for this snippet in the example below:
{
epoch: '2012-Q3',
basePrice : 1000
}
- Use
price
in the protocol instead oftransactions
Example
Here's an example of an update extension with the above 4 points met:
let encode = require('@prudent/encode');
require('@prudent/update-addon').start(function(params) {
let epoch = params.epoch;
let basePrice = params.basePrice;
// Do somethign with the params, i.e. call an external service
// and/or do some maths, and when ready:
console.log(encode.protocol('price', currentPrice));
}, {
epoch: '2012-Q3',
basePrice : 1000
});
When Prudent communicates with this extension, it'll first ask for an example of parameters that this extension expects, which is again this part here:
{
epoch: '2012-Q3',
basePrice : 1000
}
When this is known, Prudent will then send params
filled with either the same example value (if there'd been no changes from the user) or different values to the processing function. This should be used within the processing function for update specific variables. When ready, do:
console.log(encode.protocol('price', currentPrice));
id: creating_update_ext title: Creating update extensions
Update extensions are used to update commodity prices in Prudent. It is quite similar to import extensions in terms of structure with the exception of four differences:
@require/update-addon
start()
's processing function receivesparams
instead ofcontent
start()
expects a second , example object. Look out for this snippet in the example below:
{
epoch: '2012-Q3',
basePrice : 1000,
pricedIn: '$',
symbol: 'ORP'
}
- Use
price
in the protocol instead oftransactions
Example
Here's an example of an update extension with the above 4 points met:
let encode = require('@prudent/encode');
require('@prudent/update-addon').start(function(params) {
let epoch = params.epoch;
let basePrice = params.basePrice;
// Do somethign with the params, i.e. call an external service
// and/or do some maths, and when ready:
console.log(encode.protocol('price', currentPrice));
}, {
epoch: '2012-Q3',
basePrice : 1000,
pricedIn: '$',
symbol: 'ORP'
});
When Prudent communicates with this extension, it'll first ask for an example of parameters that this extension expects, which is again this part here:
{
epoch: '2012-Q3',
basePrice : 1000,
pricedIn: '$',
symbol: 'ORP'
}
pricedIn
andsymbol
in the above object are mandatory parameters for commodity price update addons.pricedIn
indicates the commodity in which the commodity-to-be-updated is priced in, i.e. $.Symbol
denotes the commodity to be updated.
When this is known, Prudent will then send params
filled with either the same example value (if there'd been no changes from the user) or different values to the processing function. This should be used within the processing function for update specific variables. When ready, do:
console.log(encode.protocol('price', currentPrice));
That's all!