Skip to content

Commit

Permalink
add FetchDailyCandles sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Mar 5, 2024
1 parent a11329b commit 18120e3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@
6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = PrintQuoteEvents.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfile.swift; sourceTree = "<group>"; };
64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileReader.swift; sourceTree = "<group>"; };
644551C92B973A0D0069E3A2 /* FetchDailyCandles.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = FetchDailyCandles.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
6447A5DA2A8E559000739CCF /* ILastingEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ILastingEvent.swift; sourceTree = "<group>"; };
6447A5DC2A8E56CF00739CCF /* ITimeSeriesEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ITimeSeriesEvent.swift; sourceTree = "<group>"; };
6447A5DE2A8E56FC00739CCF /* IIndexedEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IIndexedEvent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1059,6 +1060,7 @@
640885C62B1F657300E6CF88 /* ScheduleSample.playground */,
641C64AE2B344E770023CFAD /* PublishProfiles.playground */,
64F9C6C12B4BFD8F003ED014 /* DXFeedconnect.playground */,
644551C92B973A0D0069E3A2 /* FetchDailyCandles.playground */,
);
path = Playgrounds;
sourceTree = "<group>";
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ is a simple demonstration of how to get live updates for Instrument Profiles
- [ ] DxFeedPublishProfiles is a simple demonstration of how to publish market events
- [x] [ScheduleSample](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/ScheduleSample.playground/Contents.swift)
is a simple demonstration of how to get various scheduling information for instruments
- [x] [FetchDailyCandles](https://github.com/dxFeed/dxfeed-graal-swift-api/blob/swift/Samples/Playgrounds/FetchDailyCandles.playground/Contents.swift) is a simple demonstration of how to fetch last N-days of candles for a specified symbol

## Current State

Expand Down
26 changes: 26 additions & 0 deletions Samples/Playgrounds/FetchDailyCandles.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Cocoa
import DXFeedFramework

/// Fetches last N days of candles for a specified symbol, prints them, and exits.

// await couldn't use directly in Playground(this is accompanied by errors like: execution stopped with unexpected state)
Task {
let baseSymbol = "AAPL{=d}"
var to: Long = Long(Date.now.timeIntervalSince1970 * 1000)
let from: Long = Long(Calendar.current.date(byAdding: .day, value: -20, to: Date())!.timeIntervalSince1970 * 1000)
let endpoint = try DXEndpoint.getInstance().connect("demo.dxfeed.com:7300")
let feed = endpoint.getFeed()
guard let task = feed?.getTimeSeries(type: Candle.self, symbol: baseSymbol, fromTime: from, toTime: to) else {
print("Async task is nil")
exit(0)
}
let result = await task.result
switch result {
case .success(let value):
value?.forEach({ event in
print(event)
})
case .failure(let error):
print(error)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

0 comments on commit 18120e3

Please sign in to comment.