Browse Source

Test

etomic
jl777 7 years ago
parent
commit
17ec4b0e92
  1. 9
      iguana/exchanges/LP_commands.c
  2. 1
      iguana/exchanges/LP_nativeDEX.c
  3. 95
      iguana/exchanges/LP_prices.c
  4. 2
      iguana/exchanges/pricearray

9
iguana/exchanges/LP_commands.c

@ -94,6 +94,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r
else if ( strcmp(method,"help") == 0 ) else if ( strcmp(method,"help") == 0 )
return(clonestr("{\"result\":\" \ return(clonestr("{\"result\":\" \
available localhost RPC commands:\n \ available localhost RPC commands:\n \
pricearray(base, rel, timescale=60)\n\
setprice(base, rel, price)\n\ setprice(base, rel, price)\n\
autoprice(base, rel, price, margin, type)\n\ autoprice(base, rel, price, margin, type)\n\
goal(coin=*, perc=<autocalc>)\n\ goal(coin=*, perc=<autocalc>)\n\
@ -185,12 +186,10 @@ trust(pubkey, trust)\n\
return(clonestr("{\"error\":\"couldnt set autoprice\"}")); return(clonestr("{\"error\":\"couldnt set autoprice\"}"));
else return(clonestr("{\"result\":\"success\"}")); else return(clonestr("{\"result\":\"success\"}"));
} }
/*else if ( strcmp(method,"autofill") == 0 ) else if ( strcmp(method,"pricearray") == 0 )
{ {
if ( LP_autofill(base,rel,price,jdouble(argjson,"relvolume")) < 0 ) return(jprint(LP_pricearray(base,rel,jint(argjson,"timescale")),1));
return(clonestr("{\"error\":\"couldnt set autofill\"}")); }
else return(clonestr("{\"result\":\"success\"}"));
}*/
else if ( strcmp(method,"myprice") == 0 ) else if ( strcmp(method,"myprice") == 0 )
{ {
if ( LP_myprice(&bid,&ask,base,rel) > SMALLVAL ) if ( LP_myprice(&bid,&ask,base,rel) > SMALLVAL )

1
iguana/exchanges/LP_nativeDEX.c

@ -24,7 +24,6 @@
// bugs: // bugs:
// false detection of bobreclaim // false detection of bobreclaim
// relax ordermatch constraints?
// unduplicated bugs: // unduplicated bugs:
// swap cancel should cleanly cancel // swap cancel should cleanly cancel

95
iguana/exchanges/LP_prices.c

@ -649,6 +649,99 @@ void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveas
LP_priceinfoupdate(base,rel,price); LP_priceinfoupdate(base,rel,price);
} }
void LP_pricefname(char *fname,char *base,char *rel)
{
sprintf(fname,"%s/PRICES/%s_%s",GLOBAL_DBDIR,base,rel);
OS_compatible_path(fname);
}
void LP_priceitemadd(cJSON *retarray,uint32_t timestamp,double avebid,double aveask,double highbid,double lowask)
{
cJSON *item = cJSON_CreateArray();
jaddinum(item,timestamp);
jaddinum(item,avebid);
jaddinum(item,aveask);
jaddinum(item,highbid);
jaddinum(item,lowask);
jaddi(retarray,item);
}
cJSON *LP_pricearray(char *base,char *rel,int32_t timescale)
{
cJSON *retarray; char askfname[1024],bidfname[1024]; uint64_t bidprice64,askprice64; uint32_t bidnow,asknow,bidi,aski,firstbidi,firstaski,lastbidi,lastaski; int32_t numbids,numasks; double bidemit,askemit,bidsum,asksum,bid,ask,highbid,lowbid,highask,lowask; FILE *askfp=0,*bidfp=0;
if ( timescale <= 0 )
timescale = 60;
LP_pricefname(askfname,base,rel);
LP_pricefname(bidfname,rel,base);
retarray = cJSON_CreateArray();
firstbidi = firstaski = lastbidi = lastaski = 0;
numbids = numasks = 0;
bidsum = asksum = askemit = bidemit = highbid = lowbid = highask = lowask = 0.;
if ( (bidfp= fopen(bidfname,"rb")) != 0 && (askfp= fopen(askfname,"rb")) != 0 )
{
bidi = aski = 0;
bidemit = askemit = 0.;
if ( bidfp != 0 && fread(&bidnow,1,sizeof(bidnow),bidfp) == sizeof(bidnow) && fread(&bidprice64,1,sizeof(bidprice64),bidfp) == sizeof(bidprice64) && bidnow != 0 && bidprice64 != 0 )
{
bidi = bidnow / timescale;
if ( bidi != lastbidi )
{
if ( bidsum != 0 && numbids != 0 )
bidemit = bidsum / numbids;
bidsum = 0.;
numbids = 0;
}
bid = dstr(bidprice64);
bidsum += bid;
numbids++;
} else fclose(bidfp), bidfp = 0;
if ( askfp != 0 && fread(&asknow,1,sizeof(asknow),askfp) == sizeof(asknow) && fread(&askprice64,1,sizeof(askprice64),askfp) == sizeof(askprice64) && asknow != 0 && askprice64 != 0 )
{
aski = asknow / timescale;
if ( aski != lastaski )
{
if ( asksum != 0 && numasks != 0 )
askemit = asksum / numasks;
asksum = 0.;
numasks = 0;
}
ask = dstr(askprice64);
asksum += ask;
numasks++;
} else fclose(askfp), askfp = 0;
if ( bidemit != 0. || askemit != 0. )
{
if ( bidemit != 0. && askemit != 0. && lastbidi == lastaski )
{
LP_priceitemadd(retarray,lastbidi * timescale,bidemit,askemit,highbid,lowask);
highbid = lowbid = highask = lowask = 0.;
}
else
{
if ( bidemit != 0. )
{
LP_priceitemadd(retarray,lastbidi * timescale,bidemit,0.,highbid,0.);
highbid = lowbid = 0.;
}
if ( askemit != 0. )
{
LP_priceitemadd(retarray,lastaski * timescale,0.,askemit,0.,lowask);
highask = lowask = 0.;
}
}
}
if ( bidi != 0 )
lastbidi = bidi;
if ( aski != 0 )
lastaski = aski;
}
if ( bidfp != 0 )
fclose(bidfp);
if ( askfp != 0 )
fclose(askfp);
return(retarray);
}
void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
{ {
struct LP_priceinfo *basepp,*relpp; uint32_t now; uint64_t price64; struct LP_pubkeyinfo *pubp; char str[65],fname[512]; FILE *fp; struct LP_priceinfo *basepp,*relpp; uint32_t now; uint64_t price64; struct LP_pubkeyinfo *pubp; char str[65],fname[512]; FILE *fp;
@ -657,7 +750,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
{ {
if ( (fp= basepp->fps[relpp->ind]) == 0 ) if ( (fp= basepp->fps[relpp->ind]) == 0 )
{ {
sprintf(fname,"%s/PRICES/%s_%s",GLOBAL_DBDIR,base,rel); LP_pricefname(fname,base,rel);
fp = basepp->fps[relpp->ind] = OS_appendfile(fname); fp = basepp->fps[relpp->ind] = OS_appendfile(fname);
} }
if ( fp != 0 && price > SMALLVAL ) if ( fp != 0 && price > SMALLVAL )

2
iguana/exchanges/pricearray

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"pricearray\",\"base\":\"REVS\",\"rel\":\"KMD\",\"timescale\":60}"
Loading…
Cancel
Save