Rewrite all REST v3 examples: correct signing, pinned Docker, standardized docs#44
Open
bsoares wants to merge 1 commit into
Open
Rewrite all REST v3 examples: correct signing, pinned Docker, standardized docs#44bsoares wants to merge 1 commit into
bsoares wants to merge 1 commit into
Conversation
Rewrites every REST v3 sample so an integrating developer gets correct, idiomatic, copy-pasteable code with a request-signing implementation that holds for all request shapes (no body, query params, JSON body). Signing (root cause of the previous breakage): - The prehash uses the query string DECODED (raw values); the URL sends it percent-encoded (RFC 3986, space=%20). Both are built from one ordered param structure so the signed and sent strings can never diverge. This was validated empirically against the live API — signing the encoded form 401s. - The JSON body is serialized exactly once; the same string is signed and sent on the wire (Python uses data=, not json=; axios/requests no longer re-serialize). Signing one formatting and sending another 401s. - Timestamp in milliseconds; success is any 2xx (order creation returns 201). Correctness/robustness fixes applied across all examples: - Dynamic price = 50% of the best bid from the public order book. The old hardcoded 10.0 BRL is now rejected by the API price band (HTTP 422). - Demonstrate the public (unauthenticated) order book endpoint. - Fail fast with a clear message when credentials are missing. - Never print the API key/secret. - Non-2xx responses print status + body and exit non-zero. Dependencies minimized (stdlib where possible): JS/TS now zero-dependency (native fetch + node:crypto), Ruby/PHP stdlib-only (Gemfile/composer removed), Go stdlib and modernized. Remaining deps pinned to exact versions. Docker: every example ships a Dockerfile pinned to a full base-image version (no latest/floating tags), multi-stage for compiled languages. READMEs standardized in English (flow, credentials, Docker run, and how the signing works, including the two gotchas). Root and rest-v3 READMEs updated; WebSocket v3 listed. Verified: all 14 examples build under Docker and complete the full flow (me -> order book -> create order -> list active -> cancel) against the live API with exit 0; signing test vectors pass for every language. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every REST v3 example (12 languages + 2 official-SDK examples) was rewritten so an integrating developer gets correct, idiomatic, copy-pasteable code. The focus was the request-signing logic, which previously broke as soon as a request carried encoded query params or a JSON body.
The signing fix (root cause)
The prehash is
timestamp + method + path + queryString + rawBody. Two mistakes were present in every example and are now fixed everywhere — both validated empirically against the live API:%20never+, for the URL) from the same ordered param structure, so the signed and sent strings can never diverge.data=, notjson=; axios/requests no longer re-serialize).Correctness & robustness (all examples)
10.0BRL is now rejected by the API price band (HTTP 422), so the examples simply didn't work.idfrom the create step is used for the cancel step.Dependencies & Docker
fetch+node:crypto), Ruby/PHP stdlib-only (Gemfile/composer removed), Go stdlib and modernized. Remaining deps pinned to exact versions.Dockerfilepinned to a full base-image version (nolatest/floating tags), multi-stage for compiled languages.Docs
READMEs standardized in English (flow, credentials, Docker run, and a "how signing works" section covering the two gotchas). Root and
rest-v3READMEs updated; WebSocket v3 now listed.Verification
All 14 examples were built under Docker and run end-to-end against the live API (
/me→ order book → create order → list active → cancel) with exit 0. The order is a real LIMIT BUY placed ~50% below market and cancelled by the example itself. Per-language signing test vectors (including the RFC 3986 encoding edge cases) pass for every language.🤖 Generated with Claude Code