char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr) { char field[128],*str,*itemstr = 0; cJSON *obj; double lockbalance,imma; *balancep = 0.; strcpy(field,coinstr); tolowercase(field); strcat(field,"_balance"); if ( exchange->balancejson != 0 && (str= jstr(exchange->balancejson,field)) != 0 ) { *balancep = jdouble(exchange->balancejson,field); strcpy(field,coinstr), tolowercase(field), strcat(field,"_balance_lock"); lockbalance = jdouble(exchange->balancejson,field); strcpy(field,coinstr), tolowercase(field), strcat(field,"_balance_imma"); imma = jdouble(exchange->balancejson,field); obj = cJSON_CreateObject(); jaddnum(obj,"balance",*balancep); jaddnum(obj,"locked_balance",lockbalance); jaddnum(obj,"imma_balance",imma); itemstr = jprint(obj,1); } if ( itemstr == 0 ) return(clonestr("{\"error\":\"cant find coin balance\"}")); return(itemstr); }
void prices777_instaforex(uint32_t timestamps[NUM_INSTAFOREX],double bids[NUM_INSTAFOREX],double asks[NUM_INSTAFOREX]) { //{"NZDUSD":{"symbol":"NZDUSD","lasttime":1437580206,"digits":4,"change":"-0.0001","bid":"0.6590","ask":"0.6593"}, char contract[32],*jsonstr; cJSON *json,*item; int32_t i; memset(timestamps,0,sizeof(*timestamps) * NUM_INSTAFOREX); memset(bids,0,sizeof(*bids) * NUM_INSTAFOREX); memset(asks,0,sizeof(*asks) * NUM_INSTAFOREX); jsonstr = issue_curl("https://quotes.instaforex.com/get_quotes.php?q=NZDUSD,NZDCHF,NZDCAD,NZDJPY,GBPNZD,EURNZD,AUDNZD,CADJPY,CADCHF,USDCAD,EURCAD,GBPCAD,AUDCAD,USDCHF,CHFJPY,EURCHF,GBPCHF,AUDCHF,EURUSD,EURAUD,EURJPY,EURGBP,GBPUSD,GBPJPY,GBPAUD,USDJPY,AUDJPY,AUDUSD,XAUUSD&m=json"); if ( jsonstr != 0 ) { printf("(%s)\n",jsonstr); if ( (json= cJSON_Parse(jsonstr)) != 0 ) { for (i=0; i<NUM_INSTAFOREX; i++) { sprintf(contract,"%s%s",BASERELS[i][0],BASERELS[i][1]); if ( (item= jobj(json,contract)) != 0 ) { timestamps[i] = juint(item,"lasttime"); bids[i] = jdouble(item,"bid"); asks[i] = jdouble(item,"ask"); } } free_json(json); } free(jsonstr); } }
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr) { //[{"btc_available":"0.00000000","btc_reserved":"0.00000000","btc_balance":"0.00000000","cad_available":"0.00","cad_reserved":"0.00","cad_balance":"0.00","usd_available":"0.00","usd_reserved":"0.00","usd_balance":"0.00","xau_available":"0.000000","xau_reserved":"0.000000","xau_balance":"0.000000","fee":"0.5000"}] char field[128],*str,*itemstr = 0; cJSON *obj; double reserv,total; *balancep = 0.; strcpy(field,coinstr); tolowercase(field); strcat(field,"_available"); if ( exchange->balancejson != 0 && (str= jstr(exchange->balancejson,field)) != 0 ) { *balancep = jdouble(exchange->balancejson,field); strcpy(field,coinstr), tolowercase(field), strcat(field,"_reserved"); reserv = jdouble(exchange->balancejson,field); strcpy(field,coinstr), tolowercase(field), strcat(field,"_balance"); total = jdouble(exchange->balancejson,field); obj = cJSON_CreateObject(); jaddnum(obj,"balance",*balancep); jaddnum(obj,"locked_balance",reserv); jaddnum(obj,"total",total); itemstr = jprint(obj,1); } if ( itemstr == 0 ) return(clonestr("{\"error\":\"cant find coin balance\"}")); return(itemstr); }
void tradebot_liquidity_command(struct supernet_info *myinfo,char *base,bits256 hash,cJSON *vals) { struct liquidity_info li,refli; int32_t i; memset(&li,0,sizeof(li)); strcpy(li.base,base), strcpy(li.rel,"BTC"); li.profit = jdouble(vals,"profit"); li.refprice = jdouble(vals,"refprice"); for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++) { refli = myinfo->linfos[i]; if ( strcmp(li.rel,refli.base) == 0 && strcmp(li.base,refli.rel) == 0 ) { strcpy(li.base,refli.base); strcpy(li.rel,refli.rel); li.refprice = (1. / li.refprice); printf("Set rev linfo[%d] (%s/%s) %.6f %.8f\n",i,li.base,li.rel,li.profit,li.refprice); myinfo->linfos[i] = li; return; } else if ( refli.base[0] == 0 || (strcmp(li.base,refli.base) == 0 && strcmp(li.rel,refli.rel) == 0) ) { myinfo->linfos[i] = li; printf("Set linfo[%d] (%s/%s) %.6f %.8f\n",i,li.base,li.rel,li.profit,li.refprice); return; } } printf("ERROR: too many linfos %d\n",i); }
double blend_price(double *volp,double wtA,cJSON *jsonA,double wtB,cJSON *jsonB) { //A.{"ticker":{"base":"BTS","target":"CNY","price":"0.02958291","volume":"3128008.39295500","change":"0.00019513","markets":[{"market":"BTC38","price":"0.02960000","volume":3051650.682955},{"market":"Bter","price":"0.02890000","volume":76357.71}]},"timestamp":1438490881,"success":true,"error":""} // B.{"id":"bts\/cny","price":"0.02940000","price_before_24h":"0.02990000","volume_first":"3048457.6857147217","volume_second":"90629.45859575272","volume_btc":"52.74","best_market":"btc38","latest_trade":"2015-08-02 03:57:38","coin1":"BitShares","coin2":"CNY","markets":[{"market":"btc38","price":"0.02940000","volume":"3048457.6857147217","volume_btc":"52.738317962865"},{"market":"bter","price":"0.04350000","volume":"0","volume_btc":"0"}]} double priceA,priceB,priceB24,price,volA,volB; cJSON *obj; priceA = priceB = priceB24= price = volA = volB = 0.; if ( jsonA != 0 && (obj= jobj(jsonA,"ticker")) != 0 ) { priceA = jdouble(obj,"price"); volA = jdouble(obj,"volume"); } if ( jsonB != 0 ) { priceB = jdouble(jsonB,"price"); priceB24 = jdouble(jsonB,"price_before_24h"); volB = jdouble(jsonB,"volume_first"); } //printf("priceA %f volA %f, priceB %f %f volB %f\n",priceA,volA,priceB,priceB24,volB); if ( priceB > SMALLVAL && priceB24 > SMALLVAL ) priceB = (priceB * .1) + (priceB24 * .9); else if ( priceB < SMALLVAL ) priceB = priceB24; if ( priceA*volA < SMALLVAL ) price = priceB; else if ( priceB*volB < SMALLVAL ) price = priceA; else price = (wtA * priceA) + (wtB * priceB); *volp = (volA + volB); return(price); }
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr) { //[[{"type":"deposit","currency":"btc","amount":"0.0","available":"0.0"},{"type":"deposit","currency":"usd","amount":"0.0","available":"0.0"},{"type":"exchange","currency":"btc","amount":"0.01065851","available":"0.01065851"},{"type":"exchange","currency":"usd","amount":"23386.37278962","available":"0.00378962"},{"type":"trading","currency":"btc","amount":"0.0","available":"0.0"},{"type":"trading","currency":"usd","amount":"0.0","available":"0.0"}]] int32_t i,n,ind; char field[64],*str,*typestr,*itemstr = 0; cJSON *item,*obj,*array; double amounts[3],avail[3],val0,val1; *balancep = 0.; strcpy(field,coinstr), tolowercase(field); memset(amounts,0,sizeof(amounts)); memset(avail,0,sizeof(avail)); if ( exchange->balancejson != 0 && is_cJSON_Array(exchange->balancejson) != 0 && (n= cJSON_GetArraySize(exchange->balancejson)) > 0 ) { for (i=0; i<n; i++) { if ( (item= jitem(exchange->balancejson,i)) != 0 ) { if ( (str= jstr(item,"currency")) != 0 && strcmp(field,str) == 0 ) { val0 = jdouble(item,"amount"); val1 = jdouble(item,"available"); if ( (typestr= jstr(item,"type")) != 0 ) { if ( strcmp(typestr,"deposit") == 0 ) ind = 0; else if ( strcmp(typestr,"exchange") == 0 ) ind = 1; else if ( strcmp(typestr,"trading") == 0 ) ind = 2; else ind = -1; if ( ind >= 0 ) { amounts[ind] = val0; avail[ind] = val1; } } } } } if ( (obj= cJSON_CreateObject()) != 0 ) { touppercase(field); *balancep = avail[0] + avail[1] + avail[2]; jaddstr(obj,"base",field); jaddnum(obj,"balance",*balancep); jaddnum(obj,"total",amounts[0]+amounts[1]+amounts[2]); array = cJSON_CreateArray(), jaddinum(array,avail[0]), jaddinum(array,amounts[0]), jadd(obj,"deposit",array); array = cJSON_CreateArray(), jaddinum(array,avail[1]), jaddinum(array,amounts[1]), jadd(obj,"exchange",array); array = cJSON_CreateArray(), jaddinum(array,avail[2]), jaddinum(array,amounts[2]), jadd(obj,"trading",array); itemstr = jprint(obj,1); } } if ( itemstr == 0 ) return(clonestr("{\"error\":\"cant find coin balance\"}")); return(itemstr); }
static jdouble nativeGetDouble(JNIEnv* env, jclass clazz, jlong windowPtr, jint row, jint column) { CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); LOG_WINDOW("Getting double for %d,%d from %p", row, column, window); CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); if (!fieldSlot) { throwExceptionWithRowCol(env, row, column); return 0.0; } int32_t type = window->getFieldSlotType(fieldSlot); if (type == CursorWindow::FIELD_TYPE_FLOAT) { return window->getFieldSlotValueDouble(fieldSlot); } else if (type == CursorWindow::FIELD_TYPE_STRING) { size_t sizeIncludingNull; const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); return sizeIncludingNull > 1 ? strtod(value, NULL) : 0.0; } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { return jdouble(window->getFieldSlotValueLong(fieldSlot)); } else if (type == CursorWindow::FIELD_TYPE_NULL) { return 0.0; } else if (type == CursorWindow::FIELD_TYPE_BLOB) { throw_sqlite3_exception(env, "Unable to convert BLOB to double"); return 0.0; } else { throwUnknownTypeException(env, type); return 0.0; } }
char *WITHDRAW(struct exchange_info *exchange,cJSON *argjson) { char payload[1024],*method,*base,*destaddr,*type,*retstr = 0; cJSON *json; double amount; amount = jdouble(argjson,"amount"); if ( (destaddr= jstr(argjson,"destaddr")) == 0 || amount < SMALLVAL ) return(clonestr("{\"error\":\"no destaddr specified or amount too small\"}")); if ( (base= jstr(argjson,"base")) == 0 ) base = "bitcoin"; else if ( strcmp(base,"BTC") == 0 ) base = "bitcoin"; else if ( strcmp(base,"LTC") == 0 ) base = "litecoin"; else if ( strcmp(base,"DRK") == 0 ) base = "darkcoin"; else return(clonestr("{\"error\":\"invalid base specified\"}")); if ( (type= jstr(argjson,"extra")) == 0 ) type = "exchange"; else if ( strcmp(type,"exchange") != 0 && strcmp(type,"trading") != 0 && strcmp(type,"deposit") != 0 ) return(clonestr("{\"error\":\"invalid wallet type specified\"}")); method = "withdraw"; sprintf(payload,"{\"request\":\"/v1/%s\",\"nonce\":\"%llu\",\"amount\":\"%.6f\",\"withdraw_type\":\"%s\",\"walletselected\":\"%s\",\"address\":\"%s\"}",method,(long long)exchange_nonce(exchange),amount,base,type,destaddr); if ( (json= SIGNPOST(&retstr,exchange,payload,method)) != 0 ) { free_json(json); } return(retstr); // return standardized withdraw }
void marketmaker_pendingupdate(char *exchange,char *base,char *rel) { char *retstr; cJSON *retjson,*obj; int32_t i; struct mmpending_order *ptr; for (i=0; i<Num_Pending; i++) { ptr = &Pending_orders[i]; if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 ) continue; if ( ptr->completed == 0 && (retstr= DEX_orderstatus(exchange,ptr->orderid)) != 0 ) { //printf("%s status.(%s)\n",ptr->orderid,retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { obj = jobj(retjson,"result"); if ( is_cJSON_Array(obj) != 0 ) obj = jitem(retjson,0); if ( jdouble(obj,"QuantityRemaining") == 0. || is_cJSON_True(jobj(obj,"IsOpen")) == 0 ) { //{"Uuid":null,"OrderUuid":"e7b0789c-0c4e-413b-a768-3d5734d9cbe5","Exchange":"BTC-KMD","OrderType":"LIMIT_SELL","Quantity":877.77700000,"QuantityRemaining":462.50512234,"Limit":0.00011770,"CommissionPaid":0.00012219,"Price":0.04887750,"PricePerUnit":0.00011769,"Opened":"2017-02-20T13:16:22.29","Closed":null,"CancelInitiated":false,"ImmediateOrCancel":false,"IsConditional":false,"Condition":"NONE","ConditionTarget":null} printf("uuid.(%s) finished.(%s)\n",ptr->orderid,jprint(retjson,0)); ptr->completed = (uint32_t)time(NULL); ptr->pending = 0; } free_json(retjson); } free(retstr); } } }
uint64_t bitcoin_parseunspent(struct iguana_info *coin,struct bitcoin_unspent *unspent,double minconfirms,char *account,cJSON *item) { char *hexstr,coinaddr[64]; memset(unspent,0,sizeof(*unspent)); if ( jstr(item,"address") != 0 ) { safecopy(coinaddr,jstr(item,"address"),sizeof(coinaddr)); bitcoin_addr2rmd160(&unspent->addrtype,unspent->rmd160,coinaddr); /*sprintf(args,"[\"%s\"]",coinaddr); wifstr = bitcoind_RPC(0,coin->symbol,coin->chain->serverport,coin->chain->userpass,"dumpprivkey",args); if ( wifstr != 0 ) { bitcoin_wif2priv(&addrtype,&unspent->privkeys[0],wifstr); //printf("wifstr.(%s) -> %s\n",wifstr,bits256_str(str,unspent->privkeys[0])); free(wifstr); } else fprintf(stderr,"error (%s) cant find privkey\n",coinaddr);*/ } if ( (account == 0 || jstr(item,"account") == 0 || strcmp(account,jstr(item,"account")) == 0) && (minconfirms <= 0 || juint(item,"confirmations") >= minconfirms-SMALLVAL) ) { if ( (hexstr= jstr(item,"scriptPubKey")) != 0 ) { unspent->spendlen = (int32_t)strlen(hexstr) >> 1; if ( unspent->spendlen < sizeof(unspent->spendscript) ) decode_hex(unspent->spendscript,unspent->spendlen,hexstr); } unspent->txid = jbits256(item,"txid"); unspent->value = SATOSHIDEN * jdouble(item,"amount"); unspent->vout = jint(item,"vout"); //char str[65]; printf("(%s) -> %s %.8f scriptlen.%d\n",jprint(item,0),bits256_str(str,unspent->txid),dstr(unspent->value),unspent->scriptlen); } else printf("skip.(%s) minconfirms.%f\n",jprint(item,0),minconfirms);
/* * Class: de_rwth_0005faachen_techinfo_ltilib_Matrix * Method: _maximum * Signature: (J[I)D */ JNIEXPORT jdouble JNICALL Java_de_rwth_1aachen_techinfo_ltilib_Matrix__1maximum__J_3I (JNIEnv *env, jobject m, jlong nat, jintArray indx) { // insert your code here lti::dmatrix* ltim=jlong2matrix(nat); lti::point p=ltim->getIndexOfMaximum(); jint tmp[2]; tmp[0]=p.x; tmp[1]=p.y; env->SetIntArrayRegion(indx,0,2,tmp); return jdouble(ltim->at(p)); }
void marketmaker_pendinginit(char *exchange,char *base,char *rel) { char *retstr,*orderid; cJSON *retjson,*array,*item; int32_t i,j,n,dir; struct mmpending_order *ptr; if ( (retstr= DEX_openorders(exchange)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { //printf("%s\n",jprint(retjson,0)); if ( is_cJSON_True(jobj(retjson,"success")) != 0 && (array= jarray(&n,retjson,"result")) != 0 ) { for (i=0; i<n; i++) { item = jitem(array,i); //printf("(%s)\n",jprint(item,0)); //{"success":true,"message":"","result":[{"Uuid":null,"OrderUuid":"81ad3e37-65d4-4fee-9c29-03b050f5192b","Exchange":"BTC-KMD","OrderType":"LIMIT_BUY","Quantity":885.19934578,"QuantityRemaining":885.19934578,"Limit":0.00011184,"CommissionPaid":0,"Price":0,"PricePerUnit":null,"Opened":"2017-02-19T19:14:02.94","Closed":null,"CancelInitiated":false,"ImmediateOrCancel":false,"IsConditional":false,"Condition":"NONE","ConditionTarget":null}],"tag":"10056789044100011414"} if ( (orderid= jstr(item,"OrderUuid")) != 0 && is_cJSON_Null(jobj(item,"Closed")) != 0 && is_cJSON_False(jobj(item,"CancelInitiated")) != 0 ) { for (j=0; j<Num_Pending; j++) { ptr = &Pending_orders[j]; if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 ) continue; if ( strcmp(ptr->orderid,orderid) == 0 ) { ptr->pending = (uint32_t)time(NULL); ptr->completed = 0; printf("%s pending\n",orderid); break; } } if ( j == Num_Pending ) { if ( jstr(item,"OrderType") != 0 ) { if ( strcmp(jstr(item,"OrderType"),"LIMIT_BUY") == 0 ) dir = 1; else if ( strcmp(jstr(item,"OrderType"),"LIMIT_SELL") == 0 ) dir = -1; else dir = 0; if ( dir != 0 ) marketmaker_queue(exchange,base,rel,dir,jdouble(item,"Limit"),jdouble(item,"QuantityRemaining"),item); else printf("no dir (%s) (%s)\n",jprint(item,0),jstr(item,"OrderType")); } } } } } free_json(retjson); } free(retstr); } }
char *WITHDRAW(void **cHandlep,struct exchange_info *exchange,cJSON *argjson) { char buf[1024],*base,*destaddr; double amount; if ( (base= jstr(argjson,"base")) == 0 || strcmp(base,"BTC") != 0 ) return(clonestr("{\"error\":\"base not specified or base != BTC\"}")); if ( (destaddr= jstr(argjson,"destaddr")) == 0 ) return(clonestr("{\"error\":\"destaddr not specified\"}")); if ( (amount= jdouble(argjson,"amount")) < SMALLVAL ) return(clonestr("{\"error\":\"amount not specified\"}")); sprintf(buf,"\"amount\":%.4f,\"address\":\"%s\",",amount,destaddr); printf("submit.(%s)\n",buf); return(jprint(SIGNPOST(cHandlep,1,0,exchange,"","bitcoin_withdrawal"),1)); }
char *WITHDRAW(struct exchange_info *exchange,cJSON *argjson) { char payload[1024],*base,*destaddr,*method; double amount; if ( (base= jstr(argjson,"base")) == 0 || strcmp(base,"BTC") != 0 ) return(clonestr("{\"error\":\"base not specified or base != BTC\"}")); if ( (destaddr= jstr(argjson,"destaddr")) == 0 ) return(clonestr("{\"error\":\"destaddr not specified\"}")); if ( (amount= jdouble(argjson,"amount")) < SMALLVAL ) return(clonestr("{\"error\":\"amount not specified\"}")); method = "withdraw_coin"; sprintf(payload,"&coin_type=1&withdraw_address=%s&withdraw_amount=%.4f",destaddr,amount); return(jprint(huobi_issue_auth(exchange,method,payload),1)); }
int main(int argc, const char * argv[]) { char *base,*rel,*name,*exchange,*apikey,*apisecret,*blocktrail; double profitmargin,maxexposure,incrratio,start_rel,start_base,minask,maxbid; cJSON *retjson,*addrjson; char *retstr,*baseaddr,*reladdr,*passphrase; if ( argc > 1 && (retjson= cJSON_Parse(argv[1])) != 0 ) { minask = jdouble(retjson,"minask"); maxbid = jdouble(retjson,"maxbid"); profitmargin = jdouble(retjson,"profitmargin"); maxexposure = jdouble(retjson,"maxexposure"); incrratio = jdouble(retjson,"lotratio"); start_base = jdouble(retjson,"start_base"); start_rel = jdouble(retjson,"start_rel"); passphrase = jstr(retjson,"passphrase"); apikey = jstr(retjson,"apikey"); apisecret = jstr(retjson,"apisecret"); base = jstr(retjson,"base"); name = jstr(retjson,"name"); rel = jstr(retjson,"rel"); blocktrail = jstr(retjson,"blocktrail"); exchange = jstr(retjson,"exchange"); if ( profitmargin < 0. || maxexposure <= 0. || incrratio <= 0. || apikey == 0 || apisecret == 0 || base == 0 || name == 0 || rel == 0 || exchange == 0 || blocktrail == 0 ) { printf("illegal parameter (%s)\n",jprint(retjson,0)); exit(-1); } if ( (retstr= iguana_walletpassphrase(passphrase,999999)) != 0 ) { printf("%s\n",DEX_apikeypair(exchange,apikey,apisecret)); printf("%s %s\n",base,DEX_balance(exchange,base,"")); printf("%s %s\n",rel,DEX_balance(exchange,rel,"")); marketmaker_pendinginit(exchange,base,rel); if ( (addrjson= cJSON_Parse(retstr)) != 0 ) { baseaddr = jstr(addrjson,base); reladdr = jstr(addrjson,rel); if ( baseaddr != 0 && reladdr != 0 ) { printf("%s\n",DEX_amlp(blocktrail)); printf("%s.%s %s\n",base,baseaddr,DEX_balance("DEX",base,baseaddr)); printf("%s.%s %s\n",rel,reladdr,DEX_balance("DEX",rel,reladdr)); // initialize state using DEX_pendingorders, etc. marketmaker(minask,maxbid,baseaddr,reladdr,start_base,start_rel,profitmargin,maxexposure,incrratio,exchange,name,base,rel); } free_json(addrjson); } else printf("ERROR parsing.(%s)\n",retstr); free(retstr); } free_json(retjson); } return 0; }
double dex_balance(char *base,char *coinaddr) { char *retstr; cJSON *retjson; double balance = 0.; if ( (retstr= DEX_balance("DEX",base,coinaddr)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { balance = jdouble(retjson,"balance"); free_json(retjson); } free(retstr); } return(balance); }
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr) { char *itemstr = 0; cJSON *item,*obj; double onorders,btcvalue; *balancep = 0.; if ( exchange->balancejson != 0 && (item= jobj(exchange->balancejson,coinstr)) != 0 ) { itemstr = jprint(item,0); *balancep = jdouble(item,"available"); onorders = jdouble(item,"onOrders"); btcvalue = jdouble(item,"btcValue"); if ( (obj= cJSON_Parse(itemstr)) != 0 ) { free(itemstr); jaddstr(obj,"base",coinstr); jaddnum(obj,"balance",*balancep); jaddnum(obj,"onOrders",onorders); jaddnum(obj,"btcvalue",btcvalue); itemstr = jprint(obj,1); } } if ( itemstr == 0 ) return(clonestr("{\"error\":\"cant find coin balance\"}")); return(itemstr); }
char *WITHDRAW(void **cHandlep,struct exchange_info *exchange,cJSON *argjson) { char payload[1024],*base,*destaddr,*method,*tradepassword; double amount; if ( (base= jstr(argjson,"base")) == 0 || strcmp(base,"BTC") != 0 ) return(clonestr("{\"error\":\"base not specified or base != BTC\"}")); if ( (destaddr= jstr(argjson,"destaddr")) == 0 ) return(clonestr("{\"error\":\"destaddr not specified\"}")); if ( (amount= jdouble(argjson,"amount")) < SMALLVAL ) return(clonestr("{\"error\":\"amount not specified\"}")); if ( (tradepassword= jstr(argjson,"tradepassword")) == 0 ) return(clonestr("{\"error\":\"tradepassword not specified\"}")); method = "withdraw_coin"; sprintf(payload,"&symbol=btc_usd&chargefee=0.0001&withdraw_address=%s&withdraw_amount=%.4f&trade_pwd=%s",destaddr,amount,tradepassword); return(jprint(okcoin_issue_auth(cHandlep,exchange,method,payload),1)); }
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr) { //okcoin.({"info":{"funds":{"asset":{"net":"0","total":"0"},"free":{"btc":"0","ltc":"0","usd":"0"},"freezed":{"btc":"0","ltc":"0","usd":"0"}}},"result":true}) char field[128],*itemstr = 0; cJSON *obj,*item,*avail,*locked; double lockval = 0; *balancep = 0.; strcpy(field,coinstr); tolowercase(field); if ( exchange->balancejson != 0 && (obj= jobj(exchange->balancejson,"info")) != 0 && (item= jobj(obj,"funds")) != 0 ) { if ( (avail= jobj(item,"free")) != 0 ) *balancep = jdouble(avail,field); if ( (locked= jobj(item,"freezed")) != 0 ) lockval = jdouble(locked,field); obj = cJSON_CreateObject(); touppercase(field); jaddstr(obj,"base",field); jaddnum(obj,"balance",*balancep); jaddnum(obj,"locked",lockval); itemstr = jprint(obj,1); } if ( itemstr == 0 ) return(clonestr("{\"error\":\"cant find coin balance\"}")); return(itemstr); }
char *instantdex_request(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen) { char *base,*rel,*request; double volume,aveprice,totalvol; int32_t num,depth; struct exchange_quote sortbuf[1000]; if ( argjson != 0 ) { num = 0; depth = 30; request = jstr(argjson,"request"); base = jstr(argjson,"base"); rel = jstr(argjson,"rel"); volume = jdouble(argjson,"volume"); aveprice = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&totalvol,base,rel,volume,argjson); return(clonestr("{\"result\":\"request calculated aveprice\"}")); return(clonestr("{\"error\":\"request missing parameter\"}")); } else return(clonestr("{\"error\":\"request needs argjson\"}")); }
static jvalue numToJvalue(const T &num) { jvalue value; switch (sig) //a good compiler should simplify out the switch { case 'Z': value.z = jboolean(num); return value; case 'C': value.c = jchar(num); return value; case 'B': value.b = jbyte(num); return value; case 'S': value.s = jshort(num); return value; case 'I': value.i = jint(num); return value; case 'J': value.j = jlong(num); return value; case 'F': value.f = jfloat(num); return value; case 'D': value.d = jdouble(num); return value; } poco_bugcheck_msg(std::string(1, sig).c_str()); throw; }
uint32_t marketmaker_fiatupdate(cJSON *fiatjson) { int32_t i,n,baseid; cJSON *item,*array; double price; char *name; uint64_t mask = 0; fiatjson = jobj(fiatjson,"list"); if ( fiatjson != 0 && (array= jarray(&n,fiatjson,"resources")) > 0 ) { for (i=0; i<n; i++) { /* "resource" : { "classname" : "Quote", "fields" : { "name" : "USD/BRX", "price" : "3.063200", "symbol" : "BRX=X", "ts" : "1487866204", "type" : "currency", "utctime" : "2017-02-23T16:10:04+0000", "volume" : "0" } */ item = jitem(array,i); if ( (item= jobj(item,"resource")) != 0 ) item = jobj(item,"fields"); if ( item != 0 ) { price = jdouble(item,"price"); if ( price > SMALLVAL && (name= jstr(item,"name")) != 0 && strncmp(name,"USD/",4) == 0 ) { if ( (baseid= komodo_baseid(name+4)) >= 0 && baseid < 32 ) { if ( ((1LL << baseid) & mask) == 0 ) { _marketmaker_fiatupdate(baseid,price); mask |= (1LL << baseid); } else if ( fabs(price*PAXPRICES[0] - PAXPRICES[baseid]) > SMALLVAL ) printf("DUPLICATE PRICE? %s %.8f vs %.8f\n",name+4,price*PAXPRICES[0],PAXPRICES[baseid]); } } } } } printf("pax mask.%x\n",(uint32_t)mask); return((uint32_t)mask); }
char *bet(char *retbuf,long maxlen,struct txnet777 *TXNET,cJSON *json,char *jsonstr,char *tokenstr,char *forwarder,char *sender,int32_t valid) { struct txnet777_tx tx; int64_t balance,senderbits,betamount,destbits; if ( (betamount= jdouble(json,"bet") * SATOSHIDEN) > 0 && (destbits= calc_rpsbits(jstr(json,"move"))) != 0 ) { memset(&tx,0,sizeof(tx)); tx.in.senderbits = senderbits = conv_acctstr(sender); kv777_iterate(RPS.TXNET.transactions,&tx,0,balanceiterator); if ( (balance= tx.out[0].destamount) >= betamount ) { memset(&tx,0,sizeof(tx)); tx.out[0].destamount = betamount, tx.out[0].destbits = destbits; txnet777_signtx(&RPS.TXNET,0,&tx,sizeof(tx),RPS.name,senderbits,(uint32_t)time(NULL)); txnet777_broadcast(&RPS.TXNET,&tx); } } else sprintf(retbuf,"{\"error\":\"illegal bet\",\"betamount\":\"%llu\"}",(long long)betamount); return(0); }
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr) { char field[128],*itemstr = 0; cJSON *obj,*item; *balancep = 0.; strcpy(field,coinstr); tolowercase(field); if ( exchange->balancejson != 0 && (obj= jobj(exchange->balancejson,"return")) != 0 && (item= jobj(obj,"funds")) != 0 ) { *balancep = jdouble(item,field); obj = cJSON_CreateObject(); touppercase(field); jaddstr(obj,"base",field); jaddnum(obj,"balance",*balancep); itemstr = jprint(obj,1); } if ( itemstr == 0 ) return(clonestr("{\"error\":\"cant find coin balance\"}")); return(itemstr); }
char *WITHDRAW(void **cHandlep,struct exchange_info *exchange,cJSON *argjson) { char payload[1024],*destaddr,*paymentid,*base,*retstr = 0; cJSON *json; double amount; if ( (base= jstr(argjson,"base")) == 0 ) return(clonestr("{\"error\":\"base not specified\"}")); if ( (destaddr= jstr(argjson,"destaddr")) == 0 ) return(clonestr("{\"error\":\"destaddr not specified\"}")); if ( (amount= jdouble(argjson,"amount")) < SMALLVAL ) return(clonestr("{\"error\":\"amount not specified\"}")); paymentid = jstr(argjson,"paymentid"); sprintf(payload,"command=withdraw&nonce=%llu¤cy=%s&amount=%.6f&address=%s",(long long)exchange_nonce(exchange),base,amount,destaddr); if ( paymentid != 0 ) sprintf(payload + strlen(payload),"&paymentId=%s",paymentid); if ( (json= SIGNPOST(cHandlep,1,&retstr,exchange,EXCHANGE_AUTHURL,payload)) != 0 ) { free_json(json); } return(retstr); // return standardized withdraw }
void PAX_update(struct peggy_info *PEGS,double *btcusdp,double *btcdbtcp) { int32_t i,n,seconds,datenum; uint32_t timestamp; char url[1024],*dstr,*str; double btcddaily=0.,btcusd=0.,ask,high,low,bid,close,vol,quotevol,open,price = 0.; //cJSON *btcdtrades,*btcdtrades2,*,*bitcoincharts,; cJSON *quandl,*btcdhist,*array,*item,*bitcoinave,*blockchaininfo,*coindesk=0; //btcdtrades = url_json("https://poloniex.com/public?command=returnTradeHistory¤cyPair=BTC_BTCD"); //btcdtrades2 = url_json("https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-BTCD&count=50"); bitcoinave = url_json("https://api.bitcoinaverage.com/ticker/USD/"); //bitcoincharts = url_json("http://api.bitcoincharts.com/v1/weighted_prices.json"); blockchaininfo = url_json("https://blockchain.info/ticker"); coindesk = url_json("http://api.coindesk.com/v1/bpi/historical/close.json"); sprintf(url,"https://poloniex.com/public?command=returnChartData¤cyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-2*3600*24)); quandl = url_json("https://www.quandl.com/api/v1/datasets/BAVERAGE/USD.json?rows=1"); if ( quandl != 0 && (str= jstr(quandl,"updated_at")) != 0 && (datenum= conv_date(&seconds,str)) > 0 && (array= jarray(&n,quandl,"data")) != 0 ) { //printf("datenum.%d data.%d %d\n",datenum,n,cJSON_GetArraySize(array)); for (i=0; i<1; i++) { // ["Date","24h Average","Ask","Bid","Last","Total Volume"] // ["2015-07-25",289.27,288.84,288.68,288.87,44978.61] item = jitem(array,i); if ( (dstr= jstr(jitem(item,0),0)) != 0 && (datenum= conv_date(&seconds,dstr)) > 0 ) { btcusd = price = jdouble(jitem(item,1),0), ask = jdouble(jitem(item,2),0), bid = jdouble(jitem(item,3),0); close = jdouble(jitem(item,4),0), vol = jdouble(jitem(item,5),0); //fprintf(stderr,"%d.[%d %f %f %f %f %f].%d ",i,datenum,price,ask,bid,close,vol,n); } } } { double avebid,aveask,bidvol,askvol; struct exchange_quote sortbuf[512]; struct supernet_info *myinfo = SuperNET_MYINFO(0); cJSON *argjson = cJSON_Parse("{}"); aveask = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&askvol,"BTCD","BTC",1,argjson); avebid = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&bidvol,"BTCD","BTC",-1,argjson); if ( avebid > SMALLVAL && aveask > SMALLVAL ) { price = (avebid*bidvol + aveask*askvol) / (bidvol + askvol); *btcdbtcp = price; printf("set BTCD price %f\n",price); PEGS->btcdbtc = price; } else { btcdhist = url_json(url); //{"date":1406160000,"high":0.01,"low":0.00125,"open":0.01,"close":0.001375,"volume":1.50179994,"quoteVolume":903.58818412,"weightedAverage":0.00166204}, if ( btcdhist != 0 && (array= jarray(&n,btcdhist,0)) != 0 ) { //printf("GOT.(%s)\n",cJSON_Print(array)); for (i=0; i<1; i++) { item = jitem(array,i); timestamp = juint(item,"date"), high = jdouble(item,"high"), low = jdouble(item,"low"), open = jdouble(item,"open"); close = jdouble(item,"close"), vol = jdouble(item,"volume"), quotevol = jdouble(item,"quoteVolume"), price = jdouble(item,"weightedAverage"); //printf("[%u %f %f %f %f %f %f %f]",timestamp,high,low,open,close,vol,quotevol,price); //printf("[%u %d %f]",timestamp,OS_conv_unixtime(&seconds,timestamp),price); btcddaily = price; if ( btcddaily != 0 ) PEGS->btcdbtc = *btcdbtcp = btcddaily; } //printf("poloniex.%d\n",n); } if ( btcdhist != 0 ) free_json(btcdhist); } } if ( bitcoinave != 0 ) { if ( (price= jdouble(bitcoinave,"24h_avg")) > SMALLVAL ) { //printf("bitcoinave %f %f\n",btcusd,price); dxblend(&btcusd,price,0.5); } free_json(bitcoinave); } if ( quandl != 0 ) free_json(quandl); if ( coindesk != 0 ) free_json(coindesk); if ( blockchaininfo != 0 ) { if ( (item= jobj(blockchaininfo,"USD")) != 0 && item != 0 && (price= jdouble(item,"15m")) > SMALLVAL ) { //printf("blockchaininfo %f %f\n",btcusd,price); dxblend(&btcusd,price,0.5); } free_json(blockchaininfo); } if ( btcusd != 0 ) PEGS->btcusd = *btcusdp = btcusd; }
static void testProxy0ReturnDouble(CuTest* tc) { handler = testProxy0ReturnDouble_handler; jdouble (*f)(jdouble) = (jdouble (*)(jdouble)) _proxy0; jdouble result = f(-3.14); CuAssertTrue(tc, result == -3.14 * -3.14); }
inline jdouble NumberMarshaller::unmarshall(JNIEnv * const env, const double & in) const { return jdouble(in); }
/* * Class: de_rwth_0005faachen_techinfo_ltilib_Matrix * Method: _trace * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_de_rwth_1aachen_techinfo_ltilib_Matrix__1trace (JNIEnv *env, jobject m, jlong nat) { // insert your code here return jdouble(jlong2matrix(nat)->trace()); }
void PAX_btcprices(struct peggy_info *PEGS,int32_t enddatenum,int32_t numdates) { int32_t i,n,year,month,day,seconds,datenum; char url[1024],date[64],*dstr,*str; uint32_t timestamp,utc32[MAX_SPLINES]; struct tai t; cJSON *coindesk,*quandl,*btcdhist,*bpi,*array,*item; double btcddaily[MAX_SPLINES],cdaily[MAX_SPLINES],qdaily[MAX_SPLINES],ask,high,low,bid,close,vol,quotevol,open,price = 0.; coindesk = url_json("http://api.coindesk.com/v1/bpi/historical/close.json"); sprintf(url,"https://poloniex.com/public?command=returnChartData¤cyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-numdates*3600*24)); if ( (bpi= jobj(coindesk,"bpi")) != 0 ) { datenum = enddatenum; memset(utc32,0,sizeof(utc32)); memset(cdaily,0,sizeof(cdaily)); if ( datenum == 0 ) { datenum = OS_conv_unixtime(&t,&seconds,(uint32_t)time(NULL)); printf("got datenum.%d %d %d %d\n",datenum,seconds/3600,(seconds/60)%24,seconds%60); } for (i=0; i<numdates; i++) { expand_datenum(date,datenum); if ( (price= jdouble(bpi,date)) != 0 ) { utc32[numdates - 1 - i] = OS_conv_datenum(datenum,12,0,0); cdaily[numdates - 1 - i] = price * .001; //printf("(%s %u %f) ",date,utc32[numdates - 1 - i],price); } datenum = ecb_decrdate(&year,&month,&day,date,datenum); } PAX_genspline(&PEGS->splines[MAX_CURRENCIES],MAX_CURRENCIES,"coindesk",utc32,cdaily,numdates,cdaily); } else printf("no bpi\n"); quandl = url_json("https://www.quandl.com/api/v1/datasets/BAVERAGE/USD.json?rows=64"); if ( (str= jstr(quandl,"updated_at")) != 0 && (datenum= conv_date(&seconds,str)) > 0 && (array= jarray(&n,quandl,"data")) != 0 ) { printf("datenum.%d data.%d %d\n",datenum,n,cJSON_GetArraySize(array)); memset(utc32,0,sizeof(utc32)), memset(qdaily,0,sizeof(qdaily)); for (i=0; i<n&&i<MAX_SPLINES; i++) { // ["Date","24h Average","Ask","Bid","Last","Total Volume"] // ["2015-07-25",289.27,288.84,288.68,288.87,44978.61] item = jitem(array,i); if ( Debuglevel > 2 ) printf("(%s) ",cJSON_Print(item)); if ( (dstr= jstr(jitem(item,0),0)) != 0 && (datenum= conv_date(&seconds,dstr)) > 0 ) { price = jdouble(jitem(item,1),0), ask = jdouble(jitem(item,2),0), bid = jdouble(jitem(item,3),0); close = jdouble(jitem(item,4),0), vol = jdouble(jitem(item,5),0); if ( Debuglevel > 2 ) fprintf(stderr,"%d.[%d %f %f %f %f %f].%d ",i,datenum,price,ask,bid,close,vol,n); utc32[numdates - 1 - i] = OS_conv_datenum(datenum,12,0,0), qdaily[numdates - 1 - i] = price * .001; } } PAX_genspline(&PEGS->splines[MAX_CURRENCIES+1],MAX_CURRENCIES+1,"quandl",utc32,qdaily,n<MAX_SPLINES?n:MAX_SPLINES,qdaily); } btcdhist = url_json(url); //{"date":1406160000,"high":0.01,"low":0.00125,"open":0.01,"close":0.001375,"volume":1.50179994,"quoteVolume":903.58818412,"weightedAverage":0.00166204}, if ( (array= jarray(&n,btcdhist,0)) != 0 ) { memset(utc32,0,sizeof(utc32)), memset(btcddaily,0,sizeof(btcddaily)); //printf("GOT.(%s)\n",cJSON_Print(array)); for (i=0; i<n; i++) { item = jitem(array,i); timestamp = juint(item,"date"), high = jdouble(item,"high"), low = jdouble(item,"low"), open = jdouble(item,"open"); close = jdouble(item,"close"), vol = jdouble(item,"volume"), quotevol = jdouble(item,"quoteVolume"), price = jdouble(item,"weightedAverage"); //printf("[%u %f %f %f %f %f %f %f]",timestamp,high,low,open,close,vol,quotevol,price); if ( Debuglevel > 2 ) printf("[%u %d %f]",timestamp,OS_conv_unixtime(&t,&seconds,timestamp),price); utc32[i] = timestamp - 12*3600, btcddaily[i] = price * 100.; } if ( Debuglevel > 2 ) printf("poloniex.%d\n",n); PAX_genspline(&PEGS->splines[MAX_CURRENCIES+2],MAX_CURRENCIES+2,"btcdhist",utc32,btcddaily,n<MAX_SPLINES?n:MAX_SPLINES,btcddaily); } // https://poloniex.com/public?command=returnChartData¤cyPair=BTC_BTCD&start=1405699200&end=9999999999&period=86400 }