Description
Operating System
Windows 11 - PythonAnywhere.com
Programming Languages
Python
CCXT Version
4.3.21
Description
Hello, Phemex has recently announced they are delisting the perpetual contracts trading pair BTCUSD. I am trying to convert my script to BTCUSDT to adapt to this change. However, it appears the commands that have always worked for BTCUSD do not work for BTCUSDT and I do not know why. For example, when running this code:
exchange.set_leverage(leverage = leverage,symbol = symbol)
I get this error:
{"code":20004,"msg":"TE_ERR_INCONSISTENT_POS_MODE","data":null}
I've tried using exchange.set_position_mode to set to merged, and hedged, and this does not work. I also get similar errors when running:
exchange.create_limit_order(**new_contract_params)
Am I missing required params? Are the commands different for USDT vs. USD?
Code
try:
exchange.set_leverage(leverage = leverage,symbol = symbol)
print("Leverage set")
new_order_params={'type':'swap','code':'USDT'}
# Determine order type based on the signal
if new_signal == 'Buy':
new_order_side = 'long'
new_order_action = 'buy'
elif new_signal == 'Sell':
new_order_side = 'short'
new_order_action = 'sell'
# Get the current market price
ticker = exchange.fetch_ticker(symbol)
live_price = ticker['last']
if new_signal == 'Buy':
new_order_price = live_price + 20
elif new_signal == 'Sell':
new_order_price = live_price - 20
entry_price = {"Entry": new_order_price}
with open('entry_price.json', 'w') as entry_price_file:
json.dump(entry_price, entry_price_file)
new_order_params={'type':'swap','code':'USDT'}
available_balance = exchange.fetch_balance(params = new_order_params)
usd_balance = float(available_balance['total']['USDT'])
prior_balance = {"Value": usd_balance}
with open('usd_balance.json', 'w') as prior_balance_file:
json.dump(prior_balance, prior_balance_file)
new_order_contract_size = round(((((usd_balance * percent_of_holdings_to_enter) * leverage) / new_order_price)*1000),1)
# Create a limit order to open a new position
new_contract_params = {
'symbol': symbol,
'amount': new_order_contract_size,
'side': new_order_action,
'price': new_order_price,
}
new_order = exchange.create_limit_order(**new_contract_params)
new_order_id = new_order['id']