putAuthorized function
Future<Response>
putAuthorized(
- String endpoint, {
- String? body,
- Client? client,
- required Credential credential,
- bool isSandbox = false,
Makes an authorized PUT request to the Coinbase Advanced Trade API.
This function generates a JWT, and then makes a PUT request to the specified endpoint with the JWT in the Authorization header.
endpoint - The API endpoint to make the request to.
body - The body of the request.
client - Optional http.Client to use for the request.
credential - The user's API credentials.
isSandbox - Whether to use the sandbox environment.
Returns an http.Response object.
Implementation
Future<http.Response> putAuthorized(String endpoint,
{String? body,
http.Client? client,
required Credential credential,
bool isSandbox = false}) async {
String coinbaseApi = isSandbox ? coinbaseApiSandbox : coinbaseApiProduction;
client ??= http.Client();
String fullEndpoint = '/api/v3/brokerage$endpoint';
String jwtToken = await generateCoinbaseJwt(credential.apiKeyName,
credential.privateKeyPEM, "PUT $coinbaseApi$fullEndpoint");
var url = Uri.https(coinbaseApi, fullEndpoint);
Map<String, String> requestHeaders = {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.acceptHeader: 'application/json',
"Authorization": "Bearer $jwtToken",
};
return await client.put(url, headers: requestHeaders, body: body);
}