权益和持仓的查询


在策略中,可以通过调用AccountDataManager.GetSnapshots()方法获取所有providerID下的账户权益和持仓的明细,或GetSnapshot(byte providerId, byte route)获取指定providerID下的账户权益和持仓的明细,调用示例如下:

  1. private void AccountInfo()
  2. {
  3. System.Console.WriteLine("AccountInfo ... .. . .. ");
  4. //查询所有providerID的账户
  5. AccountDataSnapshot[] ads = this.AccountDataManager.GetSnapshots();
  6. System.Console.WriteLine("ads.Length=" + ads.Length);
  7. //AccountDataSnapshot ads_ctp = AccountDataManager.GetSnapshot(99,99); //查询CTP通道的账户
  8. foreach (AccountDataSnapshot item in ads)
  9. {
  10. AccountDataEntry[] ades = item.Entries;
  11. foreach (AccountDataEntry ade in ades)
  12. {
  13. AccountDataFieldList fields = ade.Values.Fields;
  14. foreach (AccountDataField field in fields)
  15. {
  16. Console.WriteLine("{0} = {1}" , field.Name, field.Value);
  17. }
  18. AccountData[] pos = ade.Positions;
  19. foreach (var po in pos)
  20. {
  21. Console.WriteLine("----------------------------------------");
  22. var ad = (AccountData)po;
  23. foreach (AccountDataField field in ad.Fields)
  24. {
  25. Console.WriteLine("{0} = {1}", field.Name, field.Value);
  26. }
  27. }
  28. }
  29. }
  30. }

查询结果如下:

7.3 权益和持仓的查询 - 图1