/ Exchanges / src / adhoc / utils.jl
utils.jl
 1  using .Python: pyin
 2  
 3  function resptobool(::Exchange, resp)
 4      if resp isa Exception
 5          @error "exchange: exception" exception = resp @caller
 6          false
 7      elseif applicable(haskey, resp, "code")
 8          if pyisTrue(@py haskey(resp, "code"))
 9              @py resp["code"] in (0, 200, "0", "200")
10          elseif pyisTrue(@py haskey(resp, "msg"))
11              @py "success" in resp["msg"]
12          else
13              @error "no matching key in response (default to false)" resp @caller
14              false
15          end
16      else
17          @error "exchange: unexpected value" resp @caller
18          false
19      end
20  end
21  
22  function resptobool(::Exchange{<:eids(:binance, :binanceusdm, :binancecoin)}, resp)
23      if resp isa Exception
24          @error "exchange: exception" exception = resp @caller
25          false
26      elseif applicable(haskey, resp, "code")
27          if haskey(resp, "code")
28              @py resp["code"] in (0, 200, -4046)
29          elseif haskey(resp, "msg")
30              @py "success" in resp["msg"]
31          else
32              @error "exchange: no matching key in response (default to false)" resp @caller
33              false
34          end
35      else
36          @error "exchange: unexpected value" resp @caller
37          false
38      end
39  end