Browse Source

Test

etomic
jl777 7 years ago
parent
commit
9115729750
  1. 11
      iguana/exchanges/LP_commands.c
  2. 4
      iguana/exchanges/LP_ordermatch.c
  3. 14
      iguana/exchanges/LP_portfolio.c
  4. 20
      iguana/exchanges/LP_utxos.c

11
iguana/exchanges/LP_commands.c

@ -115,7 +115,6 @@ tradesarray(base, rel, starttime=<now>-timescale*1024, endtime=<now>, timescale=
pricearray(base, rel, starttime=0, endtime=0, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\ pricearray(base, rel, starttime=0, endtime=0, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\
getrawtransaction(coin, txid)\n\ getrawtransaction(coin, txid)\n\
inventory(coin, reset=0, [passphrase=])\n\ inventory(coin, reset=0, [passphrase=])\n\
bestfit(rel, relvolume)\n\
lastnonce()\n\ lastnonce()\n\
buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, destpubkey="")\n\ buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, destpubkey="")\n\
sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce, destpubkey="")\n\ sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce, destpubkey="")\n\
@ -385,13 +384,13 @@ zeroconf_claim(address, expiration=0)\n\
} else return(clonestr("{\"error\":\"no price set\"}")); } else return(clonestr("{\"error\":\"no price set\"}"));
} }
} }
else if ( rel[0] != 0 && strcmp(method,"bestfit") == 0 ) /*else if ( rel[0] != 0 && strcmp(method,"bestfit") == 0 )
{ {
double relvolume; double relvolume;
if ( (relvolume= jdouble(argjson,"relvolume")) > SMALLVAL ) if ( (relvolume= jdouble(argjson,"relvolume")) > SMALLVAL )
return(LP_bestfit(rel,relvolume)); return(LP_bestfit(rel,relvolume));
else return(clonestr("{\"error\":\"no relvolume set\"}")); else return(clonestr("{\"error\":\"no relvolume set\"}"));
} }*/
else if ( coin[0] != 0 ) else if ( coin[0] != 0 )
{ {
if ( strcmp(method,"enable") == 0 ) if ( strcmp(method,"enable") == 0 )
@ -548,9 +547,11 @@ zeroconf_claim(address, expiration=0)\n\
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
jaddstr(retjson,"coin",coin); jaddstr(retjson,"coin",coin);
jaddnum(retjson,"timestamp",time(NULL)); jaddnum(retjson,"timestamp",time(NULL));
jadd(retjson,"alice",LP_inventory(coin)); jadd(retjson,"alice",cJSON_Parse("[]"));
//jadd(retjson,"alice",LP_inventory(coin));
//jadd(retjson,"bob",LP_inventory(coin,1)); //jadd(retjson,"bob",LP_inventory(coin,1));
LP_smartutxos_push(ptr); //LP_smartutxos_push(ptr);
LP_address_utxo_reset(ptr);
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
} }

4
iguana/exchanges/LP_ordermatch.c

