/// <summary> /// To get open positions on a symbol. /// </summary> /// <param name="symbol">The contract for this position.</param> /// <param name="count">Number of results to fetch.</param> /// <returns></returns> public async ValueTask <MyPositions> GetPositions(string symbol, long count) { var _result = new MyPositions(); var _params = new Dictionary <string, object>(); { if (count > 0) { _params.Add("count", count); } _params.Add("filter", new CArgument { isJson = true, value = new Dictionary <string, object> { { "symbol", symbol } } }); } var _response = await privateClient.CallApiGet2Async("/api/v1/position", _params); if (_response != null) { #if RAWJSON _result.rawJson = _response.Content; #endif if (_response.IsSuccessful == true) { var _positions = privateClient.DeserializeObject <List <BMyPositionItem> >(_response.Content); if (_positions != null) { foreach (var _p in _positions) { _p.orderType = OrderType.Position; _p.orderStatus = _p.isOpen ? OrderStatus.Open : OrderStatus.Closed; _p.sideType = _p.quantity > 0 ? SideType.Bid : _p.quantity < 0 ? SideType.Ask : SideType.Unknown; _p.quantity = Math.Abs(_p.quantity); _p.amount = _p.price * _p.quantity; } _result.result = _positions.ToList <IMyPositionItem>(); _result.SetSuccess(); } } else { var _message = privateClient.GetResponseMessage(_response); _result.SetFailure(_message.message); } } return(_result); }
/// <summary> /// Get open positions /// </summary> /// <returns></returns> public async ValueTask <MyPositions> GetAllPositions() { var _result = new MyPositions(); var _response = await privateClient.CallApiGet2Async("/api/v1/position"); if (_response != null) { #if RAWJSON _result.rawJson = _response.Content; #endif if (_response.IsSuccessful == true) { var _positions = privateClient.DeserializeObject <List <BMyPositionItem> >(_response.Content); if (_positions != null) { foreach (var _p in _positions) { _p.orderType = OrderType.Position; _p.orderStatus = _p.isOpen ? OrderStatus.Open : OrderStatus.Closed; _p.sideType = _p.quantity > 0 ? SideType.Bid : _p.quantity < 0 ? SideType.Ask : SideType.Unknown; _p.quantity = Math.Abs(_p.quantity); _p.amount = _p.price * _p.quantity; } _result.result = _positions.ToList <IMyPositionItem>(); _result.SetSuccess(); } } else { var _message = privateClient.GetResponseMessage(_response); _result.SetFailure(_message.message); } } return(_result); }