Skip to content

Commit

Permalink
Fix issue with Map.delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Sienkiewicz committed Nov 23, 2023
1 parent 087faf3 commit b9b9a10
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/xtb_client/messages/candle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule XtbClient.Messages.Candle do
} = args
)
when is_number(vol) and is_number(ctm_value) do
value = args |> Map.delete(["vol", "ctm", "ctmString", "symbol"]) |> new()
value = args |> Map.drop(["vol", "ctm", "ctmString", "symbol"]) |> new()

%{
value
Expand All @@ -73,7 +73,7 @@ defmodule XtbClient.Messages.Candle do
end

def new(%{"quoteId" => quote_id} = args) when is_integer(quote_id) do
value = args |> Map.delete(["quoteId"]) |> new()
value = args |> Map.drop(["quoteId"]) |> new()

%{
value
Expand Down
2 changes: 1 addition & 1 deletion lib/xtb_client/messages/chart_range.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule XtbClient.Messages.ChartRange do

def new(%{ticks: ticks} = args)
when is_number(ticks) do
value = args |> Map.delete(:ticks) |> new()
value = args |> Map.drop([:ticks]) |> new()

%{value | ticks: ticks}
end
Expand Down
6 changes: 3 additions & 3 deletions lib/xtb_client/messages/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ defmodule XtbClient.Messages do

def decode_message("getAllSymbols", data), do: SymbolInfos.new(data)

def decode_message("getTickPrices", data) when is_map(data) and map_size(data) > 1,
do: TickPrice.new(data)

def decode_message("getTickPrices", %{"quotations" => data}) when is_list(data),
do: TickPrices.new(data)

def decode_message("getTickPrices", data) when is_map(data) and map_size(data) > 1,
do: TickPrice.new(data)

def decode_message("getTradeRecords", data), do: TradeInfos.new(data)
def decode_message("getTrades", data), do: TradeInfos.new(data)
def decode_message("getTradesHistory", data), do: TradeInfos.new(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/xtb_client/messages/quotations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule XtbClient.Messages.Quotations do
} = args
)
when is_integer(min_arrival_time) and is_integer(max_level) do
value = args |> Map.delete([:min_arrival_time, :max_level]) |> new()
value = args |> Map.drop([:min_arrival_time, :max_level]) |> new()

%{value | minArrivalTime: min_arrival_time, maxLevel: max_level}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/xtb_client/messages/tick_price.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule XtbClient.Messages.TickPrice do
} = args
)
when is_integer(exemode) do
value = args |> Map.delete(["exemode"]) |> new()
value = args |> Map.drop(["exemode"]) |> new()

%{value | exe_mode: exemode}
end
Expand All @@ -83,7 +83,7 @@ defmodule XtbClient.Messages.TickPrice do
} = args
)
when is_integer(quote_id) do
value = args |> Map.delete(["quoteId"]) |> new()
value = args |> Map.drop(["quoteId"]) |> new()

%{value | quote_id: QuoteId.parse(quote_id)}
end
Expand Down
4 changes: 1 addition & 3 deletions lib/xtb_client/messages/tick_prices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ defmodule XtbClient.Messages.TickPrices do
def new(data)
when is_list(data) do
%__MODULE__{
data:
data
|> Enum.map(&TickPrice.new(&1))
data: Enum.map(data, &TickPrice.new(&1))
}
end
end
4 changes: 2 additions & 2 deletions lib/xtb_client/messages/trade_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule XtbClient.Messages.TradeInfo do
"type" => type
} = args
) do
value = args |> Map.delete(["state", "type"]) |> new()
value = args |> Map.drop(["state", "type"]) |> new()

%{value | state: state, type: type}
end
Expand All @@ -142,7 +142,7 @@ defmodule XtbClient.Messages.TradeInfo do
when is_number(spread) and
is_number(taxes) and
is_integer(timestamp_value) do
value = args |> Map.delete(["spread", "taxes", "timestamp"]) |> new()
value = args |> Map.drop(["spread", "taxes", "timestamp"]) |> new()

%{
value
Expand Down
2 changes: 1 addition & 1 deletion lib/xtb_client/messages/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule XtbClient.Messages.UserInfo do
trailing_stop: false

def new(%{"spreadType" => spread_type} = args) do
value = args |> Map.delete("spreadType") |> __MODULE__.new()
value = args |> Map.drop(["spreadType"]) |> __MODULE__.new()

%{value | spread_type: spread_type || ""}
end
Expand Down

0 comments on commit b9b9a10

Please sign in to comment.