If first_time = True Then
If httpCode = alpaca.HTTP_CODE_OK Then
'addMemo("List open positions: Success! Items retrieved: " & response.Size)
For k = 0 To response.Size - 1
Dim op As alpacaPosition = response.Get(k)
Dim p As Panel
p.Initialize("")
p.SetLayout(0, 0, CustomListView2.AsView.Width, 75dip)
p.LoadLayout("Item")
lbl_symbol.Text = op.symbol & " (" & NumberFormat2(op.currentPrice,1,2,2,True) & ")"
'Check if there is a loss
If IsNegative(op.unrealizedIntradayPL) Then
lbl_profit_loss.Text = "$(" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True) & ")"
p.Color = xui.Color_Red
Else
lbl_profit_loss.Text = "$" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True)
p.Color = xui.Color_Green
End If
lbl_Qty.Text = NumberFormat2(op.quantity,1,2,2,True)
CustomListView2.Add(p,op.symbol)
Next
alpaca.fetchAccount
End If
Else
If httpCode = alpaca.HTTP_CODE_OK Then
'addMemo("List open positions: Success! Items retrieved: " & response.Size)
For k = 0 To response.Size - 1
Dim op As alpacaPosition = response.Get(k)
Dim pnl As B4XView = CustomListView2.GetPanel(k)
pnl.GetView(0).Text = op.symbol & " (" & NumberFormat2(op.currentPrice,1,2,2,True) & ")"
'Check if there is a loss
If IsNegative(op.unrealizedIntradayPL) Then
pnl.GetView(1).Text = "$(" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True) & ")"
pnl.Color = xui.Color_Red
Else
pnl.GetView(1).Text = "$" & NumberFormat2(op.unrealizedIntradayPL,1,2,2,True)
pnl.Color = xui.Color_Green
End If
pnl.GetView(2).Text = NumberFormat2(op.quantity,1,2,2,True)
Next
End If
End If