Browse Source

Change meaning of num, ave, max utxo

jl777
jl777 7 years ago
parent
commit
d8d3716e41
  1. 6
      iguana/exchanges/LP_prices.c
  2. 8
      iguana/exchanges/LP_signatures.c
  3. 42
      iguana/exchanges/LP_utxo.c
  4. 2
      iguana/exchanges/coins

6
iguana/exchanges/LP_prices.c

@ -755,9 +755,9 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op)
jaddstr(item,"address",op->coinaddr);
jaddnum(item,"price",op->price);
jaddnum(item,"numutxos",op->numutxos);
jaddnum(item,"avevolume",dstr(op->avesatoshis)*0.8);
jaddnum(item,"maxvolume",dstr(op->maxsatoshis)*0.8);
jaddnum(item,"depth",dstr(op->depth)*0.8);
jaddnum(item,"avevolume",dstr(op->avesatoshis));
jaddnum(item,"maxvolume",dstr(op->maxsatoshis));
jaddnum(item,"depth",dstr(op->depth));
jaddbits256(item,"pubkey",op->pubkey);
jaddnum(item,"age",time(NULL)-op->timestamp);
jaddnum(item,"zcredits",dstr(op->dynamictrust));

8
iguana/exchanges/LP_signatures.c

@ -422,7 +422,7 @@ int32_t LP_price_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pub
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price)
{
struct iguana_info *basecoin,*relcoin,*kmd; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson;
struct iguana_info *basecoin,*relcoin,*kmd; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,median,minsize,maxsize; bits256 zero; cJSON *reqjson;
reqjson = cJSON_CreateObject();
// LP_addsig
if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 )//&& basecoin->electrum == 0 )//&& relcoin->electrum == 0 )
@ -441,12 +441,12 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
jaddstr(reqjson,"pubsecp",pubsecpstr);
if ( (kmd= LP_coinfind("KMD")) != 0 && (ap= LP_address(kmd,kmd->smartaddr)) != 0 && ap->instantdex_credits != 0 )
jaddnum(reqjson,"credits",dstr(ap->instantdex_credits));
if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
if ( (numutxos= LP_address_minmax(&median,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
{
//printf("send %s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize));
printf("send %s numutxos.%d median %.8f min %.8f max %.8f\n",base,numutxos,dstr(median),dstr(minsize),dstr(maxsize));
jaddstr(reqjson,"utxocoin",base);
jaddnum(reqjson,"n",numutxos);
jaddnum(reqjson,"bal",dstr(balance));
jaddnum(reqjson,"bal",dstr(median) * n);
jaddnum(reqjson,"min",dstr(minsize));
jaddnum(reqjson,"max",dstr(maxsize));
}

42
iguana/exchanges/LP_utxo.c

@ -283,30 +283,56 @@ struct LP_address *LP_address(struct iguana_info *coin,char *coinaddr)
return(ap);
}
int32_t LP_address_minmax(uint64_t *balancep,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
int32_t LP_address_minmax(uint64_t *medianp,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
{
cJSON *array,*item; bits256 txid,zero; int64_t value; int32_t i,vout,height,n = 0;
*minp = *maxp = *balancep = 0;
cJSON *array,*item; bits256 txid,zero; int64_t max,max2,value,*buf; int32_t i,m=0,vout,height,n = 0;
*minp = *maxp = *medianp = max = max2 = 0;
memset(zero.bytes,0,sizeof(zero));
if ( (array= LP_listunspent(coin->symbol,coinaddr,zero,zero)) != 0 )
{
//printf("address minmax.(%s)\n",jprint(array,0));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
buf = calloc(sizeof(*buf),n);
for (i=m=0; i<n; i++)
{
item = jitem(array,i);
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
if ( value > *maxp )
*maxp = value;
if ( LP_allocated(txid,vout) != 0 )
continue;
m++;
if ( value > max )
{
max2 = max;
max = value;
}
else if ( value > max2 )
max2 = value;
if ( *minp == 0 || value < *minp )
*minp = value;
*balancep += value;
}
if ( m > 1 )
{
revsort64s(buf,m,sizeof(*buf));
if ( max == buf[0] && max2 == buf[1] )
{
for (i=1; i<m; i++)
{
if ( max >= LP_DEPOSITSATOSHIS(buf[i]) )
{
*maxp = buf[i];
*medianp = buf[m/2];
break;
}
}
}
else printf("sort error? max %.8f != %.8f\n",dstr(max),dstr(buf[0]));
} else *minp = *maxp = *medianp = 0;
free(buf);
}
free_json(array);
}
return(n);
return(m/2);
}
int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap,char *coinaddr)

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save