当前位置: 首页>>代码示例>>C#>>正文


C# Position.ToTrade方法代码示例

本文整理汇总了C#中Position.ToTrade方法的典型用法代码示例。如果您正苦于以下问题:C# Position.ToTrade方法的具体用法?C# Position.ToTrade怎么用?C# Position.ToTrade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Position的用法示例。


在下文中一共展示了Position.ToTrade方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Adjust

 // returns any closed PL calculated on position basis (not per share)
 /// <summary>
 /// Adjusts the position by applying a new position.
 /// </summary>
 /// <param name="pos">The position adjustment to apply.</param>
 /// <returns></returns>
 public decimal Adjust(Position pos)
 {
     if ((_sym!="") && (this.Symbol != pos.Symbol)) throw new Exception("Failed because adjustment symbol did not match position symbol");
     if (_acct == "") _acct = pos.Account;
     if (_acct != pos.Account) throw new Exception("Failed because adjustment account did not match position account.");
     if ((_sym=="") && pos.isValid) _sym = pos.Symbol;
     if (!pos.isValid) throw new Exception("Invalid position adjustment, existing:" + this.ToString() + " adjustment:" + pos.ToString());
     if (pos.isFlat) return 0; // nothing to do
     bool oldside = isLong;
     decimal pl = Calc.ClosePL(this,pos.ToTrade());
     if (this.isFlat) this._price = pos.AvgPrice; // if we're leaving flat just copy price
     else if ((pos.isLong && this.isLong) || (!pos.isLong && !this.isLong)) // sides match, adding so adjust price
         this._price = ((this._price * this._size) + (pos.AvgPrice * pos.Size)) / (pos.Size+ this.Size);
     this._size += pos.Size; // adjust the size
     if (oldside != isLong) _price = pos.AvgPrice; // this is for when broker allows flipping sides in one trade
     if (this.isFlat) _price = 0; // if we're flat after adjusting, size price back to zero
     _closedpl += pl; // update running closed pl
     return pl;
 }
开发者ID:antonywu,项目名称:tradelink,代码行数:25,代码来源:PositionImpl.cs

示例2: GotPosition

 /// <summary>
 /// pass new positions as they arrive
 /// </summary>
 /// <param name="p"></param>
 public void GotPosition(Position p)
 {
     if (p.isFlat)
         return;
     fills.Add(p.ToTrade());
 }
开发者ID:bluejack2000,项目名称:core,代码行数:10,代码来源:Results.cs

示例3: GotPosition

 /// <summary>
 /// pass new positions as they arrive
 /// </summary>
 /// <param name="p"></param>
 public void GotPosition(Position p)
 {
     fills.Add(p.ToTrade());
 }
开发者ID:sopnic,项目名称:larytet-master,代码行数:8,代码来源:Results.cs


注:本文中的Position.ToTrade方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。