SwiftFlyer 0.2.2

SwiftFlyer 0.2.2

Ryo Ishikawa 维护。



 
依赖
CryptoSwift~> 0.8.3
Starscream~> 3.0.5
 

  • rinov

SwiftFlyer

bitFlyer API 的封装,支持所有提供的 API。

Swift Platform Cocoapods Carthage License

API 文档

https://lightning.bitflyer.jp/docs

使用方法

公共 API

获取市场列表。

import SwiftFlyer

let request = GetMarketListRequest()

ApiSession.shared.send(request) { result in
    switch result {
    case .success(let markets):
      print(markets)
    case .failed(let e):
      // Error handling
      break
    }
}

响应

[
  SwiftFlyer.Market(productCode: SwiftFlyer.ProductCode.btc_jpy, alias: nil),
  SwiftFlyer.Market(productCode: SwiftFlyer.ProductCode.fx_btc_jpy, alias: nil),
  SwiftFlyer.Market(productCode: SwiftFlyer.ProductCode.eth_btc, alias: nil),
  SwiftFlyer.Market(productCode: SwiftFlyer.ProductCode.bch_btc, alias: nil)
]

私有 API

生成 API 密钥: https://lightning.bitflyer.jp/developer

检查您的余额。

import SwiftFlyer
...

// For access private API.
BitFlyer.apiKey = // Your API Key
BitFlyer.apiSecretKey = // Your API Secret Key

let request = GetBalanceRequest()

ApiSession.shared.send(request) { result in
    switch result {
    case .success(let markets):
      print(markets)
    case .failed(let e):
      // Error handling
      break
    }
}

响应

[
  SwiftFlyer.Balance(amount: 0.0, available: 0.0, currencyCode: SwiftFlyer.CurrencyCode.jpy),
  SwiftFlyer.Balance(amount: 0.0, available: 0.0, currencyCode: SwiftFlyer.CurrencyCode.btc),
  SwiftFlyer.Balance(amount: 0.0, available: 0.0, currencyCode: SwiftFlyer.CurrencyCode.bch),
  SwiftFlyer.Balance(amount: 0.0, available: 0., currencyCode: SwiftFlyer.CurrencyCode.eth),
  SwiftFlyer.Balance(amount: 0.0, available: 0.0, currencyCode: SwiftFlyer.CurrencyCode.etc),
  SwiftFlyer.Balance(amount: 0.0, available: 0.0, currencyCode: SwiftFlyer.CurrencyCode.ltc),
  SwiftFlyer.Balance(amount: 0.0, available: 0.0, currencyCode: SwiftFlyer.CurrencyCode.mona)
]

RealTime API (通过 WebSocket 的 JSON RPC)

在你的项目中使用 RealTimeAPI。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    // If you want retrive realtime information, set channels and call `subscribe` of RealTimeAPI.
    typealias Channel = RealTimeAPI.SubscribeChannel

    // Set channels for subscribing realtime api from bitFlyer RealTimeAPI by using JSON RPC over WebSocket.
    let subscribeChannels: [String] = [
    Channel.SnapShot.boardSnap_fx_btc_jpy.targetChannel,
    Channel.Board.board_fx_btc_jpy.targetChannel,
    Channel.Ticker.ticker_fx_btc_jpy.targetChannel,
    Channel.Execution.execution_fx_btc_jpy.targetChannel
    ]

    // Start observing realtime API.
    RealTimeAPI.shared.subscribe(with: subscribeChannels)

    ...
}

订阅实时 API 后,你应该在你的类中实现 RealTimeAPIDelegate

class ViewController: UIViewController {    

    private let realtime: RealTimeAPI = .shared

    override func viewDidLoad() {
        super.viewDidLoad()

        // Set realtime API delegate for get your setted object.
        realtime.delegate = self
    }
}

extension UIViewController: RealTimeAPIDelegate {
    public func didReceiveSnapShot(_ snapshot: Board) {
        print(snapshot)
    }
    
    public func didReceiveBoardDiff(_ board: Board) {
        print(board)
    }
    
    public func didReceiveTicker(_ ticker: Ticker) {
        print(ticker)
    }
    
    public func didReceiveExecution(_ executions: [Execution]) {
        print(executions)
    }
}

要求

XCode 9+

Swift 4+

安装

$ pod repo update

并将以下内容添加到你的 Podfile 中

pod 'SwiftFlyer'

$ pod install

Carthage

并将以下内容添加到你的 Cartfile 中

github "rinov/SwiftFlyer"

$ carthage update

待办事项

  • 给每个请求和公共设置添加超时。
  • 提供 HMAC 256 算法,而不是 CryptoSwift。
  • 检测 API 调用超出。

免责声明

自行承担使用本软件的风险。

作者不对您的交易结果承担任何责任。

作者

Ryo Ishikawa, [email protected]

许可

SwiftFlyer遵循MIT许可证。有关更多信息,请参阅LICENSE文件。