inputs: timeout(10000),serveraddress("10.200.200.161"),port(2900),Seccode("GAZR-12.06"),
	    Secboard("PSFU"), Long_Lot(1),lot(100),Slipage(0.0005),
        Account("AC1");
{GAZR-12.06}
vars: login("n113"),dixilog("n113"),password("n113"),code(-2),result(-2),output_init(-3),outputconn(-3),
	logmsg(0),txt("d:\testfiles\FutPort(161)(bot).txt"),trigger(0),temp(-3),brokerref("n113/"),ref1(-5),ref2(-5),ref3(-5),
	portf(-10),attempt(0);

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

if (trigger=0) then
	begin
		result=is_conn();
		if (result=1) then
			begin
				fileappend(txt,"Let,s disconnect"+newline);
				disconn();
				result=is_conn();
			end;
		while (result=0) and (attempt<=5)
    		begin
	    		fileappend(txt,"if ... the works"+newline);
				OutputConn = conn(timeout);
				fileappend(txt,"conn result"+numtostr(outputconn,0)+newline);
				result=is_conn();
				attempt=attempt+1;
    		end;
		if (result=1) then
			begin
      			ref1=portfolio_open(secboard,"","",timeout);
      			fileappend(txt,"self ref: "+numtostr(ref1,0)+newline);
		  {testing of curent portfolio}
	    		brokerref="009";
	  			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);
			   	trigger=1;
				disconn();
			end;
		fileappend(txt,"-------------------------------------"+newline);
	 end;
