forked from acorscadden/CoinGecko
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from michaelibrd/feature/candle-support
Adding support for candles (ohlc)
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Candle.swift | ||
// | ||
// | ||
// Created by stringcode on 05/04/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
public typealias CandleList = [Candle] | ||
|
||
public struct Candle: Codable { | ||
public let date: Date | ||
public let open: Double | ||
public let high: Double | ||
public let low: Double | ||
public let close: Double | ||
|
||
public init(arrayData: [Double]) { | ||
date = Date(timeIntervalSince1970: Double(arrayData[0]) / 1000) | ||
open = arrayData[1] | ||
high = arrayData[2] | ||
low = arrayData[3] | ||
close = arrayData[4] | ||
} | ||
|
||
public init(date: Date, open: Double, high: Double, low: Double, close: Double) { | ||
self.date = date | ||
self.open = open | ||
self.high = high | ||
self.low = low | ||
self.close = close | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import XCTest | ||
@testable import CoinGecko | ||
|
||
final class CandleTests: XCTestCase { | ||
|
||
private let client = CoinGeckoClient() | ||
|
||
func testCandles() { | ||
let exp = XCTestExpectation() | ||
let id = "bitcoin" | ||
let vs = "usd" | ||
let candles = Resources.candles(currencyId: id, vs: vs, days: 180) { (result: Result<CandleList, CoinGeckoError>) in | ||
switch result { | ||
case let .success(candleList): | ||
XCTAssertTrue(candleList.count > 44 && candleList.count < 49, | ||
"Unexpected candle count") | ||
case let .failure(error): | ||
XCTFail(error.localizedDescription) | ||
} | ||
exp.fulfill() | ||
} | ||
client.load(candles) | ||
wait(for: [exp], timeout: 10.0) | ||
} | ||
} |