Behaviour for signing pattern implementations.
Any module implementing sign/3 can be used as a signing pattern.
Built-in patterns are dispatched via CCXT.Signing.sign/4. Custom
modules are wired via CCXT.Signing.Custom.
Implementing a Custom Pattern
defmodule MyApp.Signing.MyExchange do
@behaviour CCXT.Signing.Behaviour
@impl true
def sign(request, credentials, config) do
timestamp = CCXT.Signing.timestamp_ms()
signature = CCXT.Signing.hmac_sha256(
request.path <> to_string(timestamp),
credentials.secret
)
%{
url: request.path,
method: request.method,
headers: [
{"X-API-KEY", credentials.api_key},
{"X-TIMESTAMP", to_string(timestamp)},
{"X-SIGNATURE", CCXT.Signing.encode_hex(signature)}
],
body: request.body
}
end
endAvailable Helpers
CCXT.Signing provides crypto and encoding helpers:
timestamp_ms/0, hmac_sha256/2, hmac_sha384/2, hmac_sha512/2,
sha256/1, sha512/1, encode_hex/1, encode_base64/1,
decode_base64/1, urlencode/1, urlencode_raw/1.
Summary
Callbacks
Signs a request using the pattern's authentication method.
Callbacks
@callback sign( request :: CCXT.Signing.request(), credentials :: CCXT.Credentials.t(), config :: CCXT.Signing.config() ) :: CCXT.Signing.signed_request()
Signs a request using the pattern's authentication method.
Parameters
request- Map with:method,:path,:body, and:paramscredentials-CCXT.Credentialsstruct with API key and secretconfig- Pattern-specific configuration from the exchange spec
Returns
A signed request map with :url, :method, :headers, and :body.