crypto readme

This commit is contained in:
Jamie
2021-05-01 20:05:05 -04:00
parent af58e97c63
commit 5ee71c08f2
3 changed files with 69 additions and 11 deletions

View File

@@ -6,9 +6,21 @@ This menu aims to explore crypto world, and the usage of the following commands
* load a given coin vs a given currency [CoinGecko]
* [view](#view)
* plot the loaded crypto data
* [trend](#trend)
* show the top 7 coins from coingecko
* [top](#top)
* view top coins from coinmarketcap [coinmarketcap.com]
* [add](#add)
* add a coin/currency pair for Binance
* [book](#book)
* get and show market (order) book
* [candle](#candle)
* show candle plot of selected coin/currency
* [balance](#balance)
* show current holdings in your account for given coin
## load <a name="load"></a>
@@ -35,6 +47,12 @@ Plot the loaded crypto data.
![crypto_view](https://user-images.githubusercontent.com/25267873/115787452-20889a80-a3ba-11eb-9216-f7fd1ffc98cf.png)
## trend <a name="trend"></a>
Print the top 7 trending coins from coingecko
````
usage: trend
````
## top <a name="top"></a>
@@ -50,3 +68,39 @@ This command displays the top n cryptocurrencies from coinmarketcap.com.
<img width="990" alt="crypto" src="https://user-images.githubusercontent.com/25267873/115787544-4746d100-a3ba-11eb-9433-b7cb9142404a.png">
## add <a name="add"></a>
Add a coin/currency to the current object. Note that in binance, the exchange "ticker" is usually COINCURR, such as BTCEUR
for BTC to EURO. There is no USD, but it uses a coin tethered to the USD (USDT), which is the default. Some symbols
are a combination of coins, as `ETHBTC` is a valid symbol
````
usage: add [-c --coin] [-q --quote]
````
* -c/--coin Coin to load. If not specified, BTC will be loaded to prevent errors later.
* -q/--quote Quote currency. Defaults to `USDT` (which is 1-to-1 with USD)
Note that the usage `load btc` will also work, as it will add `-c` if not detected.
## book <a name="book"></a>
Gets and shows the order book for the given coin/currency. Shows the cumulative amount of orders.
````
usage: book -l/--limit
````
* -l/--limit Number of orders to get on each side. One of [5,10,20,50,100,500,1000,5000]. Defaults to 100.
## candle <a name="candle"></a>
Show candle chart for loaded coin/currency. (Terminal will quit if coin is not defined).
````
usage: candle [-i --interval] [-l --limit]
````
* -i/--interval. Interval for candles. One of [1day,3day,1hour,2hour,4hour,6hour,8hour,12hour,1week,1min,3min,5min,15min,30min,1month].
Defaults to 1day.
* -l/--limit. Number of candles to get. Defaults to 100.
Example output (using 3day interval and 50 candles)
![im](https://user-images.githubusercontent.com/18151143/116797645-f455d380-aab5-11eb-8dbb-df257425302d.png)
## balance <a name="balance"></a>
Shows the current holding balance in your account.
````
usage: balance
````

View File

@@ -102,18 +102,19 @@ def order_book(coin: str, other_args: List[str]):
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)
bids = np.asarray(order_book["bids"], dtype=float)
asks = np.asarray(order_book["asks"], dtype=float)
market_book = client.get_order_book(symbol=coin, limit=ns_parser.limit)
bids = np.asarray(market_book["bids"], dtype=float)
asks = np.asarray(market_book["asks"], dtype=float)
bids = np.insert(bids, 2, bids[:, 1].cumsum(), axis=1)
asks = np.insert(asks, 2, np.flipud(asks[:, 1]).cumsum(), axis=1)
plot_order_book(bids, asks, coin)
except Exception as e:
print(e)
print("")
def candles(coin: str, other_args: List[str]):
def show_candles(coin: str, other_args: List[str]):
"""
Get klines/candles for coin
Parameters
@@ -164,7 +165,7 @@ def candles(coin: str, other_args: List[str]):
)
parser.add_argument(
"-l", "--limit", dest="limit", default=200, help="Number to get", type=int
"-l", "--limit", dest="limit", default=100, help="Number to get", type=int
)
try:
@@ -231,12 +232,14 @@ def balance(coin: str):
"""
client = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY)
try:
balance = client.get_asset_balance(asset=coin)
if balance is None:
current_balance = client.get_asset_balance(asset=coin)
if current_balance is None:
print("Check loaded coin")
return
print("")
print(f"You currently have {balance['free']} free and {balance['locked']} locked")
print(
f"You currently have {current_balance['free']} free and {current_balance['locked']} locked"
)
print("")
return
except Exception as e:

View File

@@ -120,7 +120,9 @@ class CryptoController:
def call_candle(self, other_args):
"""Candle command - show candle chart from binance"""
binance_model.candles(self.current_coin + self.current_currency, other_args)
binance_model.show_candles(
self.current_coin + self.current_currency, other_args
)
def call_balance(self, _):
"""Balance command - check current holdings of coin in binance"""
@@ -134,7 +136,6 @@ class CryptoController:
print(f"{self.current_coin} loaded vs {self.current_currency}")
print("")
def menu():
crypto_controller = CryptoController()
crypto_controller.print_help(crypto_controller)