Swiftpack.co - Package - Insanely9/swift-bitbankcc

swift-bitbankcc

Carthage compatible MIT License

Description

UNOFFICIAL swift library for bitbank.cc, Bitcoin exchange.

https://bitbank.cc/

API document: https://docs.bitbank.cc/

Install

Carthage

Cartfile:

github "Insanely9/swift-bitbankcc"

How to use

Public API

import Bitbankcc

let bb = Bitbankcc()

bb.getTicker(.BTC_JPY) { error, ticker in
    guard let ticker = ticker else { return }
    print(ticker)
}

bb.getDepth(.BTC_JPY) { error, depth in
    guard let depth = depth else { return }
    print(depth)
}

bb.getTransaction(.BTC_JPY) { error, transaction in
    guard let transaction = transaction else { return }
    print(transaction)
} 

bb.getTransactions(.BTC_JPY, date: "20170410") { error, transactions in
    guard let transactions = transactions else { return }
    print(transactions)
}

bb.getCandlestick(.BTC_JPY, type: ._1DAY, date: "2017") { error, candlesticks in
    guard let candlesticks = candlesticks else { return }
    print(candlesticks)
}

Private API

Private api requires API_KEY and API_SECRET. https://bitbank.cc/account/api

let bb = Bitbankcc(key: "YOUR_API_KEY", secret: "YOUR_API_SECRET")

Assets

bb.getAssets { error, assets in
    guard let assets = assets else { return }
    print(assets)
}

Order/Orders Info

bb.getOrder(.BTC_JPY, order_id: "90956209") { error, order in
    guard let order = order else { return }
    print(order)
}

bb.getOrders(.BTC_JPY, order_ids: [90956209, 90951996]) { error, orders in
    guard let orders = orders else { return }
    print(orders)
}

Send New Order

bb.sendOrder(.BTC_JPY, amount: 1000, price: 0.01, side: .BUY, type: .LIMIT) { error, orders in
    guard let orders = orders else { return }
    print(orders)
}

Cancel Order/Orders

bb.cancelOrder(.BTC_JPY, order_id: 129781978) { error, order in
    guard let order = order else { return }
    print(order)
}

bb.cancelOrders(.BTC_JPY, order_id: [129830841, 129830734]) { error, orders in
    guard let orders = orders else { return }
    print(orders)
}

Active Orders

Option's parameter can be seen in document page

bb.getActiveOrders(.BTC_JPY, count: 1, since: 1490348550380) { error, orders in
    guard let orders = orders else { return }
    print(orders)
}

Withdrawal Account Info

bb.getWithdrawalAccount(.BTC) { error, accounts in
    guard let accounts = accounts else { return }
    print(accounts)
}

Request Withdraw

You should set "otpToken" or "smsToken".

bb.requestWithdrawal(.BTC, uuid: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX", amount: "0.005", otp_token: "867005", sms_token: "") { error, withdrawal in
    guard let withdrawal = withdrawal else { return }
    print(withdrawal)
}

Error Handling

Bitbankcc().getTicker(.BTC_JPY) { error, ticker in

    // there is an error if error object is not nil
    if let error = error {
        switch error {
        case .networkError(let statusCode, let errorCode, let desc):
            print("networkError statusCode = \(statusCode) errorCode = \(errorCode) desc = \(desc)")
        case .bitbankError(let code, let desc):
            print("bitbankError code = \(code) desc = \(desc)")
        case .otherError(let desc):
            print("otherError desc = \(desc)")
        }
        return
    }

    ...
}

Option

Make request sync

let bb = Bitbankcc()
bb.isSync = true

Licence

MIT

TODO

  • [ ] Support Objective-C
  • [ ] Support Cocoapods
  • [ ] Support Swift Package Manager

Your contributions always welcome :)

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

v1.0.0 - Jul 24, 2018