"Price Spectre"  1.0
Sample Scripts

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.

// X Lowest By $Y
// Assumes "Perform Search Automatically" is selected.
// Copyright 2011 NullApps
if(x < 1)
throw 'X must be positive.';
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
count++;
// if this is the listing to match against
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.

// X Lowest Y%
// Assumes "Perform Search Automatically" is selected.
// Copyright 2011 NullApps
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 this is the listing to match against
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.

// Average X Y%
// Assumes "Perform Search Automatically" is NOT selected.
// Copyright 2011 NullApps
if(x < 1)
throw 'X must be positive.';
if(y > 50)
throw 'Y must be 50% or less.';
// Grab the average of the X lowest priced listings.
averagePrice = ps.averageX(x);
// Sets price to y% lower than the average of the lowest X prices found.
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.

// Discount X Days $Y
// Copyright 2011 NullApps
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.

// Discount X Days Y%
// Copyright 2011 NullApps
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.
// Quota Elastic X Days Y%
// Copyright 2011 NullApps
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();
// Make sure enough time has elapsed.
if(secondsSincePriceChange >= secondsPerX)
{
numSales = ps.getNumSalesSince(secondsPerX);
currentPrice = ps.getCurrentPrice();
// Change price by y% depending on if sales quota has been reached.
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.
// Find Ebay Products Lowest
// Copyright 2011 NullApps
// fetch UPC from keywords
var upc = ps.getSearchParameter('keywords');
// create request XML
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);