Using typed actor for mutable state in an API?

I am working on an API to our internal financial system. The financial system itself uses a TCP socket server with proprietary protocol. I need to connect to it, perform handshake and listen to new events. I got the whole thing working with classic actor. The simplified actor code is as follows:

object StockSubscriptionActor {
  case class Request(stockID: String)
  def create(host: String, port: Int)(implicit actorSystem: ActorSystem) =
    Props(new StockSubscriptionActor(host, port))
class StockSubscriptionActor(host: String, port: Int) extends Actor {
  var stockData: Map[String, Int] = Map.Empty
  override def receive = {
    case pkt: ByteString => {
      // handshake with system
      // process and update stockData
      sender() ! generateResponse(pkt)
    case StockSubscriptionActor.Request(stockID) => {
      sender() ! stockData(stockID)

Once handshake is done, the actor’s primary job is to keep the connection by responding to heartbeats sent from the socket server and listen to events to update its own mutable data stockData to serve API requests. The simplified code of the request handler is as follow:

class StockController @Inject() (actorSystem: ActorSystem)(implicit ec: ExecutionContext) {
  def getStock(stockID: String) = PositionAction.async {
    implicit request =>
      val actor = actorSystem.actorOf(StockSubscriptionActor.create(HOST, PORT))
      val actorLogic = Flow[ByteString].via(Framing.delimiter(ByteString(0x03.toByte), Int.MaxValue, false)).ask[ByteString](actor)
      RestartFlow.withBackoff(RestartSettings()) { () => Tcp().outgoingConnection(host, port) }.join(actorLogic)
      (actor ? StockSubscriptionActor.Request(stockID)).map(Ok(Json.toJson(_)))

To use the typed actor interface, I think I need to put those mutable data such as stockData into behavior and pass them around as messages? But when used inside Tcp connection flow, the actor itself only deals with ByteString so I am not sure how to pass the mutable state/data around.

Is there any code examples of a similar use case?