Can not set stop loss / take profit, error ‘Order does not exist
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 18/100
Hướng nghiên cứu
Bắt đầu với hàm create_cross_order và yêu cầu POST của hàm này tới /fapi/v1/order, sau đó đối chiếu các tham số được cung cấp với tài liệu Binance Futures API. Issue không nêu tệp nào trong repository hoặc test nào, vì vậy để hoàn thành cần tái hiện lỗi đã được báo cáo và xác nhận rằng order cùng hành vi TP/SL của order được chấp nhận như dự kiến.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I have an issue is the TP/SL function not reading the Binance side
could you please help me to resolve this issues
import requests
import hashlib
import hmac
import time
def get_current_price(symbol):
base_url = 'https://fapi.binance.com'
endpoint = '/fapi/v1/ticker/price'
params = {
'symbol': symbol
}
response = requests.get(f'{base_url}{endpoint}', params=params)
data = response.json()
if 'price' in data:
return float(data['price'])
else:
return None
def calculate_required_margin(quantity, price, leverage):
return (quantity * price) / leverage
def get_account_balance():
base_url = 'https://fapi.binance.com'
endpoint = '/fapi/v2/account'
params = {
'timestamp': int(time.time() * 1000)
}
signature = hmac.new(API_SECRET.encode('utf-8'), '&'.join([f'{k}={v}' for k, v in params.items()]).encode('utf-8'), hashlib.sha256).hexdigest()
headers = {
'X-MBX-APIKEY': API_KEY
}
url = f'{base_url}{endpoint}?timestamp={params["timestamp"]}&signature={signature}'
response = requests.get(url, headers=headers)
return response.json()
def create_cross_order(symbol, side, quantity, leverage, position_side, take_profit_percent, stop_loss_percent):
base_url = 'https://fapi.binance.com'
endpoint = '/fapi/v1/order'
current_price = get_current_price(symbol)
if current_price is None:
print('Failed to fetch current price.')
return
required_margin = calculate_required_margin(quantity, current_price, leverage)
# Fetch account information to check available balance
account_info = get_account_balance()
if 'totalWalletBalance' in account_info:
total_wallet_balance = float(account_info['totalWalletBalance'])
if total_wallet_balance < required_margin:
print("Insufficient balance for required margin.")
return
else:
print("Failed to fetch account balance.")
return
# Calculate take profit and stop loss prices
take_profit_price = current_price * (1 + take_profit_percent / 100)
stop_loss_price = current_price * (1 - stop_loss_percent / 100)
params = {
'symbol': symbol,
'side': side,
'positionSide': position_side,
'quantity': quantity,
'price': current_price,
'type': 'LIMIT',
'timeInForce': 'GTC',
'leverage': leverage,
'timestamp': int(time.time() * 1000),
'takeProfit': take_profit_price,
'stopLoss': stop_loss_price
}
query_string = '&'.join([f'{k}={v}' for k, v in params.items()])
signature = hmac.new(API_SECRET.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()
headers = {
'X-MBX-APIKEY': API_KEY
}
url = f'{base_url}{endpoint}?{query_string}&signature={signature}'
response = requests.post(url, headers=headers)
return response.json()
# Show account balance
balance_response = get_account_balance()
if 'totalWalletBalance' in balance_response:
print(f"Total Wallet Balance: {balance_response['totalWalletBalance']} USDT")
else:
print("Failed to fetch account balance.")
# Create order with take profit of 1.5% and stop loss of 2%
symbol = 'BTCUSDT'
side = 'BUY' # Change this to 'SELL' if you're opening a short position
quantity = 0.01
leverage = 10 # Leverage x10
position_side = 'LONG' # Change this to 'SHORT' if opening a short position
take_profit_percent = 1.5
stop_loss_percent = 2.0
response = create_cross_order(symbol, side, quantity, leverage, position_side, take_profit_percent, stop_loss_percent)
if response is not None:
print(response)
@2pd @aisling11 @chairz @bnbot
- Ngôn ngữ chính
- Python
- Star
- 110
- Fork
- 22
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của binance/binance-toolbox-python
-
How to enable auto-reconnection?Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
Tất cả issue của binance/binance-toolbox-python
Issue tương tự
-
Harmony OPeNDAP SubSetter (HOSS) Geographic LARC_CLOUD PREFIRE_SAT2_AUX-SAT R01 production
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nasa/harmony-autotester#245 ·
-
feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
L: github:actions L: php:composer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
dependabot/dependabot-core#16493 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
2.3 EDA: `np.log` example adds +1 to every value, so it can't produce the `-inf` output shownĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
DataTalksClub/machine-learning-zoomcamp#730 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 4 ngày