Цитата |
---|
GrigoriyA написал: у меня такая же проблема . и такой же демо счет финама. Никто ничего ответить не может форум экспертов блин |
Ну почему же никто?
Отправка ассинхронного ордера
procedure TExpert.OnTrade;
var
outStr, id: string;
res: long;
ErrCode: long;
ErrSize: Dword;
ErrStr: LPSTR;
Dt: TDateTime;
begin
FOrder:= 0;
FTransID:= GetTransID();
id:= IntToStr(TransID);
FMustSpotVol:= (Volume * ExpData.FutData.Lot)/ExpData.SpotData.Lot; //Get spot volume
case aSell of
0: begin //Buy trade, sell spot (output position)
outStr:= 'ACCOUNT=' + ExpData.SpotAccaunt + '; CLIENT_CODE=' +
ExpData.Client + '; TYPE=L; TRANS_ID=' + id + '; CLASSCODE=' +
ExpData.SpotData.ClassCode + '; SECCODE=' + ExpData.SpotData.SecCode +
'; ACTION=NEW_ORDER; OPERATION=S' + '; PRICE=' +
FloatToStr(ExpData.SpotData.BuyPrice - 10 * ExpData.SpotData.Step) +
'; QUANTITY=' + FloatToStr(MustSpotVol) + ';';
end;
else begin
outStr:= 'ACCOUNT=' + ExpData.SpotAccaunt + '; CLIENT_CODE=' +
ExpData.Client + '; TYPE=L; TRANS_ID=' + id +
'; CLASSCODE=' + ExpData.SpotData.ClassCode + '; SECCODE=' +
ExpData.SpotData.SecCode +
'; ACTION=NEW_ORDER; OPERATION=B' + '; PRICE=' +
FloatToStr(ExpData.SpotData.SellPrice + 10 * ExpData.SpotData.Step) +
'; QUANTITY=' + FloatToStr(MustSpotVol) + ';';
end;
end;
ErrCode:= 0;
ErrSize:= 0;
ErrStr:= nil;
res:= T2QSendASyncTrans(LPSTR(AnsiString(outStr)), ErrCode, ErrStr, ErrSize);
if(res <> TRANS2QUIK_SUCCESS) then
begin
FTransID:= 0;
FTransBusy:= false;
end else
begin
Dt:= now();
FMemo.Lines.Add(DateToStr(Dt) + ' ' + FormatDateTime('hh:mm:ss.zzz', Now()) +
' --> Ордер ' + ExpData.SpotData.SecCode + ' отправлен.');
end;
end;
Получение тикета
//--- Transaction callback -----
procedure pfTransReplyCB;
var
i: integer;
Child: TMDIChild;
begin
Mutex.Lock;
try
for i:= 0 to MainForm.MDIChildCount - 1 do
begin
Child:= TMDIChild(MainForm.MDIChildren[i]);
if(Child <> nil) then
begin
if(dwTransId = Child.Expert.TransID) then
begin
if(nTransactionResult = TRANS2QUIK_SUCCESS) then
Child.Expert.FOrder:= nOrderNum else //Get order done
Child.Expert.FTransBusy:= false; //Get order fail
break;
end;
end;
end;
finally
Mutex.UnLock;
end;
end;
Смотрим, что произошло с ордером
//--- Order status callback -----
procedure pfOrderStatusCB;
var
i: integer;
Child: TMDIChild;
StartQty: Quantity;
// s: string;
begin
if((nMode = 0) and (dwTransID > 0)) then
begin
Mutex.Lock;
try
for i := 0 to MainForm.MDIChildCount - 1 do
begin
Child:= TMDIChild(MainForm.MDIChildren[i]);
if(Child <> nil) then
begin
if(Child.Expert.TransID = dwTransID) then
begin
if(dNumber = Child.Expert.Order) then
begin
StartQty:= T2QOrderQty(ordDescr); //Order start volume
if(string(SecCode) = Child.Expert.ExpData.FutData.SecCode) then //future
begin
case nStatus of
1: {active};
2: begin
if(StartQty = nBalance) then //Canceled
begin
Child.Expert.FOrder:= 0;
Child.Expert.FTransID:= 0;
Child.Expert.FTransBusy:= false;
end else
begin //Partial done
case nIsSell of
0: Child.Expert.FFutVol:= Child.Expert.FFutVol + (StartQty - nBalance);
else Child.Expert.FFutVol:= Child.Expert.FFutVol - (StartQty - nBalance);
end;
Child.Expert.FVolume:= StartQty - nBalance;
Child.Expert.FaSell:= nIsSell;
Child.Expert.FOrder:= 0;
PostMessage(Child.Expert.Handle, WM_ON_TRADE,
NativeUint(Child.Expert.Handle), 0);
end;
end;
else begin //Future order Done
case nIsSell of
0: Child.Expert.FFutVol:= Child.Expert.FFutVol + (StartQty - nBalance);
else Child.Expert.FFutVol:= Child.Expert.FFutVol - (StartQty - nBalance);
end;
Child.Expert.FVolume:= StartQty - nBalance;
Child.Expert.FaSell:= nIsSell;
Child.Expert.FOrder:= 0;
PostMessage(Child.Expert.Handle, WM_ON_TRADE,
NativeUint(Child.Expert.Handle), 0);
end;
end;
break;
end else
if(string(SecCode) = Child.Expert.ExpData.SpotData.SecCode) then //spot
begin
case nStatus of
1:{active};
2: begin //Canceled
Child.Expert.FOrder:= 0;
Child.Expert.FTransID:= 0;
Child.Expert.FOrder:= 0;
Child.Expert.FTransBusy:= false;
end;
else begin //Spot order Done
Child.Expert.FOrder:= 0;
Child.Expert.FTransID:= 0;
case nIsSell of
0: Child.Expert.FSpotVol:= Child.Expert.FSpotVol + (StartQty - nBalance);
else Child.Expert.FSpotVol:= Child.Expert.FSpotVol - (StartQty - nBalance);
end;
Child.Expert.FOrder:= 0;
Child.Expert.FTransBusy:= false;
end;
end;
break;
end;
end;
end;
end;
end;
finally
Mutex.Unlock;
end;
end;
end;