Skip to content

Commit

Permalink
Merge pull request #14 from dsienkiewicz/issue-13-refactor-start_link
Browse files Browse the repository at this point in the history
#13 Refactor start link
  • Loading branch information
dsienkiewicz authored Nov 21, 2023
2 parents 550f114 + 05bb94d commit 2ccb05f
Show file tree
Hide file tree
Showing 40 changed files with 649 additions and 449 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ npm-debug.log

# Dotenv files
.env*

# VSCode
.vscode/
3 changes: 3 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
elixir 1.15.6-otp-26
erlang 26.1.1
direnv 2.32.2
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ Find more examples in the folder `examples/`.

### Starting client connection
```elixir
params = %{app_name: "XtbClient", type: :demo, url: "wss://ws.xtb.com", user: "<<USER_ID>>", password: "<<PASSWORD>>"}
params = [
connection: %{
app_name: "XtbClient",
type: :demo,
url: "wss://ws.xtb.com",
user: "<<USER_ID>>",
password: "<<PASSWORD>>"}
]

{:ok, pid} = XtbClient.Connection.start_link(params)
```
Expand All @@ -34,7 +41,14 @@ params = %{app_name: "XtbClient", type: :demo, url: "wss://ws.xtb.com", user: "<
```elixir
Code.require_file("./examples/stream_listener.ex")

params = %{app_name: "XtbClient", type: :demo, url: "wss://ws.xtb.com", user: "<<USER_ID>>", password: "<<PASSWORD>>"}
params = [
connection: %{
app_name: "XtbClient",
type: :demo,
url: "wss://ws.xtb.com",
user: "<<USER_ID>>",
password: "<<PASSWORD>>"}
]
{:ok, cpid} = XtbClient.Connection.start_link(params)

args = %{symbol: "LITECOIN"}
Expand Down Expand Up @@ -81,7 +95,14 @@ Listener handle info: {:ok,
```elixir
Code.require_file("./examples/stream_listener.ex")

params = %{app_name: "XtbClient", type: :demo, url: "wss://ws.xtb.com", user: "<<USER_ID>>", password: "<<PASSWORD>>"}
params = [
connection: %{
app_name: "XtbClient",
type: :demo,
url: "wss://ws.xtb.com",
user: "<<USER_ID>>",
password: "<<PASSWORD>>"}
]
{:ok, cpid} = XtbClient.Connection.start_link(params)

args = "LITECOIN"
Expand Down
24 changes: 9 additions & 15 deletions lib/xtb_client/account_type.ex
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
defmodule XtbClient.AccountType do
@moduledoc """
Atoms representing type of account.
Helper module for handling with type of account.
"""

@type t :: :demo | :real

@doc """
Format an atom representing main type of the account to string.
"""
@spec format_main(t()) :: binary()
def format_main(account_type) when is_atom(account_type) do
case account_type do
:demo -> "demo"
:real -> "real"
end
end
@spec format_main(t()) :: String.t()
def format_main(:demo), do: "demo"
def format_main(:real), do: "real"
def format_main(other), do: raise("Unknown account type: #{inspect(other)}")

@doc """
Format and atom representing streaming type of the account to string.
"""
@spec format_streaming(t()) :: binary()
def format_streaming(account_type) when is_atom(account_type) do
case account_type do
:demo -> "demoStream"
:real -> "realStream"
end
end
@spec format_streaming(t()) :: String.t()
def format_streaming(:demo), do: "demoStream"
def format_streaming(:real), do: "realStream"
def format_streaming(other), do: raise("Unknown account type: #{inspect(other)}")
end
Loading

0 comments on commit 2ccb05f

Please sign in to comment.