搜尋此網誌

2010年9月4日 星期六

FXCM order2go 自動交易測試成功

這2天在進行用delphi 寫FXCM 的 order2go API 自動下單
一開始用 opentrade() 送出下單老是會出現
"the account with the speecified  identifier is not found"
 oTradeDesk.OpenTrade(edAccount.Text, edCurrencyPair.Text, ovBuy, iLots, dRate, sQuoteID, 0, 0, 0, 0, vOrderId, vPSD);

試了數次查不出來原因,後來仔細查看 help 的說明
第一個參數是accountID
wcsAccountID :The identifier of the account. The account must exist in the accounts table. Use the AccountID column to get the identifier of the account.
原本以為跟login 的 username 一樣都是10位數的文字
但後來在 account table 看到
AccountID  String:
 The unique number of the account. The number is unique within the connection (Real or Demo). Please note that by "connection" we mean that your Demo AccountID will be unique to all Demo accounts, and Real AccountID will unique to all Real accounts WITHIN same URL. "Connection" here does not mean the Session between Login and Logout.
Please note that FX Trading Station displays field AccountName with a Label "Account", and using AccountName parameter value somewhere where actual AccountID is required will not give you desired result.
To get CORRECT AccountID for your account, please get it from "Accounts" table of Order2Go and not from FX Trading Station.
原來 accountID 要另外用 Account table 取得,跟 login 的 username  不一樣
於是使用用 accounts table 要取 AccountID 又出現沒有這個 propertites 的錯誤xd
var
    acc : OleVariant;
begin   
  acc :=  oTradeDesk.TablesManager.FindTable('Accounts');
  edAccount.Text:=acc.AccountID;
end;
上列的寫法還是會錯誤


難道HELP 裏頭寫的是錯誤的嗎,只好用 FXCM的原本程式先下單
再用api 的 Trades table 讀取已下單資料,裏頭也有AccountID
var
    oTrade : OleVariant;
    oRows : OleVariant;
    i : Integer;
    Count_ : Integer;
begin
    oTrade :=  oTradeDesk.TablesManager.FindTable('Trades');
    oRows := oOffers.Rows;
    Count_ := oRows.Count;
    for i := 1 to Count_ do   begin
        memo1.lines.add(
        format('%s,%s,%s,%s,%s,%s,%s,%s,%s',[
        oRows.Item(i).TradeID,
        oRows.Item(i).OfferID,
        oRows.Item(i).AccountID,
        oRows.Item(i).Instrument,
        oRows.Item(i).Lot,
        oRows.Item(i).AmountK,
        oRows.Item(i).BS,
        oRows.Item(i).Open,
        oRows.Item(i).OpenOrderID
        ]));
    end;
end;    
上列的寫法總算可以捉到,不再發生錯誤了

終於捉到AccountID 只有5位數,再用這個AccountID代入 opentrade()裏去送下單
總算是成功了

沒有留言: