mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 06:51:38 +00:00
add balance command
This commit is contained in:
@@ -84,23 +84,25 @@ def order_book(coin: str, other_args: List[str]):
|
||||
|
||||
"""
|
||||
limit_list = [5, 10, 20, 50, 100, 500, 1000, 5000]
|
||||
parser = argparse.ArgumentParser(prog = "book",
|
||||
add_help = False,
|
||||
description="Get the order book for selected coin")
|
||||
parser.add_argument("-l",
|
||||
"--limit",
|
||||
dest="limit",
|
||||
help="Limit parameter. Adjusts the weight",
|
||||
default = 100,
|
||||
type = int,
|
||||
choices=limit_list)
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="book", add_help=False, description="Get the order book for selected coin"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--limit",
|
||||
dest="limit",
|
||||
help="Limit parameter. Adjusts the weight",
|
||||
default=100,
|
||||
type=int,
|
||||
choices=limit_list,
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
client = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY)
|
||||
order_book = client.get_order_book(symbol=coin, limit = ns_parser.limit)
|
||||
order_book = client.get_order_book(symbol=coin, limit=ns_parser.limit)
|
||||
bids = np.asarray(order_book["bids"], dtype=float)
|
||||
asks = np.asarray(order_book["asks"], dtype=float)
|
||||
bids = np.insert(bids, 2, bids[:, 1].cumsum(), axis=1)
|
||||
@@ -215,15 +217,13 @@ def candles(coin: str, other_args: List[str]):
|
||||
print("")
|
||||
|
||||
|
||||
def balance(coin: str, other_args: List[str]):
|
||||
def balance(coin: str):
|
||||
"""
|
||||
Get account holdings for asset
|
||||
Parameters
|
||||
----------
|
||||
coin: str
|
||||
Coin to get holdings of
|
||||
other_args : List[str]
|
||||
Argparse arguments
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -231,7 +231,15 @@ def balance(coin: str, other_args: List[str]):
|
||||
"""
|
||||
client = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY)
|
||||
try:
|
||||
client.get_asset_balance(asset=coin)
|
||||
balance = client.get_asset_balance(asset=coin)
|
||||
if balance is None:
|
||||
print("Check loaded coin")
|
||||
return
|
||||
print("")
|
||||
print(f"You currently have {balance['free']} free and {balance['locked']} locked")
|
||||
print("")
|
||||
return
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
return
|
||||
|
||||
@@ -44,15 +44,15 @@ def plot_order_book(bids: np.array, asks: np.array, coin: str):
|
||||
print("")
|
||||
|
||||
|
||||
def plot_candles(candles_df: pd.DataFrame, coin: str):
|
||||
def plot_candles(candles_df: pd.DataFrame, title: str):
|
||||
"""
|
||||
Plot candle chart from dataframe
|
||||
Parameters
|
||||
----------
|
||||
candles_df: pd.DataFrame
|
||||
Dataframe containing time and OHLVC
|
||||
coin: str
|
||||
Coin plotting for
|
||||
title: str
|
||||
title of graph
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -62,8 +62,8 @@ def plot_candles(candles_df: pd.DataFrame, coin: str):
|
||||
candles_df,
|
||||
type="candle",
|
||||
volume=True,
|
||||
title=f"{coin}",
|
||||
xrotation=10,
|
||||
title=f"{title}",
|
||||
xrotation=20,
|
||||
style="binance",
|
||||
figratio=(10, 7),
|
||||
figscale=1.10,
|
||||
|
||||
@@ -122,9 +122,9 @@ class CryptoController:
|
||||
"""Candle command - show candle chart from binance"""
|
||||
binance_model.candles(self.current_coin + self.current_currency, other_args)
|
||||
|
||||
def call_balance(self, other_args):
|
||||
def call_balance(self, _):
|
||||
"""Balance command - check current holdings of coin in binance"""
|
||||
binance_model.balance(self.current_coin, other_args)
|
||||
binance_model.balance(self.current_coin)
|
||||
|
||||
def call_add(self, other_args):
|
||||
"""Add command - set current coin for binance operations"""
|
||||
|
||||
@@ -57,7 +57,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
print(" mill papermill menu, \t\t\t menu to generate notebook reports")
|
||||
print(" econ economic data, \t\t\t from: FRED, VIX")
|
||||
print(" pa portfolio analysis, \t\t supports: robinhood, alpaca, ally ")
|
||||
print(" crypto cryptocurrencies, \t\t uses coingecko api")
|
||||
print(" crypto cryptocurrencies, \t\t coingecko, coinmarketcap and binance")
|
||||
print(
|
||||
" po portfolio optimization, \t\t optimal portfolio weights from pyportfolioopt"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user