Cinderella-Man / hands-on-elixir-and-otp-cryptocurrency-trading-bot-source-code

Resources related to the "Hands-on Elixir & OTP: Cryptocurrency trading bot" book
https://elixircryptobot.com
75 stars 24 forks source link

WebSockex timeout error #21

Closed sundevilyang closed 1 year ago

sundevilyang commented 2 years ago
Streamer.start_streaming("xrpusdt")
{:error, %WebSockex.ConnError{original: :timeout}}

is there anyone have websockex ConnError timeout error ?

sundevilyang commented 2 years ago

more info

iex(1)> Process.whereis BinanceMock
#PID<0.449.0>
iex(2)> Streamer.start_streaming("xrpusdt")
{:error, %WebSockex.ConnError{original: :timeout}}
iex(3)> Naive.Trader.start_link(
...(3)> %{symbol: "XRPUSDT", profit_interval: "-0.001"}
...(3)> )

23:23:33.971 [info]  Initializing new trader for XRPUSDT
** (EXIT from #PID<0.454.0>) shell process exited with reason: an exception was raised:
    ** (BadMapError) expected a map, got: {:http_error, %HTTPoison.Error{id: nil, reason: :timeout}}
        (elixir 1.13.2) lib/map.ex:464: Map.get({:http_error, %HTTPoison.Error{id: nil, reason: :timeout}}, :symbols, nil)
        (naive 0.1.0) lib/naive/trader.ex:49: Naive.Trader.fetch_tick_size/1
        (naive 0.1.0) lib/naive/trader.ex:35: Naive.Trader.init/1
        (stdlib 3.17.1) gen_server.erl:423: :gen_server.init_it/2
        (stdlib 3.17.1) gen_server.erl:390: :gen_server.init_it/6
        (stdlib 3.17.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Interactive Elixir (1.13.2) - press Ctrl+C to exit (type h() ENTER for help)
Cinderella-Man commented 2 years ago

Hello :wave:

Thank you for reporting. Would you be able to share which branch are you using?

sundevilyang commented 2 years ago
 ==> binance
Compiling 17 files (.ex)
warning: :crypto.hmac/3 is undefined or private, use crypto:mac/4 instead
Invalid call found at 2 locations:
  lib/binance/rest/http_client.ex:53: Binance.Rest.HTTPClient.prepare_request/4
  lib/binance/rest/http_client.ex:71: Binance.Rest.HTTPClient.signed_request_binance/3

Generated binance app

00:53:20.827 [info] Starting new supervision tree to trade on XRPUSDT {:ok, #PID<0.1276.0>} iex(2)> 00:53:28.867 [error] GenServer :"Elixir.Naive.Leader-XRPUSDT" terminating ** (BadMapError) expected a map, got: {:http_error, %HTTPoison.Error{id: nil, reason: :timeout}} (elixir 1.10.0) lib/map.ex:452: Map.get({:http_error, %HTTPoison.Error{id: nil, reason: :timeout}}, :symbols, nil) (naive 0.1.0) lib/naive/leader.ex:139: Naive.Leader.fetch_tick_size/1 (naive 0.1.0) lib/naive/leader.ex:125: Naive.Leader.fetch_symbol_settings/1 (naive 0.1.0) lib/naive/leader.ex:45: Naive.Leader.handle_continue/2 (stdlib 3.12.1.2) gen_server.erl:637: :gen_server.try_dispatch/4 (stdlib 3.12.1.2) gen_server.erl:388: :gen_server.loop/7 (stdlib 3.12.1.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3 Last message: {:continue, :start_traders}

Cinderella-Man commented 2 years ago

Hello,

Thanks for more info - I wonder, maybe your network is somehow blocking the WebSocket port - could you please give it a try without specifying the port inside the Streamer.Binance module:

-  @stream_endpoint "wss://stream.binance.com:9443/ws/"
+  @stream_endpoint "wss://stream.binance.com/ws/"

I checked, and it works for me with and without specifying the port, so maybe it will help :thinking: :shrug:

Cinderella-Man commented 2 years ago

I just realised that you couldn't even fetch the exchange info from the Binance API (a RESTful API at 443[I guess]). Can you actually reach Binance?

Could you give it a try through your browser?

https://api.binance.com/api/v3/exchangeInfo or US based API: https://api.binance.us/api/v3/exchangeInfo

Does any of those work for you?

sundevilyang commented 2 years ago

image I can reach the API through the browser.

sundevilyang commented 2 years ago

Hello,

Thanks for more info - I wonder, maybe your network is somehow blocking the WebSocket port - could you please give it a try without specifying the port inside the Streamer.Binance module:

-  @stream_endpoint "wss://stream.binance.com:9443/ws/"
+  @stream_endpoint "wss://stream.binance.com/ws/"

I checked, and it works for me with and without specifying the port, so maybe it will help 🤔 🤷

Much thanks to you for helping me.

It still shows the error {:error, %WebSockex.ConnError{original: :timeout}} without specifying the port

image

I am using v2ray to visit binance.com, the v2ray server is located in Hongkong.

sundevilyang commented 2 years ago

my v2ray server port is 443, I guess it may be the cause. let me figure it out and then let you know the result.