From b9b9a10c121020af66cc69db47eeae13ba9570f3 Mon Sep 17 00:00:00 2001 From: Daniel Sienkiewicz Date: Thu, 23 Nov 2023 12:34:24 +0100 Subject: [PATCH] Fix issue with Map.delete --- lib/xtb_client/messages/candle.ex | 4 ++-- lib/xtb_client/messages/chart_range.ex | 2 +- lib/xtb_client/messages/messages.ex | 6 +++--- lib/xtb_client/messages/quotations.ex | 2 +- lib/xtb_client/messages/tick_price.ex | 4 ++-- lib/xtb_client/messages/tick_prices.ex | 4 +--- lib/xtb_client/messages/trade_info.ex | 4 ++-- lib/xtb_client/messages/user.ex | 2 +- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/xtb_client/messages/candle.ex b/lib/xtb_client/messages/candle.ex index 0297e4b..b913aa7 100644 --- a/lib/xtb_client/messages/candle.ex +++ b/lib/xtb_client/messages/candle.ex @@ -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 @@ -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 diff --git a/lib/xtb_client/messages/chart_range.ex b/lib/xtb_client/messages/chart_range.ex index 8976274..3474b70 100644 --- a/lib/xtb_client/messages/chart_range.ex +++ b/lib/xtb_client/messages/chart_range.ex @@ -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 diff --git a/lib/xtb_client/messages/messages.ex b/lib/xtb_client/messages/messages.ex index b1117c5..2334ea6 100644 --- a/lib/xtb_client/messages/messages.ex +++ b/lib/xtb_client/messages/messages.ex @@ -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) diff --git a/lib/xtb_client/messages/quotations.ex b/lib/xtb_client/messages/quotations.ex index f64e4b9..5734d97 100644 --- a/lib/xtb_client/messages/quotations.ex +++ b/lib/xtb_client/messages/quotations.ex @@ -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 diff --git a/lib/xtb_client/messages/tick_price.ex b/lib/xtb_client/messages/tick_price.ex index 86f1294..8e7e96d 100644 --- a/lib/xtb_client/messages/tick_price.ex +++ b/lib/xtb_client/messages/tick_price.ex @@ -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 @@ -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 diff --git a/lib/xtb_client/messages/tick_prices.ex b/lib/xtb_client/messages/tick_prices.ex index 4c24899..5003628 100644 --- a/lib/xtb_client/messages/tick_prices.ex +++ b/lib/xtb_client/messages/tick_prices.ex @@ -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 diff --git a/lib/xtb_client/messages/trade_info.ex b/lib/xtb_client/messages/trade_info.ex index c8b5838..e2c9135 100644 --- a/lib/xtb_client/messages/trade_info.ex +++ b/lib/xtb_client/messages/trade_info.ex @@ -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 @@ -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 diff --git a/lib/xtb_client/messages/user.ex b/lib/xtb_client/messages/user.ex index 9133ca7..747ddc1 100644 --- a/lib/xtb_client/messages/user.ex +++ b/lib/xtb_client/messages/user.ex @@ -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