public async Task <List <BankAccountTransferData> > GetBankTransfer() { RobinhoodApi robinhoodApi = new RobinhoodApi() { BearerToken = ApplicationSettings.Default.RobinKey }; OutRobinData <TransferData> datas = await robinhoodApi.GetBankTransfers(); List <BankAccountTransferData> output = new List <BankAccountTransferData>(); foreach (TransferData data in datas.Data) { ShowMessage($"{data.direction} - {data.amount} on {data.scheduled}"); DateTime createDate = UtilityHandler.GetDateValue(data.created_at); DateTime updateDate = UtilityHandler.GetDateValue(data.updated_at); decimal transferAmnt = UtilityHandler.GetDecimalNumber(data.amount); decimal feeAmnt = UtilityHandler.GetDecimalNumber(data.fees); BankAccountTransferData d = new BankAccountTransferData() { ID = data.id, Ref_ID = data.ref_id, Transfer_AMNT = transferAmnt, Fees_AMNT = feeAmnt, BankAccount_ID = UtilityHandler.GetIdFromUrl(data.account), Direction_CODE = data.direction, Status_CODE = data.state, Created_DTTM = createDate, Update_DTTM = updateDate }; 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); }