Приветствую,форумчане!
Помогите разобраться с кодом.сам не смог до конца
Есть 2 файла:
over.json
{
"server_time":"2016-03-26T08:57:28.063Z","error":false,"warning":false,
"response":
{"email":"lblabklas@gmail.com","balance_btc":"0.01941241","positions_worth_btc":"0.01987192","net_worth_btc":"0.03928433",
"orders_open":[],
"positions_open":
[
{"position_id":"742007","order_id":"734425","symbol":"BTCUSD","margin":"0.01","leverage":"2","direction":"long","entry_price":"416.19","current_bid":"415.39","current_ask":"416.19","profit_loss":"-0.00003852","profit_loss_percent":"-0.39","value":"0.00996148","market_close":false,"stop_loss":"297.278571","take_profit":null,"created":"2016-03-26T08:57:25Z"},
{"position_id":"741898","order_id":"734289","symbol":"EURUSD","margin":"0.01","leverage":"50","direction":"long","entry_price":"1.1166","current_bid":"1.1164","current_ask":"1.1165","profit_loss":"-0.00008956","profit_loss_percent":"-0.9","value":"0.00991044","market_close":false,"stop_loss":"1.115672","take_profit":"1.117547","created":"2016-03-25T15:08:40Z"}
]
}
}
overview2.js
timer=setInterval(function(){
$.ajaxSetup({cache: false});
$.ajax({
type: 'GET',
url: 'js/over.json',
cache: false,
dataType: 'json'
})
.done(function(d){
var err=d.error;
if(err==false){
var bal=d.response.balance_btc;
$('#bal').val(bal);
var positions=''+d.response.positions_open+'';
if(positions!="undefined"){
var dd=positions.length;//uzname skolko vsego poziciy otkryto
if(dd>0){
var z;
for(z=0;z<dd;z++){
var pos_id=d.response.positions_open[z].position_id;
pos_id=parseInt(pos_id);
var order_id=''+d.response.positions_open[z].order_id+'';
var symbol=''+d.response.positions_open[z].symbol+'';
var margin=''+d.response.positions_open[z].margin+'';
var level=''+d.response.positions_open[z].leverage+'';
var direction=d.response.positions_open[z].direction;
var entry_price=''+d.response.positions_open[z].entry_price+'';
entry_price=String(entry_price);
entry_price=entry_price.substring(0,8);
var current_ask=''+d.response.positions_open[z].current_ask+'';
current_ask==String(current_ask);
current_ask=current_ask.substring(0,8);
var current_bid=''+d.response.positions_open[z].current_bid+'';
current_bid==String(current_bid);
current_bid=current_bid.substring(0,8);
var profit_loss=''+d.response.positions_open[z].profit_loss+'';
profit_loss=profit_loss.substring(0,7);
var profit_loss_percent=''+d.response.positions_open[z].profit_loss_percent+'';
var value=''+d.response.positions_open[z].value+'';
var stop_loss=''+d.response.positions_open[z].stop_loss+'';
stop_loss=String(stop_loss);
stop_loss=stop_loss.substring(0,8);
var take_profit=''+d.response.positions_open[z].take_profit+'';
take_profit=String(take_profit);
take_profit=take_profit.substring(0,8);
var created=''+d.response.positions_open[z].created+'';
zaman=String(created);
var zaman1=zaman.split("T");
var minutes=zaman1[1];
minutes=minutes.replace("Z","");
minutes=String(minutes);
var minutes1=minutes.split(":");
var created=parseInt(minutes1[0]*60*60)+parseInt(minutes1[1]*60)+parseInt(minutes1[2]);
var vremya=window.timestamp-created;
//var dnn=''+pos_id+'/'+direction+'/'+profit_loss+'/'+profit_loss_percent+ '/'+margin+'/'+level+'/'+entry_price+'/'+stop_loss+'/'+take_profit+'/'+created+'</br>';
var ms={};
var ms={
'pos_id':pos_id,
'symbol':symbol,
'order_id':order_id ,
'margin':margin ,
'level':level,
'direction':direction ,
'entry_price':entry_price ,
'current_ask':current_ask ,
'current_bid':current_bid ,
'profit_loss':profit_loss,
'profit_loss_percent':profit_loss_percent,
'value':value ,
'stop_loss':stop_loss,
'take_profit': take_profit,
'created': created,
'vremya':vremya
};
$('#positions').html(''+ms.pos_id+'/'+ms.direction+'/'+ms.profit_loss+'/'+ms.profit_loss_percent+ '/'+ms.margin+'/'+ms.level+'/'+ms.entry_price+'/'+ms.stop_loss+'/'+ms.take_profit+'/'+ms.created+'</br>');
// K SOZHALENIYU YA NE MOGU PROCHEST VSE OTKRITIE POZICII
//KAK VIDITE VIDAET TOLKO ODNU POZICIYU
//KROME TOGO XOCHU MANUPULIROVAT NAPRIMER S ETOY STROKOY:
// ms.entry_price-current_ask (XOCHU UZNAT RAZNICU MEZHDU VXODOM V RINOK I NINEWNOY CENOY ASK)
//T.E. XOCHU UZNAT RAZNICU DLYA KAZHDOY SDELKI.DAJE ESLI IX BOLSHE DVUX
} // for
}//dd==0
}//position undefined
}//err false
});//done
},2255); // SERINTERVAL
// ### Timer end
проблема в том что не могу получить доступ ко всем "positions_open":
может я json неправильно прочитал.может задачу я выдумал себе уж слишком непростую.
этот скрипт каждые 2 секунды проверяет через сколько позиций открыто на моем форекс счету. самое простое что я хотел бы сделать: узнать насколько цена entry_price отошла от нынешной цены current_ask.но этим кодом я могу получить доступ к одной позиции,а не ко всем((