Browse Source

Test

etomic
jl777 8 years ago
parent
commit
fb775092c2
  1. 48
      iguana/exchanges/mm.c

48
iguana/exchanges/mm.c

@ -680,29 +680,19 @@ int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double
return(n); return(n);
} }
void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double start_BASE,double start_REL,double profitmargin,double maxexposure,double ratioincr,char *exchange,char *name,char *base,char *rel) double marketmaker_updateprice(char *name,char *base,char *rel,double theoretical,double *incrp)
{ {
static uint32_t counter; static uint32_t counter;
cJSON *fiatjson; char *retstr; double bid,ask,start_DEXbase,start_DEXrel,USD_average=0.,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,usdprice=0.,CMC_average=0.,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0; cJSON *fiatjson; double USD_average=0.,usdprice=0.,CMC_average=0.,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.;
incr = maxexposure * ratioincr;
buyvol = sellvol = 0.;
start_DEXbase = dex_balance(base,baseaddr);
start_DEXrel = dex_balance(rel,reladdr);
while ( 1 )
{
if ( time(NULL) > lasttime+60 )
{
if ( (val= get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,name,base,rel,&USD_average)) != 0. ) if ( (val= get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,name,base,rel,&USD_average)) != 0. )
{ {
if ( theoretical == 0. ) if ( theoretical == 0. )
{ {
theoretical = val; theoretical = val;
incr /= theoretical; if ( *incrp > 2 )
maxexposure /= theoretical;
if ( incr > 2 )
{ {
incr = (int32_t)incr; *incrp = (int32_t)*incrp;
incr += 0.777; *incrp += 0.777;
} }
} else theoretical = (theoretical + val) * 0.5; } else theoretical = (theoretical + val) * 0.5;
if ( (counter++ % 12) == 0 ) if ( (counter++ % 12) == 0 )
@ -721,6 +711,25 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double
} }
LP_priceupdate(base,rel,theoretical,avebid,aveask,highbid,lowask,PAXPRICES); LP_priceupdate(base,rel,theoretical,avebid,aveask,highbid,lowask,PAXPRICES);
} }
return(theoretical);
}
void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double start_BASE,double start_REL,double profitmargin,double maxexposure,double ratioincr,char *exchange,char *name,char *base,char *rel)
{
char *retstr; double bid,ask,start_DEXbase,start_DEXrel,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0;
incr = maxexposure * ratioincr;
buyvol = sellvol = 0.;
start_DEXbase = dex_balance(base,baseaddr);
start_DEXrel = dex_balance(rel,reladdr);
while ( 1 )
{
if ( time(NULL) > lasttime+60 )
{
if ( (theoretical= marketmaker_updateprice(name,base,rel,theoretical,&incr)) != 0. )
{
if ( lasttime == 0 )
maxexposure /= theoretical;
}
if ( strcmp(exchange,"bittrex") == 0 ) if ( strcmp(exchange,"bittrex") == 0 )
{ {
balance_base = bittrex_balance(base,""); balance_base = bittrex_balance(base,"");
@ -809,7 +818,7 @@ void LP_main(void *ptr)
int main(int argc, const char * argv[]) int main(int argc, const char * argv[])
{ {
char *base,*rel,*name,*exchange,*apikey,*apisecret,*blocktrail,*retstr,*baseaddr,*reladdr,*passphrase; char *base,*rel,*name,*exchange,*apikey,*apisecret,*blocktrail,*retstr,*baseaddr,*reladdr,*passphrase;
double profitmargin,maxexposure,incrratio,start_rel,start_base,minask,maxbid; double profitmargin,maxexposure,incrratio,start_rel,start_base,minask,maxbid,incr,theoretical = 0.;
cJSON *retjson,*loginjson; int32_t i; cJSON *retjson,*loginjson; int32_t i;
if ( argc > 1 && (retjson= cJSON_Parse(argv[1])) != 0 ) if ( argc > 1 && (retjson= cJSON_Parse(argv[1])) != 0 )
{ {
@ -820,7 +829,12 @@ int main(int argc, const char * argv[])
printf("error launching LP_main (%s)\n",jprint(retjson,0)); printf("error launching LP_main (%s)\n",jprint(retjson,0));
exit(-1); exit(-1);
} else printf("(%s) launched.(%s)\n",argv[1],passphrase); } else printf("(%s) launched.(%s)\n",argv[1],passphrase);
getchar(); incr = 100.;
while ( 1 )
{
theoretical = marketmaker_updateprice("komodo","KMD","BTC",theoretical,&incr);
sleep(30);
}
profitmargin = jdouble(retjson,"profitmargin"); profitmargin = jdouble(retjson,"profitmargin");
minask = jdouble(retjson,"minask"); minask = jdouble(retjson,"minask");
maxbid = jdouble(retjson,"maxbid"); maxbid = jdouble(retjson,"maxbid");

Loading…
Cancel
Save