cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *method,char *payload) { /*signature is a HMAC-SHA256 encoded message containing: nonce, customer ID (can be found here) and API key. The HMAC-SHA256 code must be generated using a secret key that was generated with your API key. This code must be converted to it's hexadecimal representation (64 uppercase characters).Example (Python): message = nonce + customer_id + api_key signature = hmac.new(API_SECRET, msg=message, digestmod=hashlib.sha256).hexdigest().upper() key - API key signature - signature nonce - nonce */ char dest[1025],url[1024],req[1024],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*sig,*data = 0; cJSON *json; uint64_t nonce; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; nonce = exchange_nonce(exchange); sprintf(req,"%llu%s%s",(long long)nonce,exchange->userid,exchange->apikey); json = 0; if ( (sig= hmac_sha256_str(dest,exchange->apisecret,(int32_t)strlen(exchange->apisecret),req)) != 0 ) { //touppercase(sig); //printf("req.(%s) sig.(%s)\n",req,sig); //sprintf(req,"{\"key\":\"%s\",\"signature\":\"%s\",\"nonce\":%llu%s}",exchange->apikey,sig,(long long)nonce,payload); sprintf(req,"key=%s&signature=%s&nonce=%llu%s",exchange->apikey,sig,(long long)nonce,payload); //printf("submit.(%s)\n",req); sprintf(url,"%s/%s/",EXCHANGE_AUTHURL,method); if ( dotrade == 0 ) data = exchange_would_submit(req,hdr1,hdr2,hdr3,hdr4); else if ( (data= curl_post(cHandlep,url,0,req,req,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); } if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
///////////////////////////////////char *SSIAppSignIn( char *phone_num, char *password ) 函数负责向飞信网站进行身份验证,通过https发送身份验证数据///////////////////////// char *SSIAppSignIn( char *phone_num, char *password ) //登陆的时候 { static char *str; str = curl_post(phone_num, password); return trim(str); }
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path) { char url[1024],req[1024],md5secret[128],tmp[1024],dest[1025],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*sig,*data = 0; cJSON *json; uint64_t nonce; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; json = 0; nonce = exchange_nonce(exchange) * 1000 + ((uint64_t)milliseconds() % 1000); sprintf(tmp,"%llu%s%s",(long long)nonce,exchange->userid,exchange->apikey); calc_md5(md5secret,exchange->apisecret,(int32_t)strlen(exchange->apisecret)); if ( (sig= hmac_sha256_str(dest,md5secret,(int32_t)strlen(md5secret),tmp)) != 0 ) { sprintf(req,"{\"key\":\"%s\",%s\"nonce\":%llu,\"signature\":\"%s\"}",exchange->apikey,payload,(long long)nonce,sig); sprintf(hdr1,"Content-Type:application/json"); sprintf(hdr2,"charset=utf-8"); sprintf(hdr3,"Content-Length:%ld",(long)strlen(req)); sprintf(url,"https://api.quadrigacx.com/v2/%s",path); if ( dotrade == 0 ) data = exchange_would_submit(req,hdr1,hdr2,hdr3,hdr4); else if ( (data= curl_post(cHandlep,url,0,req,hdr1,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); } if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
void foo(char *serverport,char *userpass) { static CURL *cHandle; char *retstr; //sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); retstr = curl_post(&cHandle,serverport,userpass,"{\"method\":\"listreceivedbyaddress\",\"params\":[1 true]}",0,0,0,0); printf("retstr.%p (%s)\n",retstr,retstr!=0?retstr:""); }
void test_curl_post_() { CURLres *res; unsigned int len; char* hs[] = { "abc:jjj", "jfdd:ss" }; // printf("<--------------test_curl_post_---------------->\n"); // printf("test_curl_post_\n"); res = curl_post("http://www.baidu.com", 0, 0, 0); if (res->ccode) { printf("ccode:%d\n", res->ccode); } else { printf("------------------------------>\n"); len = strlen(res->rdata); printf("abc:%d,%d\n", len, res->rcode); } curl_free_res(&res); // printf("test_curl_post_2\n"); res = curl_post("http://www.baidu.com", "abc=1&jkk=2", 0, 0); printf("test_curl_post_2-1\n"); if (res->ccode) { printf("ccode:%d\n", res->ccode); } else { printf("------------------------------>\n"); len = strlen(res->rdata); printf("abc:%d,%d\n", len, res->rcode); } curl_free_res(&res); // printf("test_curl_post_3\n"); res = curl_post("http://www.baidu.com", "abc=1&jkk=2", hs, 2); printf("test_curl_post_3-1\n"); if (res->ccode) { printf("ccode:%d\n", res->ccode); } else { printf("------------------------------>\n"); len = strlen(res->rdata); printf("abc:%d,%d\n", len, res->rcode); } curl_free_res(&res); // res = curl_post("http://wwk", 0, 0, 0); printf("ccode:%d\n", res->ccode); curl_free_res(&res); }
cJSON *SIGNPOST(char **retstrp,struct exchange_info *exchange,char *payload) { static CURL *cHandle; char *data; cJSON *json; json = 0; //if ( (data= curl_post(&cHandle,"https://api.huobi.com/apiv3",0,payload,"Content-Type:application/x-www-form-urlencoded",0,0,0)) != 0 ) if ( (data= curl_post(&cHandle,"https://api.huobi.com/apiv3",0,payload,"",0,0,0)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
cJSON *SIGNPOST(char **retstrp,struct exchange_info *exchange,char *url,char *payload) { static CURL *cHandle; char hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data; cJSON *json; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; json = 0; if ( (data= curl_post(&cHandle,url,0,payload,hdr1,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload) { char *data; cJSON *json; json = 0; //if ( (data= curl_post(&cHandle,"https://api.huobi.com/apiv3",0,payload,"Content-Type:application/x-www-form-urlencoded",0,0,0)) != 0 ) if ( dotrade == 0 ) data = exchange_would_submit(payload,"","","",""); else if ( (data= curl_post(cHandlep,"https://api.huobi.com/apiv3",0,payload,"",0,0,0)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *url,char *payload) { char hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data; cJSON *json; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; json = 0; if ( dotrade == 0 ) data = exchange_would_submit(payload,hdr1,hdr2,hdr3,hdr4); else if ( (data= curl_post(cHandlep,url,0,payload,hdr1,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *url,char *payload) { char dest[SHA512_DIGEST_SIZE*2+1],hdr1[512],hdr2[512],hdr3[512],hdr4[512],*data,*sig; cJSON *json; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; json = 0; if ( (sig= hmac_sha512_str(dest,exchange->apisecret,(int32_t)strlen(exchange->apisecret),payload)) != 0 ) sprintf(hdr1,"Sign:%s",sig); else hdr1[0] = 0; sprintf(hdr2,"Key:%s",exchange->apikey); if ( dotrade == 0 ) data = exchange_would_submit(payload,hdr1,hdr2,hdr3,hdr4); else if ( (data= curl_post(cHandlep,url,0,payload,hdr1,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
cJSON *SIGNPOST(char **retstrp,struct exchange_info *exchange,char *payload,char *method) { static CURL *cHandle; char dest[1025],url[1024],hdr1[512],hdr2[512],hdr3[512],hdr4[512],req[1024],*sig,*data = 0; cJSON *json; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; json = 0; nn_base64_encode((void *)payload,strlen(payload),req,sizeof(req)); if ( (sig= hmac_sha384_str(dest,exchange->apisecret,(int32_t)strlen(exchange->apisecret),req)) != 0 ) { sprintf(hdr1,"X-BFX-APIKEY:%s",exchange->apikey); sprintf(hdr2,"X-BFX-PAYLOAD:%s",req); sprintf(hdr3,"X-BFX-SIGNATURE:%s",sig); //printf("req.(%s) H0.(%s) H1.(%s) H2.(%s)\n",req,hdr1,hdr2,hdr3); sprintf(url,"https://api.bitfinex.com/v1/%s",method); if ( (data= curl_post(&cHandle,url,0,req,hdr1,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); } return(json); }
cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path) { char cmdbuf[2048],url[1024],buf[1024],hdr1[512],hdr2[512],hdr3[512],hdr4[512],digest[33],*data; cJSON *json; uint64_t nonce; hdr1[0] = hdr2[0] = hdr3[0] = hdr4[0] = 0; json = 0; nonce = exchange_nonce(exchange); sprintf(buf,"%s_%s_%s_%llu",exchange->apikey,exchange->userid,exchange->apisecret,(long long)nonce); //printf("MD5.(%s)\n",buf); calc_md5(digest,buf,(int32_t)strlen(buf)); sprintf(cmdbuf,"key=%s&time=%llu&md5=%s%s",exchange->apikey,(long long)nonce,digest,payload); sprintf(url,"%s/%s",EXCHANGE_AUTHURL,path); if ( dotrade == 0 ) data = exchange_would_submit(payload,hdr1,hdr2,hdr3,hdr4); else if ( (data= curl_post(cHandlep,url,0,cmdbuf,hdr1,hdr2,hdr3,hdr4)) != 0 ) json = cJSON_Parse(data); if ( retstrp != 0 ) *retstrp = data; else if ( data != 0 ) free(data); return(json); }
void NXTventure_liquidation() { /*{"quantityQNT":"607438148","unconfirmedQuantityQNT":"607438148","decimals":4,"name":"ARDR","asset":""}, {"quantityQNT":"451991779","unconfirmedQuantityQNT":"451991779","decimals":4,"name":"SuperNET","asset":"12071612744977229797"}, {"quantityQNT":"146960000","unconfirmedQuantityQNT":"146960000","decimals":4,"name":"Privatebet","asset":"17083334802666450484"}, {"quantityQNT":"79500188","unconfirmedQuantityQNT":"79500188","decimals":3,"name":"crypto777","asset":"13476425053110940554"}, {"quantityQNT":"1495473","unconfirmedQuantityQNT":"1495473","decimals":0,"name":"jl777hodl","asset":"6932037131189568014"}, {"quantityQNT":"7250","unconfirmedQuantityQNT":"7250","decimals":0,"name":"InstantDEX","asset":"15344649963748848799"},*/ char *assetids[][4] = { { "12422608354438203866", "607438148", "ARDR", "10000" }, { "12071612744977229797", "451991779", "SuperNET", "10000" }, { "17083334802666450484", "146960000", "Privatebet", "10000" }, { "13476425053110940554", "79500188", "crypto777", "1000" }, { "6932037131189568014", "1495473", "jl777hodl", "1" }, { "15344649963748848799", "7250", "InstantDEX", "1" }, }; void *cHandle=0; char *retstr,*retstr2,url[1024],*account; uint64_t txid,qty,qtyA,assetid,sum; double ratio; cJSON *array,*retjson2,*item,*retjson; int32_t i,j,decimals,numassetids=(int32_t)(sizeof(assetids)/sizeof(*assetids)),n=0; char *passphrase = ""; sprintf(url,"http://127.0.0.1:7876/nxt?requestType=getAssetAccounts&asset=16212446818542881180"); if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( (array= jarray(&n,retjson,"accountAssets")) != 0 ) { for (j=0; j<numassetids; j++) { assetid = calc_nxt64bits(assetids[j][0]); qtyA = calc_nxt64bits(assetids[j][1]); decimals = (int32_t)calc_nxt64bits(assetids[j][3]); printf("distribute %llu QNT of %s assetid %llu %.8f\n",(long long)qtyA,assetids[j][2],(long long)assetid,(double)qtyA / decimals); sum = 0; for (i=0; i<n; i++) { item = jitem(array,i); qty = j64bits(item,"quantityQNT"); ratio = (double)qty / (1000000. - 13000.); if ( (account= jstr(item,"accountRS")) != 0 && qtyA*ratio >= 1 ) { if ( strcmp(account,"NXT-XRK4-5HYK-5965-9FH4Z") != 0 ) { sum += (long long)(qtyA * ratio); sprintf(url,"requestType=transferAsset&secretPhrase=%s&recipient=%s&asset=%llu&quantityQNT=%llu&feeNQT=100000000&deadline=60",passphrase,account,(long long)assetid,(long long)(qtyA * ratio)); if ( (retstr2= curl_post(&cHandle,"http://127.0.0.1:7876/nxt","",url,"","","","")) != 0 ) { if ( (retjson2= cJSON_Parse(retstr2)) != 0 ) { txid = j64bits(retjson2,"transaction"); printf("%s %.6f %8llu QNT %s -> %llu %.8f txid %llu\n",account,ratio,(long long)qtyA,assetids[j][2],(long long)(qtyA * ratio),((double)(long long)(qtyA * ratio))/decimals,(long long)txid); free_json(retjson2); } free(retstr2); } usleep(250000); } } } printf("%s distribution total %llu QNT %.8f\n",assetids[j][2],(long long)sum,(double)sum/decimals); } } free_json(retjson); } printf("NXTventure assethodlers.%d\n",n); free(retstr); } }