Browse Source

Bot status

etomic
jl777 7 years ago
parent
commit
e655f82bfb
  1. 1
      iguana/exchanges/LP_include.h
  2. 1
      iguana/exchanges/LP_nativeDEX.c
  3. 37
      iguana/exchanges/LP_ordermatch.c
  4. 28
      iguana/exchanges/LP_tradebots.c

1
iguana/exchanges/LP_include.h

@ -392,6 +392,7 @@ uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);
void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid,uint32_t quoteid);
uint64_t LP_RTsmartbalance(struct iguana_info *coin);
int32_t LP_getheight(struct iguana_info *coin);
int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg);

1
iguana/exchanges/LP_nativeDEX.c

@ -19,7 +19,6 @@
// marketmaker
//
// detecting new deposits in inventory
// BTC swaps
// bot progress
// swap started event for bot
// bot status 1600% ?

37
iguana/exchanges/LP_ordermatch.c

@ -464,9 +464,15 @@ char *LP_connectedalice(cJSON *argjson) // alice
{
cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,B,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; //uint64_t value,value2;
if ( LP_quoteparse(&Q,argjson) < 0 )
{
LP_aliceid(Q.tradeid,Q.aliceid,"error0",0,0);
clonestr("{\"error\":\"cant parse quote\"}");
}
if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 )
{
LP_aliceid(Q.tradeid,Q.aliceid,"error1",0,0);
return(clonestr("{\"result\",\"update stats\"}"));
}
printf("CONNECTED.(%s) numpending.%d tradeid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid);
/*if ( LP_alice_eligible() == 0 || LP_quotecmp(&Q,&LP_Alicequery) != 0 )
{
@ -479,16 +485,22 @@ char *LP_connectedalice(cJSON *argjson) // alice
if ( (autxo= LP_utxopairfind(0,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 )
{
printf("cant find autxo\n");
LP_aliceid(Q.tradeid,Q.aliceid,"error2",0,0);
return(clonestr("{\"error\":\"cant find autxo\"}"));
}
if ( autxo->S.swap != 0 )
{
LP_aliceid(Q.tradeid,Q.aliceid,"error3",0,0);
return(clonestr("{\"error\":\"ignore duplicate swap\"}"));
}
LP_aliceid(Q.tradeid,Q.aliceid,"connected",Q.R.requestid,Q.R.quoteid);
butxo = &B;
memset(butxo,0,sizeof(*butxo));
LP_abutxo_set(0,butxo,&Q);
if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL )
{
LP_availableset(autxo);
LP_aliceid(Q.tradeid,Q.aliceid,"error4",0,0);
printf("quote validate error %.0f\n",qprice);
return(clonestr("{\"error\":\"quote validation error\"}"));
}
@ -496,12 +508,16 @@ char *LP_connectedalice(cJSON *argjson) // alice
{
printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask);
LP_availableset(autxo);
LP_aliceid(Q.tradeid,Q.aliceid,"error5",0,0);
return(clonestr("{\"error\":\"no price set\"}"));
}
printf("%s/%s bid %.8f ask %.8f values %.8f %.8f\n",Q.srccoin,Q.destcoin,bid,ask,dstr(butxo->payment.value),dstr(butxo->deposit.value));
price = bid;
if ( (coin= LP_coinfind(Q.destcoin)) == 0 )
{
LP_aliceid(Q.tradeid,Q.aliceid,"error6",0,0);
return(clonestr("{\"error\":\"cant get alicecoin\"}"));
}
Q.privkey = LP_privkey(Q.destaddr,coin->taddr);
if ( bits256_nonz(Q.privkey) != 0 )//&& Q.quotetime >= Q.timestamp-3 )
{
@ -511,10 +527,14 @@ char *LP_connectedalice(cJSON *argjson) // alice
{
jaddstr(retjson,"error","couldnt swapinit");
LP_availableset(autxo);
LP_aliceid(Q.tradeid,Q.aliceid,"error7",Q.R.requestid,Q.R.quoteid);
return(jprint(retjson,1));
}
if ( (pairstr= jstr(argjson,"pair")) == 0 || (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 )
{
LP_aliceid(Q.tradeid,Q.aliceid,"error8",Q.R.requestid,Q.R.quoteid);
jaddstr(retjson,"error","couldnt create pairsock");
}
else if ( nn_connect(pairsock,pairstr) >= 0 )
{
//timeout = 1;
@ -524,6 +544,7 @@ char *LP_connectedalice(cJSON *argjson) // alice
swap->N.pair = pairsock;
autxo->S.swap = swap;
swap->utxo = autxo;
LP_aliceid(Q.tradeid,Q.aliceid,"started",Q.R.requestid,Q.R.quoteid);
printf("alice pairstr.(%s) pairsock.%d\n",pairstr,pairsock);
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_aliceloop,(void *)swap) == 0 )
{
@ -531,8 +552,18 @@ char *LP_connectedalice(cJSON *argjson) // alice
jaddstr(retjson,"result","success");
//jaddnum(retjson,"requestid",Q.R.requestid);
//jaddnum(retjson,"quoteid",Q.R.quoteid);
} else jaddstr(retjson,"error","couldnt aliceloop");
} else printf("connect error %s\n",nn_strerror(nn_errno()));
}
else
{
LP_aliceid(Q.tradeid,Q.aliceid,"error9",Q.R.requestid,Q.R.quoteid);
jaddstr(retjson,"error","couldnt aliceloop");
}
}
else
{
LP_aliceid(Q.tradeid,Q.aliceid,"error10",Q.R.requestid,Q.R.quoteid);
printf("connect error %s\n",nn_strerror(nn_errno()));
}
printf("connected result.(%s)\n",jprint(retjson,0));
if ( jobj(retjson,"error") != 0 )
LP_availableset(autxo);
@ -541,6 +572,7 @@ char *LP_connectedalice(cJSON *argjson) // alice
else
{
LP_availableset(autxo);
LP_aliceid(Q.tradeid,Q.aliceid,"error11",0,0);
printf("no privkey found coin.%s %s taddr.%u\n",Q.destcoin,Q.destaddr,coin->taddr);
return(clonestr("{\"error\",\"no privkey\"}"));
}
@ -658,6 +690,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
}
if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 )
{
LP_aliceid(Q.tradeid,Q.aliceid,"reserved",0,0);
printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0));
if ( (retstr= LP_quotereceived(argjson)) != 0 )
free(retstr);

28
iguana/exchanges/LP_tradebots.c

@ -27,7 +27,7 @@ struct LP_tradebot_trade
uint64_t aliceid;
int32_t dispdir;
uint32_t started,finished,requestid,quoteid,tradeid;
char base[32],rel[32];
char base[32],rel[32],event[32];
};
struct LP_tradebot
@ -100,11 +100,15 @@ cJSON *LP_tradebot_tradejson(struct LP_tradebot_trade *tp,int32_t dispflag)
double price,basevol; cJSON *item = cJSON_CreateObject();
if ( tp == 0 )
return(cJSON_Parse("{}"));
if ( tp->event[0] != 0 )
jaddstr(item,"status",tp->event);
if ( tp->requestid != 0 && tp->quoteid != 0 )
{
jaddnum(item,"requestid",tp->requestid);
jaddnum(item,"quoteid",tp->quoteid);
} else jaddnum(item,"tradeid",tp->tradeid);
if ( tp->aliceid != 0 )
jadd64bits(item,"aliceid",tp->aliceid);
if ( tp->basevol > SMALLVAL && tp->relvol > SMALLVAL )
{
if ( dispflag > 0 )
@ -338,6 +342,28 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot)
bot->pause = (uint32_t)time(NULL);
}
void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid,uint32_t quoteid)
{
struct LP_tradebot *bot,*tmp; int32_t i; struct LP_tradebot_trade *tp;
DL_FOREACH_SAFE(LP_tradebots,bot,tmp)
{
for (i=0; i<bot->numtrades; i++)
{
if ( (tp= bot->trades[i]) != 0 && tp->finished == 0 && tp->tradeid == tradeid )
{
tp->aliceid = aliceid;
if ( requestid != 0 && quoteid != 0 )
{
tp->requestid = requestid;
tp->quoteid = quoteid;
}
strcpy(tp->event,event);
break;
}
}
}
}
void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid)
{
struct LP_tradebot *bot,*tmp; int32_t i; struct LP_tradebot_trade *tp;

Loading…
Cancel
Save