Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return OrderResponse struct from buy & sell limit #14

Merged
merged 4 commits into from
Jun 23, 2018

Conversation

rupurt
Copy link
Collaborator

@rupurt rupurt commented May 25, 2018

Builds upon #13

@dvcrn
Copy link
Owner

dvcrn commented Jun 13, 2018

@rupurt finally had some time to take a closer look. The problem is that you replaced the config for key/secret with System.get_env which will return nil if the env var is not present.

The library needs a string for creating the signature

    signature =
      :crypto.hmac(
        :sha256,
        Application.get_env(:binance, :secret_key),    # <------ here 
        argument_string
      )
      |> Base.encode16()

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 13, 2018

Gotcha. How do you think I should go about testing that? Are you ok with this approach with the environment variables?

@dvcrn
Copy link
Owner

dvcrn commented Jun 13, 2018

Remove the System.get_env parts for now. Having "" as default is sane and the user can always override it in his own config later on.

Also mix test runs on MIX_ENV=test. Since the exvcr stuff is only needed for tests, could you move that into a separate config_test.ex file and load that when in test?

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 13, 2018

@dvcrn I believe the config/config.exs file is restricted to the project and won't get loaded. So projects that use the binance package won't get any exvcr config.

@dvcrn
Copy link
Owner

dvcrn commented Jun 17, 2018

Ah yeah, good point! But yeah, in either way, the System.get_env stuff isn't needed inside this project I think. If a project wants to handle the credentials like this, they can just overwrite it in their config.

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 17, 2018

@dvcrn updated with the empty strings. It looks like it's still failing with the same problem :{

@dvcrn
Copy link
Owner

dvcrn commented Jun 18, 2018

Now it's failing at a different problem though

  6) test .order_limit_buy can create an order with am immediate or cancel duration (BinanceTest)
     test/binance_test.exs:130
     ** (ArgumentError) argument error
     code: Binance.order_limit_buy("LTCBTC", 0.1, 0.01, "IOC")
     stacktrace:
       (kernel) :os.system_time(:millisecond) # <--------
       (binance) lib/binance.ex:269: Binance.create_order/11
       (binance) lib/binance.ex:336: Binance.order_limit_buy/4
       test/binance_test.exs:133: (test)

Not quite sure why this happens. I'll take a closer look later!

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 18, 2018

@dvcrn that's the same error I've been seeing on CI. Do you mind trying with an upgraded Erlang/Elixir?

@dvcrn
Copy link
Owner

dvcrn commented Jun 18, 2018

I added OTP 20 to the travis build matrix. If you rebase master and push, it should matrix build it against 1.5, 1.6, OTP 19 and OTP 20.

@rupurt rupurt force-pushed the limit-order-test-coverage branch from 82cd710 to b72dbcb Compare June 18, 2018 01:08
@rupurt
Copy link
Collaborator Author

rupurt commented Jun 18, 2018

Thanks @dvcrn. Looks like that did the trick :)

@dvcrn
Copy link
Owner

dvcrn commented Jun 18, 2018

Now the question is why it breaks on OTP 19, and why it didn't before this PR since this doesn't seem to touch any system / time stuff...

lib/binance.ex Outdated
@@ -400,6 +402,40 @@ defmodule Binance do
create_order(symbol, "SELL", "MARKET", quantity)
end

defp parse_order_response({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just want to parse a map into a struct, you can use exconstructor which is already a dep of this project

Add use ExConstructor to your struct (like here

Then use .New() to parse (like here)

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 18, 2018

@dvcrn it was untested code. OTP 19 is now a couple of years old and OTP 21 is in rc2.

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 19, 2018

@dvcrn cool pattern with ExConstructor. I've just pushed up the requested changes.

@dvcrn
Copy link
Owner

dvcrn commented Jun 22, 2018

Looking good, thanks for the fast updates!
I'll change the CI target later so the tests pass and will merge after that.

@rupurt
Copy link
Collaborator Author

rupurt commented Jun 22, 2018

😎

Fwiw OTP 21 got released this week so I added it to the travis config #16

@dvcrn dvcrn merged commit 8d1be91 into dvcrn:master Jun 23, 2018
@rupurt rupurt deleted the limit-order-test-coverage branch July 14, 2018 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants