ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.97k stars 7.53k forks source link

Bitget - create one-way mode orders with API V2 #20729

Closed krasnyd closed 10 months ago

krasnyd commented 10 months ago

Operating System

Ubuntu

Programming Languages

Python

CCXT Version

4.2.3

Description

I want to create a market order with a one-way mode. When I try to use the standard createOrder function, the API is giving me an error: {"code":"40774","msg":"The order type for unilateral position must also be the unilateral position type."}

The same error was already discussed in issue #19140 and the suggestion was to use the function create_market_order that calls the Bitget API V1 (https://bitgetlimited.github.io/apidoc/en/mix/#place-order). Is there some option for creating the same order with API V2? (https://www.bitget.com/api-doc/contract/trade/Place-Order)

Code

import os
import sys
import time
from asyncio import run
import logging
import ccxt

exchange = ccxt.bitget({
        'apiKey': '..',
        'secret': '...',
        'password': '...',
        'options': {
            'defaultType': 'swap',
        }
})

exchange.fetch_markets()
exchange.load_markets()

symbol = "IMX/USDT:USDT"
type = "market"
side = "buy" 
amount = 5

exchange.set_position_mode(False, symbol)
exchange.set_margin_mode('isolated', symbol)
exchange.set_leverage(10, symbol)

order = exchange.createOrder(symbol, type, side, amount, params={"marginMode": "isolated"})
samgermain commented 10 months ago

Could you share the result of fetchPositions please?

Dan-krm commented 10 months ago

Hey @krasnyd it looks like one-way mode orders don't work on bitget v2 if the tradeSide parameter is filled which is required for hedge mode orders. I opened a pull request that will allow you to set "oneWayMode": true in the createOrder params so that you can create one way mode orders without getting the unilateral error.

Vasco0x4 commented 8 months ago

Hello everyone,

I recently tried to integrate the "oneWayMode": true parameter into my request to the Bitget API, hoping it would allow me to place orders in one-way mode without encountering the unilateral position type error. Unfortunately, I'm still facing the same issue.

headers :

{'ACCESS-KEY': '***', 'ACCESS-SIGN': '***', 'ACCESS-PASSPHRASE': '***', 'ACCESS-TIMESTAMP': '1709932155263', 'Content-Type': 'application/json', 'locale': 'en-US'}

body :

{"symbol": "SOLUSDT", "productType": "usdt-futures", "marginMode": "isolated", "marginCoin": "USDT", "size": "0.1", "side": "buy", "orderType": "market", "oneWayMode": true}

I received the following error: {"code":"40774","msg":"The order type for unilateral position must also be the unilateral position type.","requestTime":1709932155542,"data":null}

Thank you in advance for your help!

Dan-krm commented 8 months ago

@slava387 could you try calling setPositionMode (false) before calling createOrder with the oneWayMode param set to true and let me know if that works for you

Vasco0x4 commented 8 months ago

If anyone has the same problem, you can also simply go to the trading preferences of your Bitget app or website and change the position mode in your trading preferences to 'One-way mode'.

jazzygit commented 7 months ago

Hello, just want to say, that I have been struggeling for days to get the basic buy/sell working on bitget futures perpetual. I gave up with ccxt as bitget configuration requirements (margin, one way/ dual, ticket multiple names etc..) is so weird and because nothing worked for me. :/ Finally I could make it thanks to this projet: https://github.com/BitgetLimited/v3-bitget-api-sdk/tree/master/bitget-python-sdk-api/bitget Everyone, from this great project, can just understand the basic api cals, based on request for a simple version of buy/sell !

It turn out that I had to implement bybit, then kucoin, kraken and now bit get and for EVERY brooker I had problems and long hours of searchin/debugging !! 85% ~of API REST tested sample code on internet does not work :/ Why minimal example are not maintained by brookers.. that would make crypto trader life easier !

Vasco0x4 commented 7 months ago

I had the same problem with the documentation, the documentation provided by Bitget is not up to date

I also managed to call the API for the buy/sell as well as retrieve basic information but I have difficulty placing a stop loss on an already existing order.

roberlin commented 4 months ago

Hi i have the same issue, but figured out it works from my gitpod dev but get the error from google func cloud. Possible they have different servers with different versions and schemantic reactions or they have other semantkic for ip ranges from US (I have had the same wih other crypto exchange). Generaly i think the messages is absoloet. if i send something with to place a limit order without params so i get the same errror.

Vasco0x4 commented 3 months ago

my code is from 4 months ago but is on my github in public. I am also available if you have any questions.