trades =
%{
"3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2" => [
%{
asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
last_price: 0.09019287,
priced_in: "WAVES",
volume: 13918.3182330112
},
%{
asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
last_price: 0.1313214,
priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
volume: 9986.99466236054
},
%{
asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
last_price: 1.268e-5,
priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
volume: 9786.93694331709
}
],
"474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu" => [
%{
asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
last_price: 192.01,
priced_in: "WAVES",
volume: 137852.319057268
},
%{
asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
last_price: 279.152165,
priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
volume: 77018.2552159809
},
%{
asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
last_price: 0.02768054,
priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
volume: 38723.9182969945
},
%{
asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
last_price: 459.22,
priced_in: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck",
volume: 513.413421879477
}
],
"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8" => [
%{
asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
last_price: 0.05171444,
priced_in: "WAVES",
volume: 14110.9296573005
},
%{
asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
last_price: 7.5e-6,
priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
volume: 9722.17123718049
},
%{
asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
last_price: 0.075459,
priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p",
volume: 8482.23199810624
}
]
}
defmodule Remove_Blacklisted_Assets do
def filter_excluded_assets(number_of_assets_to_be_excluded, accumulator) when accumulator == number_of_assets_to_be_excluded do
excluded = ['DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p', '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS', '2tR9EKvDPMThfrFSb96CSBGYNwNPtzwkGcdhQjv4dVoj']
number_of_assets_to_be_excluded = length(excluded)
Enum.filter(trades, fn map -> map.priced_in != Enum.fetch!(excluded, 0) end)
|> Enum.into(%{})
|> IO.inspect
end
def filter_excluded_assets(number_of_assets_to_be_excluded, accumulator) do
excluded = ['DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p', '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS', '2tR9EKvDPMThfrFSb96CSBGYNwNPtzwkGcdhQjv4dVoj']
number_of_assets_to_be_excluded = length(excluded)
Enum.filter(trades, fn map -> map.priced_in != Enum.fetch!(excluded,(number_of_assets_to_be_excluded - accumulator)) end)
|> IO.inspect
filter_excluded_assets(number_of_assets_to_be_excluded, accumulator + 1)
end
end
Desired output:
trades =
%{
"3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2" => [
%{
asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
last_price: 0.09019287,
priced_in: "WAVES",
volume: 13918.3182330112
}
],
"474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu" => [
%{
asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
last_price: 192.01,
priced_in: "WAVES",
volume: 137852.319057268
},
%{
asset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
last_price: 459.22,
priced_in: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck",
volume: 513.413421879477
}
],
"4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8" => [
%{
asset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
last_price: 0.05171444,
priced_in: "WAVES",
volume: 14110.9296573005
}
}
]
}
iex(1)> Remove_Blacklisted_Assets.filter_excluded_assets(3,0)
** (ArgumentError) you attempted to apply :priced_in on {"3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2", [%{asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2", last_price: 0.09019287, priced_in: "WAVES", volume: 13888.8199642112}, %{asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2", last_price: 1.268e-5, priced_in: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS", volume: 9792.16173281305}, %{asset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2", last_price: 0.1313214, priced_in: "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p", volume: 9610.63424570971}]}.
How do I get Enum.filter
to drill down to the map where priced_in
is located?
Also, is the repetition of the excluded
lists and the number_of_asssets_to_be_excluded
functions in each function best practice?