У меня проблема с pybit v5. Если вы можете мне помочь, заранее спасибо.
from config_exucation import ticker_1
from config_exucation import ticker_2
from pybit.unified_trading import WebSocket
from func_calcultions import get_trade_details
from time import sleep
subs = [ticker_1, ticker_2]
# Websocket Start
ws_public = WebSocket(
testnet=True,
channel_type="linear",
)
def handle_message(message):
mid_price, stop_loss, quantity = get_trade_details(message, direction="Long", capital=1000)
print(mid_price, stop_loss, quantity)
ws_public.orderbook_stream(depth=50,symbol="BTCUSDT",callback=handle_message)
while True:
sleep(1)
Функция, которую я вызывал в разделе подключения, работает нормально. Здесь нет проблем.
Однако, когда я попытался импортировать свое веб-соединение в файл с другой функцией и использовать его с нужной функцией, я не получил никаких результатов.< /p>
Вот содержимое кода, которое я хочу использовать. Можете ли вы помочь мне, как использовать его здесь?
from config_exucation import stop_lose_fail_safe
from config_exucation import ticker_1
from config_exucation import rounding_ticker_1
from config_exucation import rounding_ticker_2
from config_exucation import quantity_rounding_ticker_1
from config_exucation import quantity_rounding_ticker_2
from time import sleep
import math
# Puts all close prices in a list
def extract_close_prices(prices):
close_prices = []
for price_values in prices:
if math.isnan(price_values["close"]):
return []
close_prices.append(price_values["close"])
return close_prices
# Get trade details and latest prices
def get_trade_details(orderbook, direction="Long", capital=0):
# Set calculation and output variables
price_rounding = 20
quantity_rounding = 20
mid_price = 0
quantity = 0
stop_loss = 0
bid_item_list = []
ask_items_list = []
# Get prices, stop loss and quantity
if orderbook:
# Set price rounding
price_rounding = rounding_ticker_1 if orderbook["data"]["s"] == ticker_1 else rounding_ticker_2
quantity_rounding = quantity_rounding_ticker_1 if orderbook["data"]["s"] == ticker_1 else quantity_rounding_ticker_2
# Organise prices
for bid, ask in zip(orderbook["data"]["b"], orderbook["data"]["a"]):
bid_item_list.append(float(bid[0])) # bid'in 0. indeksini alıyoruz
ask_items_list.append(float(ask[0])) # ask'in 0. indeksini alıyoruz
# print(f"Burası Alıcıların Olduğu Kısım.{bid_item_list}")
# print(f"Burasıda Satıcıların Oldugu Kısım.{ask_items_list}")
# Calculate price, size, stop loss and average liquidity
if len(ask_items_list) > 0 and len(bid_item_list) > 0:
# # Sort lists
# ask_items_list.sort()
# bid_item_list.sort()
# bid_item_list.reverse()
# Get nearest ask, nearest bid and orderbook spread
nearest_ask = ask_items_list[0]
nearest_bid = bid_item_list[0]
# print(f"Buradaki ilk değer listenin başından gelen değer olmalı.{nearest_ask} ve .{nearest_bid}")
# Calculate hard stop lose
if direction == "Long":
mid_price = nearest_bid # Placing at Bid has high probability of not being cancelled, but may not fill
stop_loss = round(mid_price * (1 - stop_lose_fail_safe), price_rounding)
else:
mid_price = nearest_ask # Placing at Ask has high probability of not being cancelled, but may not fill
stop_loss = round(mid_price * (1 + stop_lose_fail_safe), price_rounding)
# Calculate quantity
quantity = round(capital / mid_price, quantity_rounding)
# Output result
return (mid_price, stop_loss, quantity)
Подробнее здесь: https://stackoverflow.com/questions/793 ... ernal-call
Внешний вызов веб-сокета pybit ⇐ Python
Программы на Python
1736270172
Anonymous
У меня проблема с pybit v5. Если вы можете мне помочь, заранее спасибо.
from config_exucation import ticker_1
from config_exucation import ticker_2
from pybit.unified_trading import WebSocket
from func_calcultions import get_trade_details
from time import sleep
subs = [ticker_1, ticker_2]
# Websocket Start
ws_public = WebSocket(
testnet=True,
channel_type="linear",
)
def handle_message(message):
mid_price, stop_loss, quantity = get_trade_details(message, direction="Long", capital=1000)
print(mid_price, stop_loss, quantity)
ws_public.orderbook_stream(depth=50,symbol="BTCUSDT",callback=handle_message)
while True:
sleep(1)
Функция, которую я вызывал в разделе подключения, работает нормально. Здесь нет проблем.
Однако, когда я попытался импортировать свое веб-соединение в файл с другой функцией и использовать его с нужной функцией, я не получил никаких результатов.< /p>
Вот содержимое кода, которое я хочу использовать. Можете ли вы помочь мне, как использовать его здесь?
from config_exucation import stop_lose_fail_safe
from config_exucation import ticker_1
from config_exucation import rounding_ticker_1
from config_exucation import rounding_ticker_2
from config_exucation import quantity_rounding_ticker_1
from config_exucation import quantity_rounding_ticker_2
from time import sleep
import math
# Puts all close prices in a list
def extract_close_prices(prices):
close_prices = []
for price_values in prices:
if math.isnan(price_values["close"]):
return []
close_prices.append(price_values["close"])
return close_prices
# Get trade details and latest prices
def get_trade_details(orderbook, direction="Long", capital=0):
# Set calculation and output variables
price_rounding = 20
quantity_rounding = 20
mid_price = 0
quantity = 0
stop_loss = 0
bid_item_list = []
ask_items_list = []
# Get prices, stop loss and quantity
if orderbook:
# Set price rounding
price_rounding = rounding_ticker_1 if orderbook["data"]["s"] == ticker_1 else rounding_ticker_2
quantity_rounding = quantity_rounding_ticker_1 if orderbook["data"]["s"] == ticker_1 else quantity_rounding_ticker_2
# Organise prices
for bid, ask in zip(orderbook["data"]["b"], orderbook["data"]["a"]):
bid_item_list.append(float(bid[0])) # bid'in 0. indeksini alıyoruz
ask_items_list.append(float(ask[0])) # ask'in 0. indeksini alıyoruz
# print(f"Burası Alıcıların Olduğu Kısım.{bid_item_list}")
# print(f"Burasıda Satıcıların Oldugu Kısım.{ask_items_list}")
# Calculate price, size, stop loss and average liquidity
if len(ask_items_list) > 0 and len(bid_item_list) > 0:
# # Sort lists
# ask_items_list.sort()
# bid_item_list.sort()
# bid_item_list.reverse()
# Get nearest ask, nearest bid and orderbook spread
nearest_ask = ask_items_list[0]
nearest_bid = bid_item_list[0]
# print(f"Buradaki ilk değer listenin başından gelen değer olmalı.{nearest_ask} ve .{nearest_bid}")
# Calculate hard stop lose
if direction == "Long":
mid_price = nearest_bid # Placing at Bid has high probability of not being cancelled, but may not fill
stop_loss = round(mid_price * (1 - stop_lose_fail_safe), price_rounding)
else:
mid_price = nearest_ask # Placing at Ask has high probability of not being cancelled, but may not fill
stop_loss = round(mid_price * (1 + stop_lose_fail_safe), price_rounding)
# Calculate quantity
quantity = round(capital / mid_price, quantity_rounding)
# Output result
return (mid_price, stop_loss, quantity)
Подробнее здесь: [url]https://stackoverflow.com/questions/79336816/pybit-websocket-external-call[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия