mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 15:32:04 +00:00
* implement user and change is guest * replace User methods * move remaining functions to user * fix bug * portfolio test * fix tests * fix tests * uncomment skip * ruff * start credentials model implementation * change deault structure * refacto quandl * change default struct and file names * bug * start using global user * add comments * move update flair * change cfg references in keys model * reddit & fmp * refactore additional keys * remaing config keys * remove unsude imports and fix hub keys * ruff * fix line too long * unblock unittests * fix keys model tests * remove os patch * fix account controller tests * fix account controller tests * fix account model * account fixed * fix user tests * User Model * User Model * User Model * Move session folder * User Model : grouping the models * User Model : fix bugs * Config Plot + bug fix * User Model : Refactoring plots * Feature flags * Remove dup * clean comments a fix some vars * fix feature flags controller * refactor obbff from settings controller * refactor a bunch of obbff variables * fix bug blocking terminal * fix integration tests * refactor controllers with obbff * refactor remaining ffs * remove comments * log not started * mispelled variable * set current user on local model * User Model : moving files + updating * User Preferences * User : Refactor is_guest function + bug fix * User : refactor is_guest function * Fix conftest.py * remove lost obbffs * typo on fileoverwrite * Plot config: move variables and start plot dpi * User : tests * refactor plot dpi references * remove plot dpi imports * refactor some config terminal leftover * /account/sync : fix bug * remove configs reload * start path refactor * installation paths vs user paths * remove cfg_plot * Tests : User Refactoring * user prefix only for preferences * user prefix only for preferences * move user paths * remove comment * update apply remote configs * fix tz not updating * save some copys * small fix * create interface for credentials and preferences * wrong docstrings fixed * ruff core * fix some pref setting * login is better * ruff * ruff * remove Literal * add small comment * Tests : User Refactoring * Credentials Model : add DataBento * Fix helper_funcs * Fixing code * Tests : fixing * User Model : freezing the models * Fixed Income + Databento * Tests : fixing keys * black * ruff * Tests : user model * Tests : user model * Fix linting * Fix linting * Linting * Linting * Fixing code and tests * Fix tests * mypy * SDK * Clean ruff cache * Fix syntax issue * Update fred_view * Black * Linting * Update code * Update tests * Linting * Linting * Tests * Black * Linting * Linting * Mock os.listdir to avoid looking for file that doesnt exist * Mock options paths * lint * Tests : fix * Code : update * Tests + Linting * Tests * Ruff * Code : update * Tests * Code : update * Fix workflow * Code : update --------- Co-authored-by: Chavithra PARANA <chavithra@gmail.com> Co-authored-by: luqazino@gmail.com <luqazino@gmail.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
261 lines
8.0 KiB
Python
261 lines
8.0 KiB
Python
"""Coinbase Controller"""
|
|
__docformat__ = "numpy"
|
|
|
|
# pylint: disable=R0904, C0302, W0622
|
|
import argparse
|
|
import logging
|
|
from typing import List, Optional
|
|
|
|
from openbb_terminal.core.session.current_user import get_current_user
|
|
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import EXPORT_ONLY_RAW_DATA_ALLOWED, check_positive
|
|
from openbb_terminal.menu import session
|
|
from openbb_terminal.parent_classes import BaseController
|
|
from openbb_terminal.portfolio.brokers.coinbase import coinbase_view
|
|
from openbb_terminal.rich_config import MenuText, console
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class CoinbaseController(BaseController):
|
|
"""Coinbase Controller class"""
|
|
|
|
CHOICES_COMMANDS = ["account", "history", "orders", "deposits"]
|
|
|
|
order_sortby = [
|
|
"product_id",
|
|
"side",
|
|
"price",
|
|
"size",
|
|
"type",
|
|
"created_at",
|
|
"status",
|
|
]
|
|
deposit_sort = [
|
|
"created_at",
|
|
"amount",
|
|
]
|
|
deposit_type = ["internal_deposit", "deposit"]
|
|
PATH = "/portfolio/bro/cb/"
|
|
CHOICES_GENERATION = True
|
|
|
|
def __init__(self, queue: Optional[List[str]] = None):
|
|
"""Constructor"""
|
|
super().__init__(queue)
|
|
|
|
if session and get_current_user().preferences.USE_PROMPT_TOOLKIT:
|
|
choices: dict = self.choices_default
|
|
self.choices = choices
|
|
self.completer = NestedCompleter.from_nested_dict(choices)
|
|
|
|
def print_help(self):
|
|
"""Print help"""
|
|
mt = MenuText("portfolio/bro/cb/")
|
|
mt.add_cmd("account")
|
|
mt.add_cmd("history")
|
|
mt.add_cmd("deposits")
|
|
mt.add_cmd("orders")
|
|
console.print(text=mt.menu_text, menu="Portfolio - Brokers - Coinbase")
|
|
|
|
@log_start_end(log=logger)
|
|
def call_account(self, other_args):
|
|
"""Process account command"""
|
|
parser = argparse.ArgumentParser(
|
|
prog="account",
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
description="Display info about your trading accounts on Coinbase",
|
|
)
|
|
parser.add_argument(
|
|
"--all",
|
|
action="store_true",
|
|
help="Flag to display all your account",
|
|
dest="all",
|
|
default=False,
|
|
)
|
|
parser.add_argument(
|
|
"-c",
|
|
"--currency",
|
|
default="USD",
|
|
type=str,
|
|
dest="currency",
|
|
help="Currency to display value in.",
|
|
)
|
|
|
|
if other_args and other_args[0][0] != "-":
|
|
other_args.insert(0, "--acc")
|
|
|
|
ns_parser = self.parse_known_args_and_warn(
|
|
parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED
|
|
)
|
|
|
|
if ns_parser:
|
|
coinbase_view.display_account(
|
|
currency=ns_parser.currency,
|
|
export=ns_parser.export,
|
|
sheet_name=" ".join(ns_parser.sheet_name)
|
|
if ns_parser.sheet_name
|
|
else None,
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_history(self, other_args):
|
|
"""Process account command"""
|
|
parser = argparse.ArgumentParser(
|
|
prog="history",
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
description="Display account history",
|
|
)
|
|
parser.add_argument(
|
|
"-a",
|
|
"--acc",
|
|
dest="account",
|
|
help="Symbol of coin of account or id",
|
|
type=str,
|
|
default="BTC",
|
|
required=False,
|
|
)
|
|
parser.add_argument(
|
|
"-l",
|
|
"--limit",
|
|
dest="limit",
|
|
help="Limit parameter.",
|
|
default=20,
|
|
type=check_positive,
|
|
)
|
|
|
|
if other_args and other_args[0][0] != "-":
|
|
other_args.insert(0, "--acc")
|
|
|
|
ns_parser = self.parse_known_args_and_warn(
|
|
parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED
|
|
)
|
|
|
|
if ns_parser:
|
|
coinbase_view.display_history(
|
|
ns_parser.account,
|
|
ns_parser.export,
|
|
ns_parser.sheet_name,
|
|
ns_parser.limit,
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_orders(self, other_args):
|
|
"""Process orders command"""
|
|
parser = argparse.ArgumentParser(
|
|
prog="orders",
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
description="List your current open orders",
|
|
)
|
|
parser.add_argument(
|
|
"-l",
|
|
"--limit",
|
|
dest="limit",
|
|
help="Limit parameter.",
|
|
default=20,
|
|
type=check_positive,
|
|
)
|
|
parser.add_argument(
|
|
"-s",
|
|
"--sort",
|
|
dest="sortby",
|
|
type=str,
|
|
help="Sort by given column. Default: created_at",
|
|
default="created_at",
|
|
choices=self.order_sortby,
|
|
)
|
|
parser.add_argument(
|
|
"-r",
|
|
"--reverse",
|
|
action="store_true",
|
|
dest="reverse",
|
|
default=False,
|
|
help=(
|
|
"Data is sorted in descending order by default. "
|
|
"Reverse flag will sort it in an ascending way. "
|
|
"Only works when raw data is displayed."
|
|
),
|
|
)
|
|
if other_args and other_args[0][0] != "-":
|
|
other_args.insert(0, "--acc")
|
|
|
|
ns_parser = self.parse_known_args_and_warn(
|
|
parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED
|
|
)
|
|
|
|
if ns_parser:
|
|
coinbase_view.display_orders(
|
|
limit=ns_parser.limit,
|
|
sortby=ns_parser.sortby,
|
|
descend=not ns_parser.reverse,
|
|
export=ns_parser.export,
|
|
sheet_name=" ".join(ns_parser.sheet_name)
|
|
if ns_parser.sheet_name
|
|
else None,
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_deposits(self, other_args):
|
|
"""Process deposits command"""
|
|
parser = argparse.ArgumentParser(
|
|
prog="deposits",
|
|
add_help=False,
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
description="Display a list of deposits for your account.",
|
|
)
|
|
parser.add_argument(
|
|
"-t",
|
|
"--type",
|
|
dest="type",
|
|
type=str,
|
|
help="Deposit type. Either: internal_deposits (transfer between portfolios) or deposit",
|
|
default="deposit",
|
|
choices=self.deposit_type,
|
|
)
|
|
parser.add_argument(
|
|
"-l",
|
|
"--limit",
|
|
dest="limit",
|
|
help="Limit parameter.",
|
|
default=20,
|
|
type=check_positive,
|
|
)
|
|
parser.add_argument(
|
|
"-s",
|
|
"--sort",
|
|
dest="sortby",
|
|
type=str,
|
|
help="Sort by given column. Default: created_at",
|
|
default="created_at",
|
|
choices=self.deposit_sort,
|
|
)
|
|
parser.add_argument(
|
|
"-r",
|
|
"--reverse",
|
|
action="store_true",
|
|
dest="reverse",
|
|
default=False,
|
|
help=(
|
|
"Data is sorted in descending order by default. "
|
|
"Reverse flag will sort it in an ascending way. "
|
|
"Only works when raw data is displayed."
|
|
),
|
|
)
|
|
ns_parser = self.parse_known_args_and_warn(
|
|
parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED
|
|
)
|
|
if ns_parser:
|
|
coinbase_view.display_deposits(
|
|
limit=ns_parser.limit,
|
|
sortby=ns_parser.sortby,
|
|
deposit_type=ns_parser.type,
|
|
descend=ns_parser.reverse,
|
|
export=ns_parser.export,
|
|
sheet_name=" ".join(ns_parser.sheet_name)
|
|
if ns_parser.sheet_name
|
|
else None,
|
|
)
|