Skip to content

Commit

Permalink
Add metadata to subscribe functions (#28)
Browse files Browse the repository at this point in the history
* Add metadata to subscribe_ functions to StreamingSocket

* Refactor streaming message struct

* Code review fix

* Fix closing position with price

* Fix type error
  • Loading branch information
dsienkiewicz authored Feb 1, 2024
1 parent 6fe11a3 commit 5162832
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 152 deletions.
28 changes: 9 additions & 19 deletions lib/xtb_client/streaming_message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,30 @@ defmodule XtbClient.StreamingMessage do
@type t :: %__MODULE__{
method: String.t(),
response_method: String.t(),
metadata: map(),
params: map() | nil
}
@type token :: {:method, String.t()} | {:hashed_params, String.t(), String.t()}

@enforce_keys [:method, :response_method, :params]
@enforce_keys [:method, :response_method, :metadata, :params]
defstruct method: "",
response_method: "",
metadata: %{},
params: nil

def new(method, response_method, params \\ nil) do
def new(method, response_method, metadata, params \\ nil) do
%__MODULE__{
method: method,
response_method: response_method,
metadata: metadata,
params: params
}
end

def encode_token(%__MODULE__{method: "getTrades" = method_name}) do
{:method, method_name}
def get_method_name(%__MODULE__{method: method_name}) do
method_name
end

def encode_token(%__MODULE__{method: method_name, params: %{symbol: symbol}}) do
{:hashed_params, method_name, symbol}
end

def encode_token(%__MODULE__{method: method_name}) do
{:method, method_name}
end

def decode_method_name({:method, method}) do
method
end

def decode_method_name({:hashed_params, method, _symbol}) do
method
def get_metadata(%__MODULE__{metadata: metadata}) do
metadata
end
end
Loading

0 comments on commit 5162832

Please sign in to comment.