Update README.md
The Swift implementation for Fugle Realtime API client.
Add fugle-realtime-swift as a dependency for your Package.swift file:
fugle-realtime-swift
Package.swift
dependencies: [ .package(url: "https://github.com/KeanuPang/fugle-realtime-swift.git", .upToNextMajor(from: "0.1.1")) ]
Add dependency for you target in Package.swift:
dependencies: [ .product(name: "FugleRealtime", package: "fugle-realtime-swift") ]
Query Intraday meta data by symbol 2884 via HTTP:
2884
import FugleRealtime do { if let result = try await client.getIntraday(MetaData.self, symbol: "2884") { print("\(result.toJSONString(prettyPrint: true) ?? "")") if let metaData = result.meta { print("name: \(metaData.nameZhTw ?? "")") print("priceReference: \(metaData.priceReference?.stringValue ?? "")") /// will print: /// name: 玉山金 /// priceReference: 29.6 } } client.shutdownWS() } catch {}
Subscribe Intraday quote data by symbol 2884 realtime via Websocket:
import FugleRealtime var promise: EventLoopPromise<Void>? // Prepare your callback function for quote data let quoteDataCallback: ((Result<QuoteData, ClientError>) -> Void) = { switch $0 { case .success(let result): print("\(result.quote?.priceAvg?.price?.stringValue ?? ""), \(result.quote?.priceAvg?.at ?? "")") case .failure(let failures): promise?.fail(failures) } } // connect and subscribe intraday websocket endpoint do { promise = try await client.streamIntraday(QuoteData.self, symbol: "2884", callback: quoteDataCallback) try promise?.futureResult.wait() } catch { client.shutdownWS() }
Pass your API token to FugleClient:
FugleClient
let token = "demo" let client = FugleClient = FugleClient.initWithApiToken(demo)
Or you can put .env file into working folder that contains the following enviroment variables declaration:
.env
FUGLE_API_TOKEN=demo
Now your could use FugleClient directly without passing token parameter:
let client = FugleClient.shared
Calling intraday resource via HTTP endpoint, just pass the Mapped data class to getIntraday() function:
Mapped
getIntraday()
let response: MetaData? = try await client.getIntraday(MetaData.self, symbol: "2884")
If you would like to get dealts data with paging via HTTP endpoint, you can call getIntradayDealts() function:
getIntradayDealts()
let response: DealtsData? = try await client.getIntradayDealts(symbol: "2884", pagingLimit: 10)
For historical stock data, just call getMarketData() function:
getMarketData()
let response: CandleData? = try await client.getMarketData(symbol: "2884", from: "2022-04-25", to: "2022-04-29")
If you hit any issues while using this SDK, please bug reports on GitHub issue.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
fugle-realtime-swift
The Swift implementation for Fugle Realtime API client.
Installation
Add
fugle-realtime-swift
as a dependency for yourPackage.swift
file:Add dependency for you target in
Package.swift
:Quick demo
Query Intraday meta data by symbol
2884
via HTTP:Subscribe Intraday quote data by symbol
2884
realtime via Websocket:Usage
Pass your API token to
FugleClient
:Or you can put
.env
file into working folder that contains the following enviroment variables declaration:Now your could use FugleClient directly without passing token parameter:
Calling intraday resource via HTTP endpoint, just pass the
Mapped
data class togetIntraday()
function:If you would like to get dealts data with paging via HTTP endpoint, you can call
getIntradayDealts()
function:Intraday Resource:
For historical stock data, just call
getMarketData()
function:Marketdata Resource:
Bug Report
If you hit any issues while using this SDK, please bug reports on GitHub issue.