-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageStruct.swift
More file actions
103 lines (91 loc) · 2.44 KB
/
Copy pathMessageStruct.swift
File metadata and controls
103 lines (91 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// MessageStruct.swift
// API_test
//
// Created by nick on 3/15/21.
//
import Foundation
//struct FinnhubMessage: Codable {
// let tradeData: [TradeData]
// let type: String
//
// enum CodingKeys: String, CodingKey {
// case tradeData
// case type
// }
//
// init(from decoder: Decoder) throws {
// let container = try decoder.container(keyedBy: CodingKeys.self)
//
// self.type = try container.decode(String.self, forKey: .type)
// self.tradeData = try container.decode([TradeData].self, forKey: .tradeData)
// }
//
// func encode(to encoder: Encoder) throws {
// var container = encoder.container(keyedBy: CodingKeys.self)
// try container.encode(type, forKey: .type)
// try container.encode(tradeData, forKey: .tradeData)
// }
//}
struct TradeData: Codable {
let c: [String]
let p: Float
let s: String
let t: Int
let v: Int
}
/*
struct Coordinate {
var latitude: Double
var longitude: Double
var elevation: Double
}
extension Coordinate: Decodable {
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
latitude = try values.decode(Double.self, forKey: .latitude)
longitude = try values.decode(Double.self, forKey: .longitude)
let additionalInfo = try values.nestedContainer(keyedBy: AdditionalInfoKeys.self, forKey: .additionalInfo)
elevation = try additionalInfo.decode(Double.self, forKey: .elevation)
}
}
extension Coordinate: Encodable {
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(latitude, forKey: .latitude)
try container.encode(longitude, forKey: .longitude)
var additionalInfo = container.nestedContainer(keyedBy: AdditionalInfoKeys.self, forKey: .additionalInfo)
try additionalInfo.encode(elevation, forKey: .elevation)
}
}
*/
/*
extension FinnhubMessage: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(self.type)
// hasher.combine(Tr)
}
}
extension TradeData: Hashable
*/
/*
{
"data":[
{
"c":["1","24","12"],
"p":121.38,
"s":"AAPL",
"t":1615809975482,
"v":1
},
{
"c":["1","24","12"],
"p":121.38,
"s":"AAPL",
"t":1615809975482,
"v":1
}
],
"type":"trade"
}
*/