Package: koin
KoinA 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 nowarranty. 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.AuthenticationYou need to generate your ownkey,passphraseandsecret. You can do this by going to the web portal atpro.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 ascredentials.jsonin the folder where your code is, thenKoinwill 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')SandboxI 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)FunctionsAs 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 theirAPI DocumentationAccountsGet a list of trading accounts from the profile of the API keyk.accounts()Market OrderCreate 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 argumentRequiredValuesDescriptionproduct_idYese.g'BTC-USD'The currency pair you want to trade (base currency - quote currency)sideYes'sell'or'buy'Do you want to buy or sell the base currencysizeNo0.5The ammount of the base currency you want to trade. You must specify eithersizeorfundsfundsNo58.7The ammount of the quote currency you want to use. You must specify eithersizeorfundsk.place_market_order(product_id='ETH-USD',side='buy',size=0.1)Limit OrderCreate a limit order which is executed if and when thepriceyou specify is reached. For more information about how trading works, consult the Coinbase Pro documentation.Keyword argumentRequiredValuesDescriptionproduct_idYese.g'BTC-USD'The currency pair you want to tradesideYes'sell'or'buy'Is it a buy or sell orderpriceYese.g.2100.5The market price you want to execute atsizeYes0.5The ammount of the base currency you want to tradetime_in_forceNo'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 Cancelcancel_afterNo'min','hour'or'day'Required when the order is'GTC'. This is the ammount of time after which the order is cancelled if not filledpost_onlyNo'True'or'False'Post Only is a flag to ensure your limit order is posted to the order book and is not immediatelly fileldk.place_limit_order(product_id='ETH-USD',side='buy',price=2000,size=0.1)CandlesGet historical rates for a product.Keyword argumentRequiredValuesDescriptionproduct_idYese.g'BTC-USD'The currency pair you want to get information forgranularityNo60,300,900,3600,21600or86400The size of the bucket for each candle returned. Default is60startNoe.g1629331200The start time (in epoch) for the period you want to queryendNoe.g1629331200The end time (in epoch) for the period you want to queryk.candles(product_id='ETH-USD',granularity=900)