Please thoroughly vet everything in the code for yourself before using this lib to buy, sell, or move any of your assets.
PLEASE submit an issue or pull request if you notice any bugs, security holes, or potential improvements. Any help is appreciated!
This library is a wrapper for the Kraken Digital Asset Trading Platform API. Official documentation from Kraken can be found here.
The current version can be used to query public/private data and make trades. Private data queries and trading functionality require use of your Kraken account API keys.
Kraken Swift was built by Antonio Casero
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Kraken into your Xcode project using Carthage, specify it in your Cartfile
:
github "antoniocasero/Kraken" ~> 1.0
Run carthage update
to build the framework and drag the built Kraken.framework
into your Xcode project.
If you prefer not to use any of the aforementioned dependency managers, you can integrate Kraken into your project manually.
-
Open up Terminal,
cd
into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:$ git init
-
Add Kraken as a git submodule by running the following command:
$ git submodule add https://github.com/antoniocasero/Kraken.git
-
Open the new
Kraken
folder, and drag theKraken.xcodeproj
into the Project Navigator of your application's Xcode project.It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
-
Select the
Kraken.xcodeproj
in the Project Navigator and verify the deployment target matches that of your application target. -
Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
-
In the tab bar at the top of that window, open the "General" panel.
-
Click on the
+
button under the "Embedded Binaries" section. -
Select the top
Kraken.framework
-
And that's it!
The
Kraken.framework
is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
Create a Kraken client using your credentials
let credentials = Kraken.Credentials(key: "0Q/eOVRtyfg+WbIuLjKJ.....",
secret: "EVFTYSinNiC89V.....")
let kraken = Kraken(credentials: credentials)
kraken.serverTime(completion: { let _ = $0.map{ print($0) } } // 1393056191
This functionality is provided by Kraken to to aid in approximating the skew time between the server and client.
kraken.serverTime { result in
switch result {
case .success(let serverTime):
serverTime["unixtime"] // 1393056191
serverTime["rfc1123"] // "Sat, 22 Feb 2014 08:28:04 GMT"
case .failure(let error): print(error)
}
}
Returns the assets that can be traded on the exchange. This method can be passed info
, aclass
(asset class), and asset
options. An example below is given for each:
kraken.assets(completion: { let _ = $0.map{ print($0) } })
kraken.assetsPairs(completion: { let _ = $0.map{ print($0) } })
kraken.ticker(pairs: ["BCHEUR", "BCHUSD"], completion: { let _ = $0.map{ print($0) } })
Get market depth information for given asset pairs
depth_data = kraken.order_book('LTCXRP', completion: { ... })
Get recent trades
trades = kraken.trades('LTCXRP', completion: { ... })
Get spread data for a given asset pair
spread = kraken.spread('LTCXRP', completion: { ... })
Get account balance for each asset Note: Rates used for the floating valuation is the midpoint of the best bid and ask prices
kraken.balance(completion: { ... })
Get account trade balance
kraken.tradeBalance(completion: { ... })
kraken.openOrders(completion: { ... })
kraken.closedOrders(completion: { ... })
See all orders
kraken.queryOrders(completion: { ... })
Get array of all trades
kraken.tradeHistory(completion: { ... })
Input: Array of transaction (tx) ids
kraken.queryTrades(txids:arrayIds completion: { ... })
Input: Array of transaction (tx) ids
kraken.openPositions(txids:arrayIds completion: { ... })
kraken.ledgersInfo(completion: { ... })
Input: Array of ledger ids
kraken.queryTrades(ids: ledgerIds completion: { ... })
let assetPairs = ["XLTCXXDG", "ZEURXXDG"]
kraken.queryTrades(ids: assetPairs completion: { ... })
There are 4 required parameters for buying an order. The example below illustrates the most basic order. Please see the Kraken documentation for the parameters required for more advanced order types.
// buying 0.01 XBT (bitcoin) for XRP (ripple) at market price
let opts = [
"pair": "XBTXRP",
"type": "buy",
"ordertype": "market",
"volume": "0.01"
]
kraken.addOrder(options:opts completion: { ... })
kraken.cancelOrder(ids:["UKIYSP-9VN27-AJWWYC"] completion: { ... })