A library to interface with the Coinbase/CoinbasePro API
- Currently a work in progress.
- I'm using this project to help further my understanding of the C language so there will be many, many changes as I progress, but hopefully there will be something you can take away.
- The src/main.c file is meant as a test implementation.
- If there's anything you want to see added, please let me know!
- cJSON - To format and parse the output.
To compile without installing:
git clone https://github.com/cjhead/cbpro.git
cd cbpro
make
To install:
git clone https://github.com/cjhead/cbpro.git
cd cbpro
sudo make install
To create and run a couple simple test programs:
- Note: You may need to modify LD_LIBRARY_PATH
make test
test/bin/get_all_products
test/bin/get_product
test/bin/get_product_book
test/bin/get_product_candles
test/bin/get_product_stats
sudo make uninstall
- The files in test/src/ can be used as simple templates
- When compiling your own programs, you'll need to use these flags:
-lcbpro -lcurl
To begin, create a Client:
#include <cbpro.h>
int main(void) {
struct Client *client = client_create();
}
Not every call requires user authentication. To get you started, you can try something like this:
#include <cbpro.h>
int main(void) {
// Create the client
struct Client *client = client_create();
// Get all available currencies
get_all_products(client);
// Print results to stdout
printf("%s\n", client->data->buffer);
// Cleanup
client_cleanup(client);
curl_global_cleanup();
return EXIT_SUCCESS;
}
Some API calls will require the user to be authenticated. Simply copy your API credentials to a locally saved file that you supply in your code. The file should look like this:
secret_key ****************
api_key *************
passphrase *********
-
NOTE: This is most likely not very secure.
-
You should then be able to use the functions requiring authentication.
#include <cbpro.h>
int main(void) {
// Create the client
struct Client *client = client_create();
// Authenticate the client
const char *cred_file = "creds.txt";
FILE *fh = fopen(cred_file, "r");
authorize_client(fh, client);
authorize_client(cred_file, client);
// Get all accounts belonging to the user
get_accounts(client);
// Print results to stdout
printf("%s\n", client->data->buffer);
// Cleanup
client_cleanup(client);
curl_global_cleanup();
return EXIT_SUCCESS;
}
- For the functions that require authorization, you'll need to put your credentials in a text file with a format like to this:
secret_key ****************
api_key *************
passphrase *********