Price Spectre provides several sample scripts to get started. Several of these are also pre-defined algorithms that are available to all users.
All sample scripts are free to use in part or whole within Price Spectre. Users are welcome to create their own derivative works based on these samples for use within Price Spectre.
X Lowest By $Y
The X Lowest By $Y script sets a final price that is Y less than the Xth lowest price found.
if(x < 1)
throw 'X must be positive.';
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
X Lowest By Y%
The X Lowest Y% script sets a final price that is Y less than the Xth lowest price found.
if(x < 1)
throw 'X must be positive.';
if(y > 50)
throw 'Y must be 50% or less.';
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() * (1 - y/100));
break;
}
}
Average X Y%
The Average X Y% script sets a final price that is Y% less than the average X lowest prices found.
if(x < 1)
throw 'X must be positive.';
if(y > 50)
throw 'Y must be 50% or less.';
averagePrice = ps.averageX(x);
ps.setPrice(averagePrice * (1 - y/100));
Discount X Days $Y
The Discount X Days $Y script sets a final price that is Y less than the current price if X days have passed since the last price change.
if(x < 1)
throw 'X must be positive.';
if(y == 0)
throw 'Y cannot be 0.';
secondsPerDay = 86400;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceChange >= x)
ps.setPrice(currentPrice - y);
Discount X Days Y%
The Discount X Days Y% script sets a final price that is Y% less than the current price if X days have passed since the last price change.
if(x < 1)
throw 'X must be positive.';
secondsPerDay = 86400;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceChange >= x)
ps.setPrice(currentPrice * (1 - y/100));
Quota Elastic X Days Y%
The Quota Elastic script increases or decreases price Y% depending on whether the required quota of sales was achieved over the period of X days.
- Attention
- This is not the same as the pre-defined Elastic algorithm which uses the revenue generated in determining the final price.
if(x < 1)
throw 'X must be positive.';
if(y <= 0)
throw 'Y must be positive.';
if(y > 50)
throw 'Y must be 50% or less.';
quota = 3;
secondsPerDay = 86400;
secondsPerX = secondsPerDay * x;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
if(secondsSincePriceChange >= secondsPerX)
{
numSales = ps.getNumSalesSince(secondsPerX);
currentPrice = ps.getCurrentPrice();
if(numSales >= quota)
ps.setPrice(currentPrice * (1 + y/100));
else
ps.setPrice(currentPrice * (1 - y/100));
}
Ebay Products Lowest
The Find Ebay Products Lowest script uses the WS class to call eBay's Finding API and set the price $0.01 lower than the lowest price found
- Attention
- This script is provided for informational purposes only and should not be used. Leave calling eBay's API to Price Spectre as we have years of experience doing this. However this script can be used as a starting point for calling similar external APIs.
var upc = ps.getSearchParameter('keywords');
var xmlStr = "<?xml version='1.0'?>"
+ '<findItemsByProductRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">'
+ "<productId type=\"UPC\">" + upc + "</productId>"
+ "<sortOrder>PricePlusShippingLowest</sortOrder>"
+ "</findItemsByProductRequest>";
var request = new XMLDocument(xmlStr);
var headers = new Array(
"X-EBAY-SOA-OPERATION-NAME: findItemsByProduct",
"X-EBAY-SOA-SECURITY-APPNAME: <YOUR APP ID>",
"X-EBAY-SOA-GLOBAL-ID: EBAY-US",
"X-EBAY-SOA-SERVICE-VERSION: 1.11.0"
);
ws.setRequestBody(request);
ws.setHeaders(headers);
ws.setEndpoint("http://svcs.ebay.com/services/search/FindingService/v1");
var response = ws.post();
var responseXML = new XMLDocument(response);
var priceNode = responseXML.getElement('currentPrice');
var price = ps.getCurrentPrice();
if(priceNode)
{
price = priceNode.getValue() - 0.01;
}
ps.setPrice(price);