@ -751,7 +751,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag)
return(n); return(n);
} }
char *LP_bestfit(char *rel,double relvolume) /*char *LP_bestfit(char *rel,double relvolume)
{ {
struct LP_utxoinfo *autxo; struct LP_utxoinfo *autxo;
if ( relvolume <= 0. || LP_priceinfofind(rel) == 0 ) if ( relvolume <= 0. || LP_priceinfofind(rel) == 0 )
@ -759,7 +759,7 @@ char *LP_bestfit(char *rel,double relvolume)
if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 )
return(clonestr("{\"error\":\"cant find utxo that is close enough in size\"}")); return(clonestr("{\"error\":\"cant find utxo that is close enough in size\"}"));
return(jprint(LP_utxojson(autxo),1)); return(jprint(LP_utxojson(autxo),1));
} }*/
int32_t LP_aliceonly(char *symbol) int32_t LP_aliceonly(char *symbol)
{ {

14
iguana/exchanges/LP_portfolio.c

@ -63,7 +63,7 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr)
} }
free_json(array); free_json(array);
} }
if ( (array= LP_inventory(symbol)) != 0 ) /*if ( (array= LP_inventory(symbol)) != 0 )
{ {
if ( (n= cJSON_GetArraySize(array)) > 0 && is_cJSON_Array(array) != 0 ) if ( (n= cJSON_GetArraySize(array)) > 0 && is_cJSON_Array(array) != 0 )
{ {
@ -75,8 +75,9 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr)
} }
} }
free_json(array); free_json(array);
} }*/
*valuep = valuesum; *valuep = valuesum;
satoshisum = valuesum;
return(satoshisum); return(satoshisum);
} }
@ -489,7 +490,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,struct iguana_info *buy,struct iguana_info *sell,double relvolume,int32_t setbaserel,char *gui) int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,struct iguana_info *buy,struct iguana_info *sell,double relvolume,int32_t setbaserel,char *gui)
{ {
char *retstr2; double bid,ask,maxprice; bits256 zero; uint32_t requestid,quoteid,iter,i; cJSON *retjson2; char *retstr2; uint64_t txfee,desttxfee; double bid,ask,maxprice; bits256 zero; uint32_t requestid,quoteid,iter,i; cJSON *retjson2; struct LP_utxoinfo A; struct LP_address_utxo *utxos[1000]; int32_t max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
LP_txfees(&txfee,&desttxfee,buy->symbol,sell->symbol);
requestid = quoteid = 0; requestid = quoteid = 0;
LP_myprice(&bid,&ask,buy->symbol,sell->symbol); LP_myprice(&bid,&ask,buy->symbol,sell->symbol);
maxprice = ask; maxprice = ask;
@ -507,7 +509,8 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str
{ {
if ( relvolume < dstr(LP_MIN_TXFEE) ) if ( relvolume < dstr(LP_MIN_TXFEE) )
break; break;
if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 ) if ( LP_address_myutxopair(&A,0,utxos,max,sell,sell->symbol,txfee,relvolume,maxprice,desttxfee) == 0 )
//if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 )
{ {
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
if ( (retstr2= LP_autobuy(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui,LP_lastnonce+1,zero,1)) != 0 ) if ( (retstr2= LP_autobuy(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui,LP_lastnonce+1,zero,1)) != 0 )
@ -531,7 +534,8 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str
for (i=0; i<100; i++) for (i=0; i<100; i++)
{ {
relvolume *= .99; relvolume *= .99;
if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 ) if ( LP_address_myutxopair(&A,0,utxos,max,sell,sell->symbol,txfee,relvolume,maxprice,desttxfee) == 0 )
//if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 )
{ {
printf("i.%d relvolume %.8f from %.8f\n",i,relvolume,sell->relvolume); printf("i.%d relvolume %.8f from %.8f\n",i,relvolume,sell->relvolume);
break; break;

20
iguana/exchanges/LP_utxos.c

@ -194,7 +194,7 @@ void LP_availableset(struct LP_utxoinfo *utxo)
} }
} }
} }
*/
cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo)
{ {
@ -327,16 +327,6 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t
return(0); return(0);
} }
txfee = LP_txfeecalc(coin,0,0); txfee = LP_txfeecalc(coin,0,0);
/*if ( iambob != 0 && value2 < 9 * (satoshis >> 3) + 2*txfee ) // big txfee padding
{
if ( value2 > 2*txfee )
tmpsatoshis = (((value2 - 2*txfee) / 9) << 3);
else
{
printf("value2 %.8f <= 2 * %.8f\n",dstr(value2),dstr(txfee));
return(0);
}
} else tmpsatoshis = (satoshis - txfee);*/
char str[65],str2[65],dispflag = 0;//(iambob == 0); char str[65],str2[65],dispflag = 0;//(iambob == 0);
if ( iambob == 0 && bits256_cmp(pubkey,G.LP_mypub25519) != 0 ) if ( iambob == 0 && bits256_cmp(pubkey,G.LP_mypub25519) != 0 )
{ {
@ -527,7 +517,7 @@ cJSON *LP_inventory(char *symbol)
printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,utxo->payment.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,utxo->payment.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0);
} }
return(array); return(array);
} }*/
int32_t LP_maxvalue(uint64_t *values,int32_t n) int32_t LP_maxvalue(uint64_t *values,int32_t n)
{ {
@ -582,7 +572,7 @@ int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t
int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub)
{ {
int32_t enable_utxos = 0; int32_t enable_utxos = 0;
char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,biggerval,value,total = 0; int64_t targetval; char *script,destaddr[64]; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,biggerval,value,total = 0; int64_t targetval; //struct LP_utxoinfo *utxo;
if ( coin == 0 || (IAMLP == 0 && coin->inactive != 0) ) if ( coin == 0 || (IAMLP == 0 && coin->inactive != 0) )
{ {
//printf("coin not active\n"); //printf("coin not active\n");
@ -682,7 +672,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri
{ {
value = values[i]; value = values[i];
values[i] = 0, used++; values[i] = 0, used++;
portable_mutex_lock(&LP_UTXOmutex); /*portable_mutex_lock(&LP_UTXOmutex);
if ( iambob != 0 ) if ( iambob != 0 )
{ {
if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,biggerval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 ) if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,biggerval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 )
@ -696,7 +686,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri
{ {
} }
} }
portable_mutex_unlock(&LP_UTXOmutex); portable_mutex_unlock(&LP_UTXOmutex);*/
total += value; total += value;
} // else printf("scriptmismatch.(%s) vs %s\n",script,jprint(item,0)); } // else printf("scriptmismatch.(%s) vs %s\n",script,jprint(item,0));
} //else printf("nothing near i.%d\n",i); } //else printf("nothing near i.%d\n",i);

Loading…
Cancel
Save