Skip to content

Commit

Permalink
Add "request private token" interface
Browse files Browse the repository at this point in the history
  • Loading branch information
backslash-f committed Dec 26, 2023
1 parent b8c24da commit b71c300
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Sources/SwiftTrader/SwiftTrader+KucoinSpot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,32 @@ public extension SwiftTrader {
return .failure(swiftTraderError)
}
}

// MARK: - WebSocket

/// Requests an authorized token for subscribing to private channels and messages via WebSocket.
///
/// https://www.kucoin.com/docs/websocket/basic-info/apply-connect-token/private-channels-authentication-request-required-
///
/// - Returns: An instance of `KucoinWebSocketPrivateTokenResponse` or `SwiftTraderError`.
@discardableResult func kucoinSpotWebSocketRequestPrivateToken() async throws
-> Result<KucoinWebSocketPrivateTokenResponse, SwiftTraderError> {
guard let auth = kucoinAuth else {
return .failure(.kucoinMissingAuthentication)
}
let request = KucoinSpotWebSocketBulletPrivateRequest(
kucoinAuth: auth,
settings: settings.networkRequestSettings
)
switch await request.execute() {
case .success(let model):
guard let privateTokenResponse = model as? KucoinWebSocketPrivateTokenResponse else {
return .failure(.unexpectedResponse(modelString: "\(model)"))
}
return .success(privateTokenResponse)
case .failure(let error):
let swiftTraderError = handle(networkRequestError: error, operation: .kucoinSpotWebSocketPrivateToken)
return .failure(swiftTraderError)
}
}
}

0 comments on commit b71c300

Please sign in to comment.