Baseクラスの全てを掲載
# base.py
"""
Bcolors class
Gvar class
Coin class
Gmo_dataframe class
"""
import numpy as np
import datetime as dt
import pandas as pd
############## Bot colors class
class Bcolors:
HEADER = '\033[95m' # bright magenta
OKBLUE = '\033[94m' # bright blue
OKCYAN = '\033[96m' # bright cyan
OKGREEN = '\033[92m' # bright green
WARNING = '\033[93m' # bright yellow
FAIL = '\033[91m' # bright red
ENDC = '\033[0m' # reset
BOLD = '\033[1m' # bold
UNDERLINE = '\033[4m' # underline
########### Global variables
class Gvar:
###########################
def __init__(self) -> None:
self.callers_method_name = '_main_:'
self.domain = 'desktop-pc' # desktop_pc or note_pc
self.exchange = 'bot' # 'bot' or 'bot1' or 'bot2' ....
self.folder_gmo = f'{self.domain}/{self.exchange}/' # desktop-pc/bot/
self.real_mode = False
self.reset_mode = True
self.debug_mode = True
self.coin_list = [Coin()]
self.althorithm_id = 0
self.stoploss_method_id = 0
self.buysell_condition = 0
self.sellbuy_condition = 0
self.close_pending_orders_freq = 0
self.close_pending_orders = False
self.close_pending_orders_request = False
self.cancel_pending_orders = False
self.buy_count = 0
self.sell_count = 0
self.stop_loss_count = 0
self.buy_cancel_count = 0
self.sell_cancel_count = 0
self.stop_loss = False
self.debug_mode_debug1 = False
self.debug_mode_debug2 = False
#########################
def __str__(self) -> str:
return f"Gvar({self.domain=}, {self.exchange=}, {self.folder_gmo=}, {self.real_mode=}, {self.reset_mode=}, {self.stop_loss=}, {self.debug_mode=}, ...)"
########### Coin class
class Coin:
###########################
def __init__(self) -> None:
self.symbol = 'BTC_JPY'
self.suspend = False
self.master_csv_not_found = False
self.master_df = pd.DataFrame()
self.master2_df = pd.DataFrame()
self.real_mode = False # True of False
self.fake_or_real = 'fake' # 'fake' or 'real'
self.trade_type = 'buy_sell' # 'buy_sell' or 'sell_buy'
self.suspend_new_order = False
self.qty = 0.01
self.round_timestamp_freq = '1S' # freq: H-hour, T-minute, S-seconds, L-milliseconds : new version 0X - skip round timestamp
self.api_retry_limit_count = 6 # GMO api retry limit count
self.api_market_timeout_limit = 100 # 100 seconds
self.profit_rate = 1.0015 # default profit rate (0.0015 + 1)
self.leverage_fee_rate = 0.0004 # default fee leverage rate 0.0004
self.stop_loss_rate = 0.0200 # default stop loss rate 0.0200
self.trend_search_count = 3
self.close_count_limit = 7
self.qty_decimal = 2
self.price_decimal = 0
self.cancel_pending_orders = False
self.debug_mode = False
self.debug_mode_stop_loss = False
self.debug_mode_cancel_pending_orders = False
self.buy_count = 0
self.sell_count = 0
self.stop_loss_count = 0
self.buy_cancel_count = 0
self.sell_cancel_count = 0
self.buy_position_list = []
self.sell_position_list = []
self.position_count_0_10 = 0
self.position_count_11_30 = 0
self.position_count_31_50 = 0
self.position_count_51_70 = 0
self.position_count_71_90 = 0
self.position_count_91_999 = 0
self.buy_sell_lc5 = 0
self.buy_sell_lc10 = 0
self.buy_sell_lc15 = 0
self.buy_sell_lc18 = 0
self.buy_sell_lc20 = 0
self.buy_sell_lc23 = 0
self.buy_sell_lc25 = 0
self.sell_buy_lc5 = 0
self.sell_buy_lc10 = 0
self.sell_buy_lc15 = 0
self.sell_buy_lc18 = 0
self.sell_buy_lc20 = 0
self.sell_buy_lc23 = 0
self.sell_buy_lc25 = 0
self.buy_sell_action12 = False
self.buy_sell_action13 = False
self.buy_sell_action14 = False
self.buy_sell_action15 = False
self.buy_sell_action21 = False
self.buy_sell_action22 = False
self.buy_sell_action23 = False
self.buy_sell_action24 = False
self.buy_sell_action25 = False
self.buy_sell_action26 = False
self.buy_sell_action32_1 = False
self.buy_sell_action32_2 = False
self.buy_sell_action33_1 = False
self.buy_sell_action33_2 = False
self.buy_sell_action41 = False
self.sell_buy_action12 = False
self.sell_buy_action13 = False
self.sell_buy_action14 = False
self.sell_buy_action15 = False
self.sell_buy_action21 = False
self.sell_buy_action22 = False
self.sell_buy_action23 = False
self.sell_buy_action24 = False
self.sell_buy_action25 = False
self.sell_buy_action26 = False
self.sell_buy_action32_1 = False
self.sell_buy_action32_2 = False
self.sell_buy_action33_1 = False
self.sell_buy_action33_2 = False
self.sell_buy_action41 = False
#########################
def __str__(self) -> str:
return f"Coin({self.symbol=}, {self.suspend=}, {self._master_df.shape=}, {self._master2_df.shape=}, {self.round_timestamp_freq=}, {self.trade_type=}, ...)"
@property
def master_df(self) -> pd.DataFrame:
return self._master_df
@property
def master2_df(self) -> pd.DataFrame:
return self._master2_df
@master_df.setter
def master_df(self, master_df: pd.DataFrame) -> None:
if master_df.shape[0] > 0:
cols = master_df.columns
if not 'timestamp' in cols:
raise KeyError(f"master_df['timestamp'] column not found: {cols=}")
self._master_df = master_df.copy()
@master2_df.setter
def master2_df(self, master2_df: pd.DataFrame) -> None:
if master2_df.shape[0] > 0:
cols = master2_df.columns
if not 'time' in cols:
raise KeyError(f"master2_df['time'] column not found: {cols=}")
self._master2_df = master2_df.copy()
#################### GMO dataframe class
class Gmo_dataframe:
### GMO Master DataFrame
GMO_MASTER = [
'price',
'side',
'size',
'timestamp'
]
### GMO Maser DataFrame2
GMO_MASTER2 = [
'time',
'open',
'close',
'low',
'high',
'price',
'buy_price',
'sell_price',
'side',
'size',
'symbol',
'trend',
'pct_change'
]
### Order DataFrame
ORDER_CSV = [
'buy_time',
'sell_time',
'buy_order_id',
'sell_order_id',
'buy_real_qty',
'sell_real_qty',
'buy_real_price',
'sell_real_price',
'buy_real_fee',
'sell_real_fee',
'real_profit',
'accumulated_leverage_fee',
'close_count',
'close_update_date',
'order_closed',
'stop_loss',
'cancelled',
'order_open_date',
'order_close_date',
'log_time'
]
ORDER_XLSX = [
'time(B)',
'time(S)',
'order(B)',
'order(S)',
'qty(B)',
'qty(S)',
'price(B)',
'price(S)',
'fee(B)',
'fee(S)',
'buy(SUM)',
'sell(SUM)',
'profit(AMT)',
'profit(%)',
'fee(L)', # leverage fee
'count(L)', # leverage fee count
'close(L)', # leverage fee close date
'closed',
'stop',
'cancel',
'open',
'close',
'log_time' # update every time
]
### Buy Order DataFrame
BUY_ORDER = [
'buy_time',
'qty',
'price',
'real_qty',
'real_price',
'real_fee',
'sell_time',
'log_time'
]
### Buy Order Sub DataFrame
BUY_ORDER_SUB = [
'buy_time',
'buy_order_id',
'position_id',
'qty',
'price',
'real_qty',
'real_price',
'real_fee',
'get_price_count',
'sold',
'stop_loss',
'cancelled',
'sell_time',
'sell_order_id',
'log_time'
]
### Buy Order Child DataFrame
BUY_ORDER_CHILD = [
'buy_time',
'buy_order_id',
'position_id',
'qty',
'price',
'real_qty',
'real_price',
'real_fee',
'sell_time',
'sell_order_id',
'log_time'
]
### Sell Order DataFrame
SELL_ORDER = [
'sell_time',
'qty',
'price',
'real_qty',
'real_price',
'real_fee',
'buy_time',
'log_time'
]
### Sell Order Sub DataFrame
SELL_ORDER_SUB = [
'sell_time',
'sell_order_id',
'position_id',
'qty',
'price',
'real_qty',
'real_price',
'real_fee',
'get_price_count',
'bought',
'stop_loss',
'cancelled',
'buy_time',
'buy_order_id',
'log_time'
]
### Sell Order Child DataFrame
SELL_ORDER_CHILD = [
'sell_time',
'sell_order_id',
'position_id',
'qty',
'price',
'real_qty',
'real_price',
'real_fee',
'buy_time',
'buy_order_id',
'log_time'
]