uint64_t TRADE(char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume) { char payload[1024],pairstr[64],pricestr[64],*extra,*method; cJSON *json; int32_t type; uint64_t txid = 0; if ( (extra= *retstrp) != 0 ) *retstrp = 0; if ( (dir= flipstr_for_exchange(exchange,pairstr,"%s%s",dir,&price,&volume,base,rel)) == 0 ) { printf("cant find baserel (%s/%s)\n",base,rel); return(0); } if ( extra != 0 && strcmp(extra,"market") == 0 ) method = (dir > 0) ? "buy_market" : "sell_market"; else method = (dir > 0) ? "buy" : "sell", sprintf(pricestr,"&price=%.2f",price); if ( strcmp(pairstr,"btccny") == 0 ) type = 1; else if ( strcmp(pairstr,"ltccny") == 0 ) type = 2; else { printf("cant find baserel (%s/%s)\n",base,rel); return(0); } sprintf(payload,"&amount=%.4f&coin_type=%d%s",volume,type,pricestr); if ( (json= huobi_issue_auth(exchange,method,payload)) != 0 ) { txid = j64bits(json,"order_id"); free_json(json); } return(txid); }
uint64_t TRADE(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume) { char payload[1024],buf[1024],url[1024],digest[512],pairstr[512],pricestr[64],*extra,*typestr; cJSON *json; uint64_t txid = 0; if ( (extra= *retstrp) != 0 ) *retstrp = 0; if ( (dir= flipstr_for_exchange(exchange,pairstr,"%s_%s",dir,&price,&volume,base,rel)) == 0 ) { printf("cant find baserel (%s/%s)\n",base,rel); return(0); } if ( extra != 0 && strcmp(extra,"market") == 0 ) typestr = (dir > 0) ? "buy_market" : "sell_market", sprintf(pricestr,"&price=%.2f",price); // docs say market orders put volume in price else typestr = (dir > 0) ? "buy" : "sell"; sprintf(pricestr,"&price=%.2f",price); sprintf(buf,"amount=%.4f&api_key=%s%ssymbol=%s&type=%s&secret_key=%s",volume,exchange->apikey,pricestr,pairstr,typestr,exchange->apisecret); calc_md5(digest,buf,(int32_t)strlen(buf)); touppercase(digest); sprintf(payload,"amount=%.4f&api_key=%s%s&symbol=%s&type=%s&sign=%s",volume,exchange->apikey,pricestr,pairstr,typestr,digest); sprintf(url,"%s/%s",EXCHANGE_AUTHURL,"trade.do"); if ( CHECKBALANCE(retstrp,dotrade,exchange,dir,base,rel,price,volume) == 0 && (json= SIGNPOST(cHandlep,dotrade,retstrp,exchange,url,payload)) != 0 ) { txid = j64bits(json,"order_id"); free_json(json); } return(txid); }
uint64_t TRADE(char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume) { char payload[1024],pairstr[512],*typestr,*method,*extra; cJSON *json; uint64_t txid = 0; if ( (extra= *retstrp) != 0 ) *retstrp = 0; if ( (dir= flipstr_for_exchange(exchange,pairstr,"%s%s",dir,&price,&volume,base,rel)) == 0 ) { printf("cant find baserel (%s/%s)\n",base,rel); return(0); } method = "order/new"; //Either "market" / "limit" / "stop" / "trailing-stop" / "fill-or-kill" / "exchange market" / "exchange limit" / "exchange stop" / "exchange trailing-stop" / "exchange fill-or-kill". (type starting by "exchange " are exchange orders, others are margin trading orders) if ( (typestr= extra) == 0 ) typestr = "exchange limit"; sprintf(payload,"{\"request\":\"/v1/%s\",\"nonce\":\"%llu\",\"exchange\":\"bitfinex\",\"side\":\"%s\",\"type\":\"%s\",\"price\":\"%.8f\",\"amount\":\"%.8f\",\"symbol\":\"%s\"}",method,(long long)exchange_nonce(exchange),dir>0?"buy":"sell",typestr,price,volume,pairstr); if ( (json= SIGNPOST(retstrp,exchange,payload,method)) != 0 ) { if ( (txid= j64bits(json,"order_id")) == 0 ) { if ( dir != 0 ) printf("bitfinex: no txid error\n"); } free_json(json); } return(txid); }
uint64_t TRADE(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume) { char payload[1024],pairstr[64],*extra,*path; cJSON *json; uint64_t txid = 0; if ( (extra= *retstrp) != 0 ) *retstrp = 0; if ( (dir= flipstr_for_exchange(exchange,pairstr,"%s_%s",dir,&price,&volume,base,rel)) == 0 ) { printf("cant find baserel (%s/%s)\n",base,rel); return(0); } path = (dir > 0) ? "buy" : "sell"; //key - API key //signature - signature //nonce - nonce //amount - amount of major currency //price - price to buy at //book - optional, if not specified, will default to btc_cad sprintf(payload,"\"amount\":%.6f,\"price\":%.3f,\"book\":\"%s_%s\",",volume,price,base,rel); if ( CHECKBALANCE(retstrp,dotrade,exchange,dir,base,rel,price,volume) == 0 && (json= SIGNPOST(cHandlep,dotrade,retstrp,exchange,payload,path)) != 0 ) { // parse json and set txid free_json(json); } return(txid); }
uint64_t TRADE(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume) { char payload[1024],url[512],pairstr[512],*extra; cJSON *json; uint64_t txid = 0; if ( (extra= *retstrp) != 0 ) *retstrp = 0; if ( (dir= flipstr_for_exchange(exchange,pairstr,"%s%s",dir,&price,&volume,base,rel)) == 0 ) { printf("cant find baserel (%s/%s)\n",base,rel); return(0); } sprintf(url,"%s/%s/",EXCHANGE_AUTHURL,dir>0 ? "buy" : "sell"); if ( CHECKBALANCE(retstrp,dotrade,exchange,dir,base,rel,price,volume) == 0 && (json= SIGNPOST(cHandlep,dotrade,retstrp,exchange,url,payload)) != 0 ) { // parse json and set txid free_json(json); } return(txid); }