Hi guys.
I am writing a code for submitting of order to buy, however it doesn't work. What I should do is to submit one limit order at a time.
Could you please check it?
/* Submission of order to buy */
insert
Code:
if (r_i>0) {
tot_cash[i]=cash[i]-limit_cash[i];
tot_stocks[i]=stocks[i]-limit_stock[i];
size=(int)(ran2(&idum)*(tot_cash[i]/b[i])));
if(size<0){
printf(“ERROR”, i, tot_stocks[i], stocks[i], limit_stock[i], size, b[i]);
size=0;
}
if(size>stock_max) {
size=stock_max;
}
for(n_trades=0; n_trades<size; n_trades++){
if(N_a==0){
temp=1;
tr=0;
sign_limit=1;
vol_bid_limit ++;
limit_cash[i]+=b[i];
status[i]++;
k=-1;
while (k<N_b){
k++
if(b[i]<bl[k]) break;
}
k_insert=k;
for(k = N_b - 1; k > k_insert - 1 ; k--) {
bl[k+1]=bl[k];
b_trader[k+1] = b_trader[k] ; bo_t_entry[k+1] = bo_t_entry[k];
}
bl[k_insert]= b[i]; b_trader[k_insert] = i; bo_t_entry[k_insert] = t; b_t_entry[i] = t;
N_b ++;
}
else if(N_a>0&&b[i]< al[N_a-1]){
temp=1;
tr =0;
sign_limit=1; vol_bid_limit ++; limit_cash[i]+=b[i]; status[i] ++;
k=-1;
while( k < N_b){
k++;
if(b[i] < bl[k]) break; }
k_insert=k;
for(k = N_b - 1; k > k_insert - 1 ; k--){
bl[k+1]=bl[k];
b_trader[k+1] = b_trader[k] ; bo_t_entry[k+1] = bo_t_entry[k];
}
bl[k_insert]= b[i];
b_trader[k_insert] = i; bo_t_entry[k_insert] = t; b_t_entry[i] = t;
N_b ++;
}
else if (N_a >=1
sign_market=1;
vol_bid_market
trading_volume
p[t]=al[N_a-1];
execution_time = t- ao_t_entry[N_a-1]; execution_time=1;
if(execution_time < TIME_MAX){
distribution_time_a[execution_time]++; count_time_a++;
}
b_t_trade[i] = t;
b_t_entry[i] = t; status[a_trader[N_a-1]] --; a_t_trade[a_trader[N_a-1]] = t; stocks[i]++; stocks[a_trader[N_a-1]]--; limit_stock[a_trader[N_a-1]]--;
cash[a_trader[N_a-1]]+= al[N_a-1]; cash[i] -=al[N_a-1];
}
}
}
Many thanks.