Skip to main content

A simple library for Coinbase Pro

Project description

Koin

A simple library for interacting with the Coinbase Pro API.

It was born out of the need to programmatically monitor and trade on Coinbase Pro and it is slowly being developed to cover all of the endpoints supported. The library is currently in Alpha version, which means I am still testing and modifying heavily, I will make my best effort to keep things as stable as possible, but expect features and interfaces to change.

The MIT license is quite straightforward, but I just want to reiterate that this software is provided AS IS with no warranty. Obviously automating trading can be dangerous for your pocket, but it is up to you to use this library wisely!

It is NOT a library for the regular Coinbase product, this is only for Coinbase Pro.

Authentication

You need to generate your own key, passphrase and secret. You can do this by going to the web portal at pro.coinbase.com, clicking on your profile and then going to the API section. You can choose the permissions (View, Transfer, Trade). I recommend isolating permissions to only what you need per app.

You can generate your keys by clicking 'New API Key'. Make sure you note these down in a json with the following structure:

{
 "key":"xxxxx",
 "passphrase":"xxxxxx",
 "secret":"xxxxxxxxxxxxxxxxxx"
}

If you save it as credentials.json in the folder where your code is, then Koin will pick it up.

k = koin.Koin()

Otherwise you will need to specify the location of the credentials file.

k = koin.Koin(credentials_file = 'credentials/my_coinbase_pro_credentials.json')

Sandbox

I recommend using the sandbox environment before interacting with the production environment. For this you will need to create separate API Keys in the separate Sandbox web portal. You can find it at:

https://public.sandbox.exchange.coinbase.com/

Once you have your keys generated and saved in a json, you need to specify its for the sandbox environment as follows:

k = koin.Koin(credentials_file = 'sandbox.json', sandbox=True)

Functions

As I mentioned, the aim is to cover all endpoints. As I make them available, I will add them to this section. More information is available from Coinbase Pro on their API Documentation

Accounts

Get a list of trading accounts from the profile of the API key

k.accounts()

Market Order

Create a market order which is executed at the current market price. Here you can only specify either the ammount of base currency you want, or the ammount of quote currency you want to use in the trade. For more information about how trading works, consult the Coinbase Pro documentation.

Keyword argument Required Values Description
product_id Yes e.g 'BTC-USD' The currency pair you want to trade (base currency - quote currency)
side Yes 'sell' or 'buy' Do you want to buy or sell the base currency
size No 0.5 The ammount of the base currency you want to trade. You must specify either size or funds
funds No 58.7 The ammount of the quote currency you want to use. You must specify either size or funds
k.place_market_order(
 product_id = 'ETH-USD',
 side = 'buy',
 size = 0.1
)

Limit Order

Create a limit order which is executed if and when the price you specify is reached. For more information about how trading works, consult the Coinbase Pro documentation.

Keyword argument Required Values Description
product_id Yes e.g 'BTC-USD' The currency pair you want to trade
side Yes 'sell' or 'buy' Is it a buy or sell order
price Yes e.g. 2100.5 The market price you want to execute at
size Yes 0.5 The ammount of the base currency you want to trade
time_in_force No 'GTC', 'GTT', 'IOC' or 'FOK' The time in force policy: Good Til Cancel, Good Til Time, Immediate or Cancel, Fill or Kill. Default is Good til Cancel
cancel_after No 'min', 'hour' or 'day' Required when the order is 'GTC'. This is the ammount of time after which the order is cancelled if not filled
post_only No 'True' or 'False' Post Only is a flag to ensure your limit order is posted to the order book and is not immediatelly fileld
k.place_limit_order(
 product_id = 'ETH-USD',
 side = 'buy',
 price = 2000,
 size = 0.1
)

Candles

Get historical rates for a product.

Keyword argument Required Values Description
product_id Yes e.g 'BTC-USD' The currency pair you want to get information for
granularity No 60, 300, 900, 3600, 21600 or 86400 The size of the bucket for each candle returned. Default is 60
start No e.g 1629331200 The start time (in epoch) for the period you want to query
end No e.g 1629331200 The end time (in epoch) for the period you want to query
k.candles(
 product_id = 'ETH-USD',
 granularity = 900
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

koin-0.0.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

koin-0.0.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file koin-0.0.3.tar.gz.

File metadata

  • Download URL: koin-0.0.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for koin-0.0.3.tar.gz
Algorithm Hash digest
SHA256 31a9168d5a4d4436f75851777f937009f10457b6f9e899c7902819ed9f75e0ac
MD5 f9b42c771726b8673d12c1e663e82810
BLAKE2b-256 3307e60ada655fcc54c52cfcac706c518ba3d71531a75e1f2d8c3620ac00d1e3

See more details on using hashes here.

File details

Details for the file koin-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: koin-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for koin-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9661e7a6b32cc30eb968d5f5c2260951bc27796fe46756a4057b769ab4d7d8db
MD5 2f5b78b539643e9765cebac7fe047f3f
BLAKE2b-256 67f864b471977e1bc37bc4b9695aebb4a869c159a8921791c2d0d37d0295a454

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page