Shatterhand
05-12-2013, 09:19 AM
Here is a function for getting item prices from the zybez price guide. Calculates weighted average from the last X offers.
API: http://forums.zybez.net/runescape-2007-prices/api/?info
type
Offer = record
selling : Boolean;
quantity : Integer;
price : Integer;
date : Integer;
name : String;
valid : Boolean;
comment : String;
end;
function GetPrice(Item: String) : Integer;
var
str, templine, s1, s2 : String;
Offers : Array[1..100] of Offer;
explodes : Array of String;
maxsamples, i, j,
recentlow, recenthigh, highalch : Integer;
buyquantity, sellquantity, buyvalue, sellvalue,
buyprice, sellprice : Integer;
DebugMode : Boolean;
begin
Result := 0;
buyquantity := 0;
sellquantity := 0;
buyvalue := 0;
sellvalue := 0;
//DEBUG
DebugMode := True;
//last X offers
maxsamples := 100;
//getting page
explodes := Explode(' ',Item);
Item := Implode('+',explodes);
str := GetPage('http://forums.zybez.net/runescape-2007-prices/api/' + Item);
if (str = '{"error":"No results found."}') then
begin
Writeln('{"error":"No results found."}');
Exit;
end;
explodes := Explode('+',Item);
explodes[0] := Capitalize(explodes[0]);
Item := Implode(' ',explodes);
str := Between('"name":"'+Item+'"', ']}', str);
str := str + ']}';
recentlow := StrToInt(Between('recent_low":"', '"',str));
recenthigh := StrToInt(Between('recent_high":"', '"',str));
highalch := StrToInt(Between('high_alch":"', '"',str));
str := Between('"offers":[', ']}', str);
str := str + ',';
//getting lines
s1 := '{';
s2 := '},';
for i:=1 to maxsamples do
begin
templine := Between(s1, s2, str);
s1 := templine + '},{';
case Between('selling":"', '"', templine) of
'0': Offers[i].selling := False;
'1': Offers[i].selling := True;
end;
Offers[i].quantity := CashStrToInt(Between('quantity":"', '"', templine));
Offers[i].price := CashStrToInt(Between('price":"', '"', templine));
Offers[i].date := CashStrToInt(Between('date":"', '"', templine));
Offers[i].name := Between('rs_name":"', '"', templine);
Offers[i].valid := True;
Offers[i].comment := '';
end;
//removing: name duplicates
for i:=1 to maxsamples do
begin
j := 1;
while (j < i) do
begin
if (Offers[i].name = Offers[j].name) then
begin
Offers[i].valid := False;
Offers[i].comment := '[name duplicate]';
Break;
end;
Inc(j);
end;
end;
//removing: lower than 0.8*highalch
for i:=1 to maxsamples do
begin
if (Offers[i].price < (highalch*0.8)) then
begin
Offers[i].valid := False;
Offers[i].comment := '[lower than 0.8*highalch]';
end;
end;
//removing: higher than 1.5*recenthigh
for i:=1 to maxsamples do
begin
if not (recenthigh = 0) then
if (Offers[i].price > (recenthigh*1.5)) then
begin
Offers[i].valid := False;
Offers[i].comment := '[higher than 1.5*recenthigh]';
end;
end;
//removing: overflow
for i:=1 to maxsamples do
begin
if ((Offers[i].price * Offers[i].quantity) < 0) then
begin
Offers[i].valid := False;
Offers[i].comment := '[overflow]';
end;
end;
//Offers - DEBUG
for i:=1 to maxsamples do
begin
Writeln('['+IntToStr(i)+'] '+ 'selling: '+BoolToStr(Offers[i].selling)+', quantity: '+IntToStr(Offers[i].quantity)+', price: '+IntToStr(Offers[i].price)+', date: '+IntToStr(Offers[i].date)+', name: '+Offers[i].name+', valid: '+BoolToStr(Offers[i].valid)+' '+Offers[i].comment);
end;
//getting quantities, prices
for i:=1 to maxsamples do
begin
if (Offers[i].valid = True) then
begin
if (Offers[i].selling = True) then
begin
sellvalue := sellvalue + Offers[i].quantity * Offers[i].price;
sellquantity := sellquantity + Offers[i].quantity;
end;
if (Offers[i].selling = False) then
begin
buyvalue := buyvalue + Offers[i].quantity * Offers[i].price;
buyquantity := buyquantity + Offers[i].quantity;
end;
end;
end;
//calculating result
if not (buyquantity = 0) then
buyprice := buyvalue / buyquantity
else
buyprice := 0;
if not (sellquantity = 0) then
sellprice := sellvalue / sellquantity
else
sellprice := 0;
Result := (buyprice + sellprice) / 2;
//DEBUG
if DebugMode then
begin
Writeln('buyprice: ' + IntToStr(buyprice));
Writeln('buyvalue: ' + IntToStr(buyvalue));
Writeln('buyquantity: ' + IntToStr(buyquantity));
Writeln('sellprice: ' + IntToStr(sellprice));
Writeln('sellvalue: ' + IntToStr(sellvalue));
Writeln('sellquantity: ' + IntToStr(sellquantity));
end;
end;
Writeln(IntToStr(GetPrice('rune scimitar')));
(Working on this...)
CalcInvPrice. Calculates the price of the inventory, using GetPrice or manual prices for each items.
program PriceChecker;
{$DEFINE SMART}
{$I SRL-OSR/SRL.simba}
{$IFDEF SMART}
{$I SRL-OSR/SRL/misc/SmartGraphics.simba}
{$ENDIF}
const
ManualPrice = False;
//set it True if you want to set the prices yourself
//set it False if you want to use zybez price guide prices
type
Item = record
name : String;
amount : Integer;
price : Integer;
end;
function GetPrice(Item: String) : Integer;
var
str, templine, s1, s2 : String;
name, selling, quantity, price : String;
Lines, Names : Array[1..100] of String;
maxsamples, i, j,
buyquantity, sellquantity, buyvalue, sellvalue,
buyprice, sellprice: Integer;
match : Boolean;
begin
Result := 0;
//last X offers
maxsamples := 50;
buyquantity := 0;
sellquantity := 0;
buyvalue := 0;
sellvalue := 0;
//getting page
str := GetPage('http://forums.zybez.net/runescape-2007-prices/api/' + Item);
if (str = '{"error":"No results found."}') then Exit;
str := Between('"offers":[', ']}]', str);
str := str + ',';
s1 := '{';
s2 := '},';
//getting lines
for i:=1 to maxsamples do
begin
templine := Between(s1, s2, str);
s1 := templine + '},{';
Lines[i] := templine;
end;
//getting names, removing duplicates
for i:=1 to maxsamples do
begin
name := Between('"rs_name":"', '"', Lines[i]);
match := False;
j := 1;
while ((j < i) and (match = False)) do
begin
if (name = Names[j]) then
match := True;
Inc(j);
end;
if (match = False) then
Names[i] := name
else
Lines[i] := '-------------------------------- DELETED, NAME DUPLICATES --------------------------------';
end;
//getting quantities, prices
for i:=1 to maxsamples do
begin
templine := Lines[i];
if not (templine = '') then
begin
selling := Between('"selling":"', '"', templine);
quantity := Between('"quantity":"', '"', templine);
price := Between('"price":"', '"', templine);
if (selling = '1') then
begin
sellvalue := sellvalue + StrToInt(quantity) * StrToInt(price);
sellquantity := sellquantity + StrToInt(quantity);
end;
if (selling = '0') then
begin
buyvalue := buyvalue + StrToInt(quantity) * StrToInt(price);
buyquantity := buyquantity + StrToInt(quantity);
end;
end;
end;
if not (buyquantity = 0) then
buyprice := Round(buyvalue / buyquantity)
else
buyprice := 0;
if not (sellquantity = 0) then
sellprice := Round(sellvalue / sellquantity)
else
sellprice := 0;
Result := (buyprice + sellprice) / 2;
//DEBUG
//for i:=1 to maxsamples do
// Writeln('[' + IntToStr(i) + '] ' + Lines[i]);
//Writeln('buyprice: ' + IntToStr(buyprice));
//Writeln('buyvalue: ' + IntToStr(buyvalue));
//Writeln('buyquantity: ' + IntToStr(buyquantity));
//Writeln('sellprice: ' + IntToStr(sellprice));
//Writeln('sellvalue: ' + IntToStr(sellvalue));
//Writeln('sellquantity: ' + IntToStr(sellquantity));
end;
function FormatValue(value : Integer) : String;
var
kmod, mmod : Integer;
begin
if (value < 1000) then
Result := IntToStr(value)
else
begin
kmod := value mod 1000;
Result := IntToStr((value-kmod)/1000) + 'k';
end;
end;
procedure CalcInvPrice;
var
X,Y, i, sum, price : Integer;
opts : Array of TOptions;
text, input : String;
Items : Array[1..28] of Item;
begin
for i:=1 to 28 do
begin
if ExistsItem(i) then
begin
Items[i].amount := GetAmountBox(InvBox(i));
end;
end;
for i:=1 to 28 do
begin
if ExistsItem(i) then
begin
MouseItem(i,mouse_right);
opts := GetChooseOptions;
text := opts[High(opts)-1].str;
text := Replace(text,'Examine ','');
text := Replace(text,'Examine','');
Items[i].name := text;
ChooseOption('asd');
end;
end;
sum := 0;
for i:=1 to 28 do
begin
if not (Items[i].amount = 0) then
begin
if (Items[i].name = 'Coins') then
begin
Writeln(IntToStr(Items[i].amount) + ' x ' + Items[i].name + ' = ' + FormatValue(Items[i].amount));
sum := sum + Items[i].amount;
end else
begin
text := Items[i].name;
text := Replace(text,' ','+');
if ManualPrice then
if InPutQuery('Price',Items[i].name + ':',input) then
price := StrToInt(input)
else
price := GetPrice(text)
else
price := GetPrice(text);
Writeln(IntToStr(Items[i].amount) + ' x ' + Items[i].name + ' = ' + IntToStr(Items[i].amount) + ' x ' + IntToStr(price) + ' = ' + FormatValue(Items[i].amount*price));
sum := sum + Items[i].amount*price;
end;
end;
end;
Writeln('');
Writeln('Total value: ' + FormatValue(sum));
end;
begin
ClearDebug;
SetupSRL;
CalcInvPrice;
end.
API: http://forums.zybez.net/runescape-2007-prices/api/?info
type
Offer = record
selling : Boolean;
quantity : Integer;
price : Integer;
date : Integer;
name : String;
valid : Boolean;
comment : String;
end;
function GetPrice(Item: String) : Integer;
var
str, templine, s1, s2 : String;
Offers : Array[1..100] of Offer;
explodes : Array of String;
maxsamples, i, j,
recentlow, recenthigh, highalch : Integer;
buyquantity, sellquantity, buyvalue, sellvalue,
buyprice, sellprice : Integer;
DebugMode : Boolean;
begin
Result := 0;
buyquantity := 0;
sellquantity := 0;
buyvalue := 0;
sellvalue := 0;
//DEBUG
DebugMode := True;
//last X offers
maxsamples := 100;
//getting page
explodes := Explode(' ',Item);
Item := Implode('+',explodes);
str := GetPage('http://forums.zybez.net/runescape-2007-prices/api/' + Item);
if (str = '{"error":"No results found."}') then
begin
Writeln('{"error":"No results found."}');
Exit;
end;
explodes := Explode('+',Item);
explodes[0] := Capitalize(explodes[0]);
Item := Implode(' ',explodes);
str := Between('"name":"'+Item+'"', ']}', str);
str := str + ']}';
recentlow := StrToInt(Between('recent_low":"', '"',str));
recenthigh := StrToInt(Between('recent_high":"', '"',str));
highalch := StrToInt(Between('high_alch":"', '"',str));
str := Between('"offers":[', ']}', str);
str := str + ',';
//getting lines
s1 := '{';
s2 := '},';
for i:=1 to maxsamples do
begin
templine := Between(s1, s2, str);
s1 := templine + '},{';
case Between('selling":"', '"', templine) of
'0': Offers[i].selling := False;
'1': Offers[i].selling := True;
end;
Offers[i].quantity := CashStrToInt(Between('quantity":"', '"', templine));
Offers[i].price := CashStrToInt(Between('price":"', '"', templine));
Offers[i].date := CashStrToInt(Between('date":"', '"', templine));
Offers[i].name := Between('rs_name":"', '"', templine);
Offers[i].valid := True;
Offers[i].comment := '';
end;
//removing: name duplicates
for i:=1 to maxsamples do
begin
j := 1;
while (j < i) do
begin
if (Offers[i].name = Offers[j].name) then
begin
Offers[i].valid := False;
Offers[i].comment := '[name duplicate]';
Break;
end;
Inc(j);
end;
end;
//removing: lower than 0.8*highalch
for i:=1 to maxsamples do
begin
if (Offers[i].price < (highalch*0.8)) then
begin
Offers[i].valid := False;
Offers[i].comment := '[lower than 0.8*highalch]';
end;
end;
//removing: higher than 1.5*recenthigh
for i:=1 to maxsamples do
begin
if not (recenthigh = 0) then
if (Offers[i].price > (recenthigh*1.5)) then
begin
Offers[i].valid := False;
Offers[i].comment := '[higher than 1.5*recenthigh]';
end;
end;
//removing: overflow
for i:=1 to maxsamples do
begin
if ((Offers[i].price * Offers[i].quantity) < 0) then
begin
Offers[i].valid := False;
Offers[i].comment := '[overflow]';
end;
end;
//Offers - DEBUG
for i:=1 to maxsamples do
begin
Writeln('['+IntToStr(i)+'] '+ 'selling: '+BoolToStr(Offers[i].selling)+', quantity: '+IntToStr(Offers[i].quantity)+', price: '+IntToStr(Offers[i].price)+', date: '+IntToStr(Offers[i].date)+', name: '+Offers[i].name+', valid: '+BoolToStr(Offers[i].valid)+' '+Offers[i].comment);
end;
//getting quantities, prices
for i:=1 to maxsamples do
begin
if (Offers[i].valid = True) then
begin
if (Offers[i].selling = True) then
begin
sellvalue := sellvalue + Offers[i].quantity * Offers[i].price;
sellquantity := sellquantity + Offers[i].quantity;
end;
if (Offers[i].selling = False) then
begin
buyvalue := buyvalue + Offers[i].quantity * Offers[i].price;
buyquantity := buyquantity + Offers[i].quantity;
end;
end;
end;
//calculating result
if not (buyquantity = 0) then
buyprice := buyvalue / buyquantity
else
buyprice := 0;
if not (sellquantity = 0) then
sellprice := sellvalue / sellquantity
else
sellprice := 0;
Result := (buyprice + sellprice) / 2;
//DEBUG
if DebugMode then
begin
Writeln('buyprice: ' + IntToStr(buyprice));
Writeln('buyvalue: ' + IntToStr(buyvalue));
Writeln('buyquantity: ' + IntToStr(buyquantity));
Writeln('sellprice: ' + IntToStr(sellprice));
Writeln('sellvalue: ' + IntToStr(sellvalue));
Writeln('sellquantity: ' + IntToStr(sellquantity));
end;
end;
Writeln(IntToStr(GetPrice('rune scimitar')));
(Working on this...)
CalcInvPrice. Calculates the price of the inventory, using GetPrice or manual prices for each items.
program PriceChecker;
{$DEFINE SMART}
{$I SRL-OSR/SRL.simba}
{$IFDEF SMART}
{$I SRL-OSR/SRL/misc/SmartGraphics.simba}
{$ENDIF}
const
ManualPrice = False;
//set it True if you want to set the prices yourself
//set it False if you want to use zybez price guide prices
type
Item = record
name : String;
amount : Integer;
price : Integer;
end;
function GetPrice(Item: String) : Integer;
var
str, templine, s1, s2 : String;
name, selling, quantity, price : String;
Lines, Names : Array[1..100] of String;
maxsamples, i, j,
buyquantity, sellquantity, buyvalue, sellvalue,
buyprice, sellprice: Integer;
match : Boolean;
begin
Result := 0;
//last X offers
maxsamples := 50;
buyquantity := 0;
sellquantity := 0;
buyvalue := 0;
sellvalue := 0;
//getting page
str := GetPage('http://forums.zybez.net/runescape-2007-prices/api/' + Item);
if (str = '{"error":"No results found."}') then Exit;
str := Between('"offers":[', ']}]', str);
str := str + ',';
s1 := '{';
s2 := '},';
//getting lines
for i:=1 to maxsamples do
begin
templine := Between(s1, s2, str);
s1 := templine + '},{';
Lines[i] := templine;
end;
//getting names, removing duplicates
for i:=1 to maxsamples do
begin
name := Between('"rs_name":"', '"', Lines[i]);
match := False;
j := 1;
while ((j < i) and (match = False)) do
begin
if (name = Names[j]) then
match := True;
Inc(j);
end;
if (match = False) then
Names[i] := name
else
Lines[i] := '-------------------------------- DELETED, NAME DUPLICATES --------------------------------';
end;
//getting quantities, prices
for i:=1 to maxsamples do
begin
templine := Lines[i];
if not (templine = '') then
begin
selling := Between('"selling":"', '"', templine);
quantity := Between('"quantity":"', '"', templine);
price := Between('"price":"', '"', templine);
if (selling = '1') then
begin
sellvalue := sellvalue + StrToInt(quantity) * StrToInt(price);
sellquantity := sellquantity + StrToInt(quantity);
end;
if (selling = '0') then
begin
buyvalue := buyvalue + StrToInt(quantity) * StrToInt(price);
buyquantity := buyquantity + StrToInt(quantity);
end;
end;
end;
if not (buyquantity = 0) then
buyprice := Round(buyvalue / buyquantity)
else
buyprice := 0;
if not (sellquantity = 0) then
sellprice := Round(sellvalue / sellquantity)
else
sellprice := 0;
Result := (buyprice + sellprice) / 2;
//DEBUG
//for i:=1 to maxsamples do
// Writeln('[' + IntToStr(i) + '] ' + Lines[i]);
//Writeln('buyprice: ' + IntToStr(buyprice));
//Writeln('buyvalue: ' + IntToStr(buyvalue));
//Writeln('buyquantity: ' + IntToStr(buyquantity));
//Writeln('sellprice: ' + IntToStr(sellprice));
//Writeln('sellvalue: ' + IntToStr(sellvalue));
//Writeln('sellquantity: ' + IntToStr(sellquantity));
end;
function FormatValue(value : Integer) : String;
var
kmod, mmod : Integer;
begin
if (value < 1000) then
Result := IntToStr(value)
else
begin
kmod := value mod 1000;
Result := IntToStr((value-kmod)/1000) + 'k';
end;
end;
procedure CalcInvPrice;
var
X,Y, i, sum, price : Integer;
opts : Array of TOptions;
text, input : String;
Items : Array[1..28] of Item;
begin
for i:=1 to 28 do
begin
if ExistsItem(i) then
begin
Items[i].amount := GetAmountBox(InvBox(i));
end;
end;
for i:=1 to 28 do
begin
if ExistsItem(i) then
begin
MouseItem(i,mouse_right);
opts := GetChooseOptions;
text := opts[High(opts)-1].str;
text := Replace(text,'Examine ','');
text := Replace(text,'Examine','');
Items[i].name := text;
ChooseOption('asd');
end;
end;
sum := 0;
for i:=1 to 28 do
begin
if not (Items[i].amount = 0) then
begin
if (Items[i].name = 'Coins') then
begin
Writeln(IntToStr(Items[i].amount) + ' x ' + Items[i].name + ' = ' + FormatValue(Items[i].amount));
sum := sum + Items[i].amount;
end else
begin
text := Items[i].name;
text := Replace(text,' ','+');
if ManualPrice then
if InPutQuery('Price',Items[i].name + ':',input) then
price := StrToInt(input)
else
price := GetPrice(text)
else
price := GetPrice(text);
Writeln(IntToStr(Items[i].amount) + ' x ' + Items[i].name + ' = ' + IntToStr(Items[i].amount) + ' x ' + IntToStr(price) + ' = ' + FormatValue(Items[i].amount*price));
sum := sum + Items[i].amount*price;
end;
end;
end;
Writeln('');
Writeln('Total value: ' + FormatValue(sum));
end;
begin
ClearDebug;
SetupSRL;
CalcInvPrice;
end.