Kraken Futures WebSocket API
The listed functions and data types allow to access to public and private (authenticated) websocket feeds.
FuturesWebSocketClient
KrakenEx.FuturesWebSocketModule.FuturesWebSocketClient
— TypeFuturesWebSocketClient
Type that stores information about the client and can be used to establish public and private websocket connections for Kraken Futures trading.
Fields
key
– Kraken Futures API keysecret
– Kraken Futures Secret keycancel_public_connection
– can be set disable the active public websocket connectioncancel_private_connection
– can be set to disable the active private websocket connection
The following will be managed by the connection:
new_challenge
– newest signed messagelast_challenge
– last signed messagechallenge_ready
– is set if the challenge is signedurl
– default websocket url for Kraken Futuresactive_subscriptions
– List of active subscribed feedspending_subscriptions
– List of pending subscribtionspublic_ws
– Public connected websocket instanceprivate_ws
– Private connected websocket instanceavailable_public_feeds
– List of all public feedsavailable_private_feeds
– List of all private feeds
Exampless
FuturesWebSocketClient()
– default, public clientFuturesWebSocketClient("the-api-key", "the-api-secret-key")
– authenticated client for public and private requests
WebSocket utilities
KrakenEx.FuturesWebSocketModule.connect
— Methodconnect(
client::FuturesWebSocketClient;
callback::Core.Function,
public::Bool=true,
private::Bool=false
)
Can create up to two (one private and one public) websocket connections. The public and/or private websocket object will be stored within the FuturesWebSocketClient
. Websocket feeds can be subscribed and unsubscribed after a successful connection. This function must be invoked using @async
. Private websocket connections and privat feed subscriptions requre valid API keys on the passed FuturesWebSocketClient
object.
Attributes
client::FuturesWebSocketClient
– theFuturesWebSocketClient
instancecallback::Core.Function
– Callback function wich receives the websocket messagespublic::Bool=true
– switch to activate/deactivate the public websocket connectionprivate::Bool=false
– switch to activate/deactivate the private websocket connection
Examples
julia> # ws_client = FuturesWebSocketClient() # unauthenticated
julia> ws_client = FuturesWebSocketClient("api-key", "secret-key") # authenticated
julia> on_message(msg::Union{Dict{String,Any},String}) = println(msg)
julia> con = @async connect(ws_client, callback=on_message)
julia> subscribe(client=ws_client, feed="ticker", products=["PI_XBTUSD", "PF_SOLUSD"]) # public feeds
julia> subscribe(client=ws_client, feed="open_orders") # private feed
julia> wait(conn)
KrakenEx.FuturesWebSocketModule.subscribe
— Methodsubscribe(;
client::FuturesWebSocketClient,
feed::String,
products::Union{Vector{String},Nothing}=nothing
)
Subscribe to a websocket feed.
Examples
julia> # ws_client = FuturesWebSocketClient() # unauthenticated
julia> ws_client = FuturesWebSocketClient("api-key", "secret-key") # authenticated
julia> on_message(msg::Union{Dict{String,Any},String}) = println(msg)
julia> con = @async connect(ws_client, callback=on_message)
julia> subscribe(client=ws_client, feed="ticker", products=["PI_XBTUSD", "PF_SOLUSD"]) # public feeds
julia> subscribe(client=ws_client, feed="open_orders") # private feed
julia> wait(conn)
KrakenEx.FuturesWebSocketModule.unsubscribe
— Methodunsubscribe(;
client::FuturesWebSocketClient,
feed::String,
products::Union{Vector{String},Nothing}=nothing
)
Unsubscribe from a subscribed feed.
Examples
julia> # ws_client = FuturesWebSocketClient() # unauthenticated
julia> ws_client = FuturesWebSocketClient("api-key", "secret-key") # authenticated
julia> on_message(msg::Union{Dict{String,Any},String}) = println(msg)
julia> con = @async connect(ws_client, callback=on_message)
julia> unsubscribe(client=ws_client, feed="ticker", products=["PI_XBTUSD", "PF_SOLUSD"]) # public feeds
julia> unsubscribe(client=ws_client, feed="open_orders") # private feed
julia> wait(conn)