Skip to content

An library for the coinbase exhange api written in dart

License

Notifications You must be signed in to change notification settings

pcrady/coinbase_exchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coinbase_exchange

An unofficial sdk for the coinbase cloud exchange.

Gif

Getting Started

This project is a Dart sdk the coinbase exchange api. This sdk allows for the retrieval of real time pricing data using the coinbase websocket feed and information about individual profiles on coinbase and coinbase pro. It also allows for the trading of cryptocurrencies on the coinbase pro platform. This package uses api keys which must be generated from coinbase pro or the coinbase pro sandbox.

To test to make sure you have generated your keys correctly, create a file test/secrets.dart with the contents:

class Secrets {
  static const String apiKey = '';
  static const String secretKey = '';
  static const String passphrase = '';
}

Put in your apiKey, secretKey and passphrase. In the coinbase_exchange_test.dart file. Then run:

pub run test --chain-stack-traces test/coinbase_exchange_test.dart

This will by default execute the tests in the coinbase pro sandbox so make sure you have used the appropriate keys. The tests are currently incomplete and only test Accounts, Coinbase Accounts, Conversions and Currencies.

Websocket Feed

// Make sure to import the package as something so you dont polute your environment.
import 'package:coinbase_exchange/coinbase_exchange.dart' as cb;

cb.WebsocketClient wsClient = cb.WebsocketClient(sandbox: false);

var stream = wsClient.subscribe(
  productIds: ['BTC-USD'],
  channels: [
    cb.ChannelEnum.heartBeat,
  ],
);

// The first event is always a subscriptions event which tells you which channels you 
// have subscribed to. After the first event it is up to you to manually sort events 
// from the stream.
stream.listen((event) {
  print(event.toJson().toString());
  wsClient.close();
});

API

// Make sure to import the package as something so you dont polute your environment.
import 'package:coinbase_exchange/coinbase_exchange.dart' as cb;

var accounts = await cb.accountsClient.listAccounts();

for (cb.Account account in accounts) {
  print(account.currency);
}

About

An library for the coinbase exhange api written in dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages