CCXT Futues - STOP_MARKET (Python)

Viewed 234

I am attemptin to create a STOP_MARKET order on Futures this is my code:

def futurePlaceOrder(self, symbol, type, side, amount, price=None, params={}):
    return = self.binanceFuture.createOrder (symbol, type, side, amount, price, params = {})

STOP_LOSS =  (futurePlaceOrder(
    symbol = 'BTC/USDT',
    type = 'STOP_MARKET',
    side = 'BUY',
    amount = 0.003,
    params = {
        'stopPrice': 29500,
        'closePosition': False
    }
))

but I am getting the following error:

ccxt.base.errors.InvalidOrder: binance createOrder() requires a stopPrice extra param for a STOP_MARKET order

any advice please, thank you

1 Answers

Does this achieve what you are looking for?

import ccxt
import asyncio
import json

exchange = ccxt.binance({
    'apiKey': [...],
    'secret': [...],
    'enableRateLimit': True,
})

exchange.options = {'defaultType': 'future', # or 'margin' or 'spot'
                    'adjustForTimeDifference': True,
                    'newOrderRespType': 'FULL',
                    'defaultTimeInForce': 'GTC'}

markets = exchange.load_markets()

symbol = 'BTC/USDT'
type ='TAKE_PROFIT'
side = 'buy'
amount = 0.001
price = 26000
params = {
        'stopPrice': 25000,
        }

order = exchange.createOrder(symbol, type, side, amount, price, params)

open_orders = exchange.fetchOrders('BTC/USDT')
data = json.dumps(open_orders, indent=4, separators=(',', ': ') )
print(data)
Related