Skip to content

Instantly share code, notes, and snippets.

@Ljzn
Created December 13, 2023 11:42
Show Gist options
  • Save Ljzn/a491111df7826276fe8f40028c6014d8 to your computer and use it in GitHub Desktop.
Save Ljzn/a491111df7826276fe8f40028c6014d8 to your computer and use it in GitHub Desktop.
def okx_signing(config, %{url: url, body: body, method: method}) do
secret = config["okx_secret_key"]
access_key = "your access key"
timestamp = DateTime.utc_now() |> DateTime.truncate(:millisecond) |> DateTime.to_iso8601()
%{path: path, query: query} = URI.new!(url)
data = timestamp <> method <> path <> "?" <> query <> body
sign = :crypto.mac(:hmac, :sha256, secret, data) |> Base.encode64()
[
{"OK-ACCESS-KEY", access_key},
{"OK-ACCESS-TIMESTAMP", timestamp},
{"OK-ACCESS-PASSPHRASE", "your passphrase"},
{"OK-ACCESS-SIGN", sign}
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment