inputs: timeout(10000),serveraddress("10.200.200.161"),port(2900),Seccode("EESR"), Long_Lot(1),lot(100),Slipage(0.0005),
        Account("S01-00000F00");

vars: login("n113"),dixilog("n113"),password("n113"),code(-2),result(-2),output_init(-3),outputconn(-3),
	logmsg(0),txt("d:\testfiles\portOC(161).txt"),trigger(0),temp(-3),brokerref("n113/"),ref1(-5),ref2(-5),ref3(-5),
	portf(-10),attempt(1), Secboard("EQBR");

defineDLLFunc: "D:\omegalib\1.0.0.30\niomegadll.dll", int, "conn",int;
defineDLLFunc: "D:\omegalib\1.0.0.30\niomegadll.dll", int, "disconn";
defineDLLFunc: "D:\omegalib\1.0.0.30\niomegadll.dll", int, "is_conn";
defineDLLFunc: "D:\omegalib\1.0.0.30\niomegadll.dll", int, "portfolio_open",LPSTR {secboard},lpstr {brokerref},lpstr {account},int {TimeOut};
defineDLLFunc: "D:\omegalib\1.0.0.30\niomegadll.dll", double,  "get_current_portfolio",LPSTR,LPSTR, LPSTR,LPSTR,int,int;
defineDLLFunc: "D:\omegalib\1.0.0.30\niomegadll.dll", int, "portfolio_close", int {ref};

if (trigger=0) then
	begin
		filedelete(txt);
		result=is_conn();
		fileappend(txt,"Connection message:"+numtostr(result,0)+newline);
		if (result=1) then
			begin
				fileappend(txt,"disconnecting..."+newline);
				disconn();
				result=is_conn();
			end;
		while (result=0) and (attempt<=5)
    		begin
	    		fileappend(txt,"connecting attempt: "+numtostr(attempt,0)+newline);
				OutputConn = conn(timeout);
				fileappend(txt,"conn result"+numtostr(outputconn,0)+newline);
				result=is_conn();
		        fileappend(txt,"Connection message after conn:"+numtostr(result,0)+newline);
				fileappend(txt,"-------------------------------------------"+newline);
				attempt=attempt+1;
		    end;
		if (result=1) then
			begin
     			fileappend(txt,"before opening"+newline);
				portf=get_current_portfolio(secboard,account,brokerref,seccode,1,timeout);
				fileappend(txt,"self portfolio: "+numtostr(portf,0)+newline);
				ref1=portfolio_open(secboard,brokerref,account,timeout);
      			fileappend(txt,"self ref: "+numtostr(ref1,0)+newline);
			    {testing of curent portfolio}
	    		portf=get_current_portfolio(secboard,account,brokerref,seccode,1,timeout);
		   	    fileappend(txt,"self portfolio: "+numtostr(portf,0)+newline);
			    {closing}
				temp=portfolio_close(ref1);
			  	fileappend(txt,"close self ref: "+numtostr(temp,0)+newline);
				{Really closed??}
			    fileappend(txt,"self portfolio after closing: "+newline);
				portf=get_current_portfolio(secboard,account,brokerref,seccode,2,timeout);
				fileappend(txt,"self portfolio: "+numtostr(portf,0)+newline);
				disconn();
				trigger=trigger+1;
			end;
	end;
