-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbinance_client.py
More file actions
34 lines (26 loc) · 1.28 KB
/
binance_client.py
File metadata and controls
34 lines (26 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import inspect
from binance import Client
class BinanceClient:
@staticmethod
def check_balance(api_k: str, api_s: str, logger=None) -> [float] or int:
func_name = inspect.currentframe().f_code.co_name
try:
client = Client(api_k, api_s)
client.close_connection()
return [float(client.get_asset_balance(value).get("free")) for value in ["BTC", "USDT", "BUSD"]]
except Exception as error:
logger.error(f"{func_name}/{api_k}||{error.__class__},{error.args[0]}") if logger else 1
return -1
@staticmethod
def buy_order(api_k: str, api_s: str, token: str, percent: str = None, logger=None) -> int:
func_name = inspect.currentframe().f_code.co_name
try:
client = Client(api_k, api_s)
balance = float(client.get_asset_balance("BTC").get("free"))
client.create_order(symbol=(token + "BTC"), side='BUY', type='MARKET', quoteOrderQty=balance)
client.close_connection()
logger.info(f"{func_name}/{api_k}") if logger else 1
return 0
except Exception as error:
logger.error(f"{func_name}/{api_k}||{error.__class__},{error.args[0]}") if logger else 1
return -1