public async Task <List <BankPortfolioData> > GetPositionData() { List <BankPortfolioData> output = new List <BankPortfolioData>(); RobinhoodApi api = new RobinhoodApi() { BearerToken = ApplicationSettings.Default.RobinKey }; OutRobinData <RhPosition> datas = await api.GetPositions(); foreach (RhPosition data in datas.Data) { RhInstrument inst = await InstrumentLookup.GetRhInstrument(data.instrument); ShowMessage($"{inst.Symbol}- {inst.SimpleName}"); decimal shareCount = UtilityHandler.GetDecimalNumber(data.quantity); decimal costBasis = UtilityHandler.GetDecimalNumber(data.average_buy_price); BankPortfolioData d = new BankPortfolioData() { BankAccount_ID = UtilityHandler.GetString(data.account_number), Trade_CODE = UtilityHandler.GetString(inst.Symbol), Trade_NAME = UtilityHandler.GetString(inst.SimpleName), Shares_CNT = shareCount, CostBasis_AMNT = costBasis, Value_AMNT = shareCount * costBasis, Export_DATE = DateTime.Today, Instrument_ID = inst.Id }; output.Add(d); } return(output); }
private async Task <List <BankTransactionData> > Convert2BankTransactionData(OutRobinData <RhTransaction> datas) { List <BankTransactionData> output = new List <BankTransactionData>(); foreach (RhTransaction data in datas.Data) { string accountID = UtilityHandler.GetIdFromUrl(data.account); RhInstrument inst = await InstrumentLookup.GetRhInstrument(data.instrument); decimal valueAmt = UtilityHandler.GetDecimalNumber(data?.executed_notional?.amount); if (data.state == "cancelled") { ShowMessage($"{inst.Symbol} [{data.side.ToUpper()}] - {inst.SimpleName}"); BankTransactionData d = new BankTransactionData() { BankAccount_ID = accountID, TransAction_DATE = UtilityHandler.GetDateValue(data.created_at), TransAction_CODE = UtilityHandler.GetString(data.side).ToUpper(), Settlement_DATE = UtilityHandler.GetDateValue(data.updated_at), Trade_CODE = UtilityHandler.GetString(inst.Symbol), Trade_NAME = UtilityHandler.GetString(inst.SimpleName), Instrument_ID = UtilityHandler.GetString(inst.Id), Trade_ID = string.Empty, Shares_CNT = UtilityHandler.GetDecimalNumber(data.quantity), CostBasis_AMNT = UtilityHandler.GetDecimalNumber(data.price), Value_AMNT = valueAmt, Type_CODE = UtilityHandler.GetString(data.type), GoodUntil_CODE = UtilityHandler.GetString(data.time_in_force), State_CODE = UtilityHandler.GetString(data.state), Export_DATE = DateTime.Today }; output.Add(d); continue; } if (data.executions is null) { continue; } foreach (Execution e in data.executions) { ShowMessage($"{inst.Symbol} [{data.side.ToUpper()}] - {inst.SimpleName}"); BankTransactionData d = new BankTransactionData() { BankAccount_ID = accountID, TransAction_DATE = data.executions[0].timestamp, TransAction_CODE = UtilityHandler.GetString(data.side).ToUpper(), Settlement_DATE = UtilityHandler.GetDateValue(data.executions[0].settlement_date), Trade_CODE = UtilityHandler.GetString(inst.Symbol), Trade_NAME = UtilityHandler.GetString(inst.SimpleName), Instrument_ID = UtilityHandler.GetString(inst.Id), Trade_ID = UtilityHandler.GetString(e.id), Shares_CNT = UtilityHandler.GetDecimalNumber(e.quantity), CostBasis_AMNT = UtilityHandler.GetDecimalNumber(e.price), Value_AMNT = valueAmt, Type_CODE = UtilityHandler.GetString(data.type), GoodUntil_CODE = UtilityHandler.GetString(data.time_in_force), State_CODE = UtilityHandler.GetString(data.state), Export_DATE = DateTime.Today }; output.Add(d); } } int seqNumb = output.Count; foreach (BankTransactionData row in output) { row.Seq_NUMB = seqNumb; seqNumb--; } return(output); }