using System; using System.Collections.Generic; using Newtonsoft.Json; namespace BrokerInterfaceTDAmeritrade.Models { //https://developer.tdameritrade.com/account-access/apis/get/accounts-0 //https://jsoneditoronline.org/#left=cloud.072ef793b8c745d0ba37f10d71ef7dc5 TDA-PORTFOLIO-MODEL public class TdaPosition { public double shortQuantity { get; set; } public double averagePrice { get; set; } public double currentDayProfitLoss { get; set; } public double currentDayProfitLossPercentage { get; set; } public double longQuantity { get; set; } public double settledLongQuantity { get; set; } public double settledShortQuantity { get; set; } public double agedQuantity { get; set; } public TdaInstrument instrument { get; set; } public double marketValue { get; set; } //Custom public DateTime matchedClosedDateTime { get; set; } public string accountId { get; set; } } public class CancelTime { public string date { get; set; } public bool shortFormat { get; set; } } public class OrderLegCollection { public string orderLegType { get; set; } public int? legId { get; set; } public TdaInstrument instrument { get; set; } public string instruction { get; set; } public string positionEffect { get; set; } public double? quantity { get; set; } public string quantityType { get; set; } } public class TdaInstrument { public string assetType { get; set; } public string cusip { get; set; } public string symbol { get; set; } public string description { get; set; } } public class ReplacingOrderCollection { } public class ChildOrderStrategy { } public class OrderStrategy { public string session { get; set; } public string duration { get; set; } public string orderType { get; set; } public object cancelTime { get; set; } public string complexOrderStrategyType { get; set; } public double? quantity { get; set; } public double? filledQuantity { get; set; } public double? remainingQuantity { get; set; } public string requestedDestination { get; set; } public string destinationLinkName { get; set; } public object releaseTime { get; set; } public decimal? stopPrice { get; set; } public string stopPriceLinkBasis { get; set; } public string stopPriceLinkType { get; set; } public double? stopPriceOffset { get; set; } public string stopType { get; set; } public string priceLinkBasis { get; set; } public string priceLinkType { get; set; } public decimal? price { get; set; } public string taxLotMethod { get; set; } public List orderLegCollection { get; set; } public double? activationPrice { get; set; } public string specialInstruction { get; set; } public string orderStrategyType { get; set; } public long? orderId { get; set; } public long? localOrderId { get; set; } public bool? cancelable { get; set; } public bool? editable { get; set; } public string status { get; set; } public DateTime? enteredTime { get; set; } public DateTime? closeTime { get; set; } public string tag { get; set; } public long? accountId { get; set; } public List orderActivityCollection { get; set; } public List replacingOrderCollection { get; set; } public List childOrderStrategies { get; set; } public string statusDescription { get; set; } public DateTime? goodAtDateTime { get; set; } public DateTime? goodUntilDateTime { get; set; } public bool isTimeStop() { return goodAtDateTime == null ? false : true; } public string makeOrderRequest() { var accountId = this.accountId.ToString(); this.orderId = null; this.localOrderId = null; this.accountId = null; this.quantity = null; this.status = null; this.enteredTime = null; this.goodAtDateTime = null; return accountId; } } public class ExecutionLeg { public int legId { get; set; } public double quantity { get; set; } public double mismarkedQuantity { get; set; } public decimal price { get; set; } public DateTime time { get; set; } } public class OrderActivityCollection { public string activityType { get; set; } public string executionType { get; set; } public double quantity { get; set; } public double orderRemainingQuantity { get; set; } public List executionLegs { get; set; } } public class InitialBalances { public double accruedInterest { get; set; } public double cashAvailableForTrading { get; set; } public double cashAvailableForWithdrawal { get; set; } public double cashBalance { get; set; } public double bondValue { get; set; } public double cashReceipts { get; set; } public double liquidationValue { get; set; } public double longOptionMarketValue { get; set; } public double longStockValue { get; set; } public double moneyMarketFund { get; set; } public double mutualFundValue { get; set; } public double shortOptionMarketValue { get; set; } public double shortStockValue { get; set; } public bool isInCall { get; set; } public double unsettledCash { get; set; } public double cashDebitCallValue { get; set; } public double pendingDeposits { get; set; } public double accountValue { get; set; } } public class CurrentBalances { public double accruedInterest { get; set; } public double cashBalance { get; set; } public double cashReceipts { get; set; } public double longOptionMarketValue { get; set; } public double liquidationValue { get; set; } public double longMarketValue { get; set; } public double moneyMarketFund { get; set; } public double savings { get; set; } public double shortMarketValue { get; set; } public double pendingDeposits { get; set; } public double cashAvailableForTrading { get; set; } public double cashAvailableForWithdrawal { get; set; } public double cashCall { get; set; } public double longNonMarginableMarketValue { get; set; } public double totalCash { get; set; } public double shortOptionMarketValue { get; set; } public double mutualFundValue { get; set; } public double bondValue { get; set; } public double cashDebitCallValue { get; set; } public double unsettledCash { get; set; } } public class ProjectedBalances { public double accruedInterest { get; set; } public double cashBalance { get; set; } public double cashReceipts { get; set; } public double longOptionMarketValue { get; set; } public double liquidationValue { get; set; } public double longMarketValue { get; set; } public double moneyMarketFund { get; set; } public double savings { get; set; } public double shortMarketValue { get; set; } public double pendingDeposits { get; set; } public double cashAvailableForTrading { get; set; } public double cashAvailableForWithdrawal { get; set; } public double cashCall { get; set; } public double longNonMarginableMarketValue { get; set; } public double totalCash { get; set; } public double shortOptionMarketValue { get; set; } public double mutualFundValue { get; set; } public double bondValue { get; set; } public double cashDebitCallValue { get; set; } public double unsettledCash { get; set; } } public class SecuritiesAccount { public string type { get; set; } public string accountId { get; set; } public int roundTrips { get; set; } public bool isDayTrader { get; set; } public bool isClosingOnlyRestricted { get; set; } public List positions { get; set; } public List orderStrategies { get; set; } public InitialBalances initialBalances { get; set; } public CurrentBalances currentBalances { get; set; } public ProjectedBalances projectedBalances { get; set; } } public class SecuritiesAccountItem { public SecuritiesAccount securitiesAccount { get; set; } } public class Error { public string error { get; set; } } public class Mapper { public static string OrderType(string source) { switch (source.ToUpper()) { case "MARKET": return "MARKET"; case "LIMIT": return "LIMIT"; case "STOP": return "STOP"; case "STOPLIMIT": return "STOP_LIMIT"; case "TRAILINGSTOP": return "TRAILING_STOP"; default: return ""; } } public static string AssetType(string source) { switch (source.ToUpper()) { case "STK": return "EQUITY"; default: return ""; } } public static string Duration(string source) { switch (source.ToUpper()) { case "GTC": return "GOOD_TILL_CANCEL"; case "GDA": return "DAY"; case "FOK": return "FILL_OR_KILL"; default: return "DAY"; } } } }