Внешний вызов веб-сокета pybitPython

Программы на Python
Ответить
Anonymous
 Внешний вызов веб-сокета pybit

Сообщение 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)


Подробнее здесь: https://stackoverflow.com/questions/793 ... ernal-call
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»