Skip to content

Commit

Permalink
Add suport testnet and create new constant hedge mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardospinoza committed Jan 10, 2023
1 parent 7206a1c commit 26a5b33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
FIRST_COIN_SYMBOL = "USDT"
SECOND_COIN_SYMBOL = "BTC"
CONTRACT_SYMBOL = SECOND_COIN_SYMBOL + FIRST_COIN_SYMBOL
TIMEFRAME = "h1"
TIMEFRAME = "h1" # m1 m5 m15 h1 h4 d1 etc...
TAKE_PROFIT_PERCENTS = [2, 3, 1.5, 2] # len(TAKE_PROFIT_PERCENTS) must equals STRATEGIES_COUNT
STOP_LOSS_PERCENTS = [-1, -1, -1.5, -1.5] # len(STOP_LOSS_PERCENTS) must equals STRATEGIES_COUNT
PRICE_DECIMAL_DIGITS = 2
Expand All @@ -27,3 +27,7 @@
LAST_ACCOUNT_BALANCES_LIST_MAX_LENGTH = 12
IMPORTANT_CANDLES_COUNT = 100
SEND_TELEGRAM_MESSAGE = False
HEDGE_MOODE = True # True to allow long and short positions simultaneously
IS_TESTNET = True # True to enable mode teste for Binance
URL_BASE_PRODUCTION = "https://fapi.binance.com"
URL_BASE_TESTNET = "https://testnet.binancefuture.com"
6 changes: 4 additions & 2 deletions credentials.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
API_KEY = ""
SECRET_KEY = ""
API_KEY_PRODUCTION = ""
SECRET_KEY_PRODUCTION = ""
API_KEY_TESTNET = ""
SECRET_KEY_TESTNET = ""
TELEGRAM_API_KEY = ""
TELEGRAM_USER_ID = ""
11 changes: 7 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,11 @@ def close_all_open_positions_market_price() -> int:

def init_bot() -> None:
global binance_futures_api
binance_futures_api = UMFutures(key=API_KEY, secret=SECRET_KEY)


if IS_TESTNET:
binance_futures_api = UMFutures(key=API_KEY_PRODUCTION, secret=SECRET_KEY_PRODUCTION)
else:
binance_futures_api = UMFutures(key=API_KEY_TESTNET, secret=SECRET_KEY_TESTNET)

def update_is_price_increasing(
price_direction_indicator_name_1: str,
Expand Down Expand Up @@ -731,7 +734,7 @@ def set_position_mode(hedge_mode: bool) -> int:
else:
binance_futures_api.change_position_mode(dualSidePosition="false", timestamp=get_local_timestamp())
return SUCCESSFUL
except:
except:
pass
logging.warning("ERROR/WARNING in set_position_mode (this may happen normally when position mode is unchanged)")
return ERROR
Expand Down Expand Up @@ -921,7 +924,7 @@ def main() -> None:
init_bot()
update_account_balance_and_unrealized_profit(FIRST_COIN_SYMBOL)
set_leverage(CONTRACT_SYMBOL, LEVERAGE)
set_position_mode(hedge_mode=True)
set_position_mode(HEDGE_MOODE)
while True:
sleep(SLEEP_INTERVAL)
update_current_time()
Expand Down

0 comments on commit 26a5b33

Please sign in to comment.