tbank_invest 0.6.4
tbank_invest: ^0.6.4 copied to clipboard
T-Invest (T-Bank) Invest API: fully typed REST (V1* DTOs), WebSocket (dart:io), OpenAPI codegen, optional hand helpers. Unofficial. Not for Flutter Web.
// ignore_for_file: avoid_print
/// Minimal example: sandbox [GetAccounts] (requires a real sandbox token).
///
/// From package root:
/// `dart run --define=TBANK_TOKEN=t.xxx example/example.dart`
library;
import 'package:tbank_invest/tbank_invest.dart';
Future<void> main() async {
const token = String.fromEnvironment('TBANK_TOKEN', defaultValue: '');
if (token.isEmpty) {
print(
'Set token: dart run --define=TBANK_TOKEN=t.xxx example/example.dart');
return;
}
final client = TinvestClient(
InvestConfig(
token: token,
environment: InvestEnvironment.sandbox,
),
);
try {
final response =
await client.users.getAccounts(const V1GetAccountsRequest());
final accounts = response.accounts ?? <V1Account>[];
print('Accounts: ${accounts.length}');
for (final account in accounts) {
final status = account.status?.name ?? 'n/a';
print('- ${account.id} ${account.name ?? ''} ($status)');
}
} on InvestApiException catch (e) {
print('API error: $e');
} finally {
client.close();
}
}