Skip to content

teqbench/tradingtoolbox.trading.modeler.data.nosql.mongodb.services

Repository files navigation

Trading Modeler MongoDB Repository Services API

Build Status Badge Build Number Badge Coverage

Overview

MongoDB repository service implementation for Trading Position Modeler.

Contents

Developer Environment Setup

General

.NET

Usage

Add NuGet Package To Project

dotnet add package TradingToolbox.Trading.Modeler.Data.NoSql.MongoDB.Services

Update Source Code

namespace TradingToolbox.Applications.Trading.Modeler.ServiceApp.Controllers
{
    /// <summary>
    /// Controller for trading position modeling.
    /// </summary>
    /// <seealso cref="Microsoft.AspNetCore.Mvc.ControllerBase" />
    [ApiController]
    [Route("api/tradingtoolbox/trading/[controller]")]
    public class ModelerController : ControllerBase
    {
        private readonly IMongoDbService _mongoDbService;

        /// <summary>
        /// Initializes a new instance of the <see cref="ModelerController" /> class.
        /// </summary>
        /// <param name="mongoDbService">The mongo database service to do DB operstaions.</param>
        public ModelerController(IMongoDbService mongoDbService)
        {
            _mongoDbService = mongoDbService;
        }

        /// <summary>
        /// Gets all of the position documents from the DB
        /// </summary>
        /// <returns>List of position documents.</returns>
        [HttpGet("positions")]
        public async Task<IActionResult> GetAll()
        {
            IEnumerable<PositionModelDocument> items = new List<PositionModelDocument>();

            try
            {
                // For now, just force sort to be by ListPosition and do here...can move to FindAsync later...
                // TODO - Add sort capability to FindAsync in TeqBench.System.Data.NoSql.MongoDb.Repository
                items = (await _mongoDbService.PositionModelRepository.FindAsync(_ => true)).OrderBy(item => item.ListPosition);
            }
            catch (Exception e)
            {
                return StatusCode(StatusCodes.Status500InternalServerError, e);
            }

            return Ok(items);
        }
    }
}

Licensing

License