OpenBB icon indicating copy to clipboard operation
OpenBB copied to clipboard

Transition from Coinbase Pro to Coinbase Advanced broker (API v3)

Open marcelonyc opened this issue 2 years ago • 10 comments

Description

In June Coinbase announced that they will begin sunsetting Coinbase Pro by end of 2022.

https://www.coinbase.com/blog/hello-advanced-trade-goodbye-coinbase-pro

This PR implements integration with their new Coinbase Advanced API. This API (v3) is still under development and it is significantly different than the Pro API. It also requires using different APIs depending on the task.

  • [x] Screenshot of the feature or the bug before/after fix, if applicable. orders accounts

  • [x] Relevant motivation and context. Coinbase sunsetting PRO API

  • [x] List any dependencies that are required for this change.

  • Added environment variables for API KEYS keys_model.py

  • Added menu text for new paths en.yml

  • Added a function to validate datetime arguments to helper_funcs.py

How has this been tested?

I manually tested each command including placing/canceling orders with Coinbase Advance. Order commands have a --dry-run option to review the json payload. Screenshot of each order test here: dry-run cancelorder limitgtcbuy limitgtcsell limitgtdbuy limitgtd_sell stopgtcbuy stopgtcsell stopgtdbuy stopgtdsell

  • Please describe the tests that you ran to verify your changes.
  • Provide instructions so we can reproduce.
  • Please also list any relevant details for your test configuration.
  • [x] Make sure affected commands still run in terminal
  • [ ] Ensure the SDK still works
  • [ ] Check any related reports

Checklist:

Others

  • [X] I have performed a self-review of my own code.
  • [X] I have commented my code, particularly in hard-to-understand areas.

marcelonyc avatar Dec 09 '22 15:12 marcelonyc

Hey thanks for this! Looks awesome!

I am trying to find someone on the team with the credentials to test this out (or maybe our friend @JakubPluta)

jmaslek avatar Dec 09 '22 19:12 jmaslek

Followup: havent been ignoring this. I just switched my account over to this new v3 thing. Said I would have access in 2 days lol. So will be able to test out then

jmaslek avatar Dec 17 '22 00:12 jmaslek

@jmaslek no rush. I am taking the time to clean up the code and also adding create/cancel order menus. Unfortunately, Coinbase is not providing a sandbox environment for the Advanced Trading API (Yet). I have to test my orders code carefully so I do not wipe out my portfolio or get an unexpected tax bill :)

marcelonyc avatar Dec 17 '22 13:12 marcelonyc

Hey I am finally giving this a go. I got my api key up and whatnot:

│     coinbase_advanced      CB_ADV                     defined, test passed     

But when I try to enter the cbadv menu:

023 Jan 05, 11:28 (🦋) /portfolio/bro/ $ cbadv

2023 Jan 05, 11:28 (🦋) /portfolio/bro/cbadv/ $ ?

Nothing is happening. So I look at the debug printout and I am getting:

  File "/Users/james/OpenBBTerminal/OpenBBTerminal/openbb_terminal/portfolio/brokers/bro_controller.py", line 80, in call_cbadv
    self.queue = self.load_class(
  File "/Users/james/OpenBBTerminal/OpenBBTerminal/openbb_terminal/parent_classes.py", line 219, in load_class
    return class_ins(*args, **kwargs).menu()
  File "/Users/james/OpenBBTerminal/OpenBBTerminal/openbb_terminal/portfolio/brokers/coinbase_advanced/coinbase_advanced_controller.py", line 70, in __init__
    choices: dict = self.choices_default
  File "/Users/james/OpenBBTerminal/OpenBBTerminal/openbb_terminal/parent_classes.py", line 115, in choices_default
    choices = build_controller_choice_map(controller=self)
  File "/Users/james/OpenBBTerminal/OpenBBTerminal/openbb_terminal/core/completer/choices.py", line 322, in build_controller_choice_map
    raise Exception(
Exception: On command : `cancelorder`.
'status'

This has to do with autocomplete -- but everything on your end looks good. IS this happening for you at all?

I think I may have found the issue with this? Note I have no active orders. I think I have like 12 bucks sitting in the free learn stuff so that I can access the API lol

jmaslek avatar Jan 05 '23 16:01 jmaslek

This is probably a me issue as well in the sense of maybe I didnt do coinbase advanced setup correctly, but the account is showing no response even though i have a small amount of some coins like btc/eth


2023 Jan 05, 11:44 (🦋) /portfolio/bro/cbadv/ $ account


2023 Jan 05, 11:44 (🦋) /portfolio/bro/cbadv/ $ account

jmaslek avatar Jan 05 '23 16:01 jmaslek

This is probably a me issue as well in the sense of maybe I didnt do coinbase advanced setup correctly, but the account is showing no response even though i have a small amount of some coins like btc/eth


2023 Jan 05, 11:44 (🦋) /portfolio/bro/cbadv/ $ account


2023 Jan 05, 11:44 (🦋) /portfolio/bro/cbadv/ $ account

@jmaslek I am not sure why it would come back empty if you have valid assets. Unless the assets you have are "Not Tradable in your region". For some reason, the request does not return those For example in the UI (for my account) XRP shows as "Not Tradeble in your region". I have a few XRP in Coinbase, they do not show when I run accounts.

marcelonyc avatar Jan 05 '23 17:01 marcelonyc

@jmaslek I am not sure why it would come back empty if you have valid assets. Unless the assets you have are "Not Tradable in your region". For some reason, the request does not return those For example in the UI (for my account) XRP shows as "Not Tradeble in your region". I have a few XRP in Coinbase, they do not show when I run accounts.

Hmm. Interesting. Im in the US, but I have BTC/ETH/ETH2 so I assume those would show up.

jmaslek avatar Jan 05 '23 17:01 jmaslek

@jmaslek when you created the API key did you select all the accounts or just My Wallet? Screenshot from 2023-01-05 13-09-02

marcelonyc avatar Jan 05 '23 18:01 marcelonyc

@jmaslek when you created the API key did you select all the accounts or just My Wallet? Screenshot from 2023-01-05 13-09-02

Do not remember. Knowing meself I did all

jmaslek avatar Jan 05 '23 18:01 jmaslek

I changed the cancelorder command to avoid the error @jmaslek saw. And btw, I realized that at some point, I removed cancelorder from the menu. It is there now.

For cancelorder, Instead of loading a list of orders, which does not work well, the user has to paste the order_id ( cancelorder --order_id <paste order id here> )

To make the order_id visible when users list orders, I gave the orders command a --slim argument to display less columns.

Screen Shot 2023-01-05 at 4 28 14 PM

A side note on this. If print_rich_table had the option to provide columns min/max width, I could just changed the width of the order_id column to be wider. Maybe I will make this a feature request.

I am not sure why @jmaslek can't list accounts. I was able to reproduce it with an API key with limited account access, but I am not sure if that is the case he ran into.

marcelonyc avatar Jan 05 '23 22:01 marcelonyc