Skip to content

Commit

Permalink
fix: kucoin refacto
Browse files Browse the repository at this point in the history
Signed-off-by: rodesousa <[email protected]>
  • Loading branch information
rodesousa committed Nov 6, 2021
1 parent 08dee56 commit 95032b8
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 221 deletions.
1 change: 1 addition & 0 deletions fixture/kucoin_exchange_info.json

Large diffs are not rendered by default.

71 changes: 47 additions & 24 deletions lib/pex/exchange.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ defmodule Pex.Exchange do
"""
@callback get_balance() :: float

@doc """
List of coins in our portfolio
"""
@callback coins_list() :: [map]
# @doc """
# List of coins in our portfolio
# """
# @callback coins_list() :: [map]

@doc """
List of coins whitout exchange order
"""
@callback coins_list_without_exchange_order() :: [String.t()]
# @doc """
# List of coins whitout exchange order
# """
# @callback coins_list_without_exchange_order() :: [String.t()]

@doc """
Gets coins list without local order
"""
@callback coins_list_without_trade() :: [map]
# @doc """
# Gets coins list without local order
# """
# @callback coins_list_without_trade() :: [map]

@doc """
Creates a trade
"""
@callback create_trade(map) :: {:ok, %Pex.Data.Trade{}} | {:error, %Ecto.Changeset{}}
# @doc """
# Creates a trade
# """
# @callback create_trade(map) :: {:ok, %Pex.Data.Trade{}} | {:error, %Ecto.Changeset{}}

@doc """
Creates a trade with shad strategy
"""
@callback create_shad(map) :: {:ok, %Pex.Data.Trade{}} | {:error, %Ecto.Changeset{}}
# @doc """
# Creates a trade with shad strategy
# """
# @callback create_shad(map) :: {:ok, %Pex.Data.Trade{}} | {:error, %Ecto.Changeset{}}

@doc """
Places a order market buy
"""
@callback market_buy(String.t(), float, float, float) :: [map]
# @doc """
# Places a order market buy
# """
# @callback market_buy(String.t(), float, float, float) :: [map]

@doc """
Loads exchange info from fixture/filename
Expand All @@ -55,4 +55,27 @@ defmodule Pex.Exchange do
data = Jason.encode!(data)
File.write!("fixture/#{filename}", data)
end

@doc """
Return a truncated number with the same decimal number of &2
# Examples
iex> trunc(10.945, 0.01)
10.94
"""
@spec trunc(float, String.t()) :: float
def trunc(price, filter) do
decimal = String.to_float(filter)
[_a, decimal] = String.split("#{decimal}", ".")

case decimal == "0" do
true ->
trunc(price) * 1.0

false ->
price
|> Float.floor(String.length(decimal))
end
end
end
3 changes: 3 additions & 0 deletions lib/pex/risk_management.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ defmodule Pex.RiskManagement do
position: position
}
end

@doc false
def decrease(number), do: number * (1 - @decrease_rate)
end
Loading

0 comments on commit 95032b8

Please sign in to comment.