mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
Fix bug regarding new typing with dataclasses.
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
from .exceptions import LabelerSerializerException
|
||||
|
||||
from typing import Generic, TypeVar, Iterable, Optional, List, Tuple, Any, cast
|
||||
from typing import Type, Generic, TypeVar, Iterable, Optional, List, Tuple, Any, cast
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
class _Type(object):
|
||||
def __init__(self, **kwargs):
|
||||
for key, value in kwargs.items():
|
||||
self.__setattr__(key,value)
|
||||
self.__setattr__(key, value)
|
||||
|
||||
class _Serializer(Generic[T]):
|
||||
def __init__(self, name: str, labels: List[str], IGNORE: List[str] = [ "_PLACEHOLDER" ]):
|
||||
self.name, self.__labels, self.__IGNORE = name, labels, IGNORE
|
||||
def __init__(self, name: str, klass: Type[_Type], labels: List[str], IGNORE: List[str] = [ "_PLACEHOLDER" ]):
|
||||
self.name, self.klass, self.__labels, self.__IGNORE = name, klass, labels, IGNORE
|
||||
|
||||
def _serialize(self, *args: Any, skip: Optional[List[str]] = None) -> Iterable[Tuple[str, Any]]:
|
||||
labels = list(filter(lambda label: label not in (skip or list()), self.__labels))
|
||||
@@ -24,4 +24,7 @@ class _Serializer(Generic[T]):
|
||||
yield label, args[index]
|
||||
|
||||
def parse(self, *values: Any, skip: Optional[List[str]] = None) -> T:
|
||||
return cast(T, _Type(**dict(self._serialize(*values, skip=skip))))
|
||||
return cast(T, self.klass(**dict(self._serialize(*values, skip=skip))))
|
||||
|
||||
def generate_labeler_serializer(name: str, klass: T, labels: List[str], IGNORE: List[str] = [ "_PLACEHOLDER" ]) -> _Serializer[T]:
|
||||
return _Serializer[T](name, klass, labels, IGNORE)
|
||||
@@ -20,12 +20,12 @@ class _Notification(_Serializer, Generic[T]):
|
||||
__LABELS = [ "MTS", "TYPE", "MESSAGE_ID", "_PLACEHOLDER", "NOTIFY_INFO", "CODE", "STATUS", "TEXT" ]
|
||||
|
||||
def __init__(self, serializer: Optional[_Serializer] = None, iterate: bool = False):
|
||||
super().__init__("Notification", _Notification.__LABELS, IGNORE = [ "_PLACEHOLDER" ])
|
||||
super().__init__("Notification", Notification, _Notification.__LABELS, IGNORE = [ "_PLACEHOLDER" ])
|
||||
|
||||
self.serializer, self.iterate = serializer, iterate
|
||||
|
||||
def parse(self, *values: Any, skip: Optional[List[str]] = None) -> Notification[T]:
|
||||
notification = cast(Notification[T], _Type(**dict(self._serialize(*values))))
|
||||
notification = cast(Notification[T], Notification(**dict(self._serialize(*values))))
|
||||
|
||||
if isinstance(self.serializer, _Serializer):
|
||||
NOTIFY_INFO = cast(List[Any], notification.NOTIFY_INFO)
|
||||
@@ -34,7 +34,7 @@ class _Notification(_Serializer, Generic[T]):
|
||||
if len(NOTIFY_INFO) == 1 and isinstance(NOTIFY_INFO[0], list):
|
||||
NOTIFY_INFO = NOTIFY_INFO[0]
|
||||
|
||||
notification.NOTIFY_INFO = cast(T, _Type(**dict(self.serializer._serialize(*NOTIFY_INFO, skip=skip))))
|
||||
else: notification.NOTIFY_INFO = cast(T, [ _Type(**dict(self.serializer._serialize(*data, skip=skip))) for data in NOTIFY_INFO ])
|
||||
notification.NOTIFY_INFO = cast(T, self.serializer.klass(**dict(self.serializer._serialize(*NOTIFY_INFO, skip=skip))))
|
||||
else: notification.NOTIFY_INFO = cast(T, [ self.serializer.klass(**dict(self.serializer._serialize(*data, skip=skip))) for data in NOTIFY_INFO ])
|
||||
|
||||
return notification
|
||||
@@ -1,16 +1,16 @@
|
||||
from . import types
|
||||
|
||||
from .. labeler import _Serializer
|
||||
from .. labeler import generate_labeler_serializer
|
||||
|
||||
from .. notification import _Notification
|
||||
|
||||
#region Serializers definition for Rest Public Endpoints
|
||||
|
||||
PlatformStatus = _Serializer[types.PlatformStatus]("PlatformStatus", labels=[
|
||||
PlatformStatus = generate_labeler_serializer("PlatformStatus", klass=types.PlatformStatus, labels=[
|
||||
"OPERATIVE"
|
||||
])
|
||||
|
||||
TradingPairTicker = _Serializer[types.TradingPairTicker]("TradingPairTicker", labels=[
|
||||
TradingPairTicker = generate_labeler_serializer("TradingPairTicker", klass=types.TradingPairTicker, labels=[
|
||||
"SYMBOL",
|
||||
"BID",
|
||||
"BID_SIZE",
|
||||
@@ -24,7 +24,7 @@ TradingPairTicker = _Serializer[types.TradingPairTicker]("TradingPairTicker", la
|
||||
"LOW"
|
||||
])
|
||||
|
||||
FundingCurrencyTicker = _Serializer[types.FundingCurrencyTicker]("FundingCurrencyTicker", labels=[
|
||||
FundingCurrencyTicker = generate_labeler_serializer("FundingCurrencyTicker", klass=types.FundingCurrencyTicker, labels=[
|
||||
"SYMBOL",
|
||||
"FRR",
|
||||
"BID",
|
||||
@@ -44,7 +44,7 @@ FundingCurrencyTicker = _Serializer[types.FundingCurrencyTicker]("FundingCurrenc
|
||||
"FRR_AMOUNT_AVAILABLE"
|
||||
])
|
||||
|
||||
TickersHistory = _Serializer[types.TickersHistory]("TickersHistory", labels=[
|
||||
TickersHistory = generate_labeler_serializer("TickersHistory", klass=types.TickersHistory, labels=[
|
||||
"SYMBOL",
|
||||
"BID",
|
||||
"_PLACEHOLDER",
|
||||
@@ -60,14 +60,14 @@ TickersHistory = _Serializer[types.TickersHistory]("TickersHistory", labels=[
|
||||
"MTS"
|
||||
])
|
||||
|
||||
TradingPairTrade = _Serializer[types.TradingPairTrade]("TradingPairTrade", labels=[
|
||||
TradingPairTrade = generate_labeler_serializer("TradingPairTrade", klass=types.TradingPairTrade, labels=[
|
||||
"ID",
|
||||
"MTS",
|
||||
"AMOUNT",
|
||||
"PRICE"
|
||||
])
|
||||
|
||||
FundingCurrencyTrade = _Serializer[types.FundingCurrencyTrade]("FundingCurrencyTrade", labels=[
|
||||
FundingCurrencyTrade = generate_labeler_serializer("FundingCurrencyTrade", klass=types.FundingCurrencyTrade, labels=[
|
||||
"ID",
|
||||
"MTS",
|
||||
"AMOUNT",
|
||||
@@ -75,38 +75,38 @@ FundingCurrencyTrade = _Serializer[types.FundingCurrencyTrade]("FundingCurrencyT
|
||||
"PERIOD"
|
||||
])
|
||||
|
||||
TradingPairBook = _Serializer[types.TradingPairBook]("TradingPairBook", labels=[
|
||||
TradingPairBook = generate_labeler_serializer("TradingPairBook", klass=types.TradingPairBook, labels=[
|
||||
"PRICE",
|
||||
"COUNT",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
FundingCurrencyBook = _Serializer[types.FundingCurrencyBook]("FundingCurrencyBook", labels=[
|
||||
FundingCurrencyBook = generate_labeler_serializer("FundingCurrencyBook", klass=types.FundingCurrencyBook, labels=[
|
||||
"RATE",
|
||||
"PERIOD",
|
||||
"COUNT",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
TradingPairRawBook = _Serializer[types.TradingPairRawBook]("TradingPairRawBook", labels=[
|
||||
TradingPairRawBook = generate_labeler_serializer("TradingPairRawBook", klass=types.TradingPairRawBook, labels=[
|
||||
"ORDER_ID",
|
||||
"PRICE",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
FundingCurrencyRawBook = _Serializer[types.FundingCurrencyRawBook]("FundingCurrencyRawBook", labels=[
|
||||
FundingCurrencyRawBook = generate_labeler_serializer("FundingCurrencyRawBook", klass=types.FundingCurrencyRawBook, labels=[
|
||||
"OFFER_ID",
|
||||
"PERIOD",
|
||||
"RATE",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
Statistic = _Serializer[types.Statistic]("Statistic", labels=[
|
||||
Statistic = generate_labeler_serializer("Statistic", klass=types.Statistic, labels=[
|
||||
"MTS",
|
||||
"VALUE"
|
||||
])
|
||||
|
||||
Candle = _Serializer[types.Candle]("Candle", labels=[
|
||||
Candle = generate_labeler_serializer("Candle", klass=types.Candle, labels=[
|
||||
"MTS",
|
||||
"OPEN",
|
||||
"CLOSE",
|
||||
@@ -115,7 +115,7 @@ Candle = _Serializer[types.Candle]("Candle", labels=[
|
||||
"VOLUME"
|
||||
])
|
||||
|
||||
DerivativesStatus = _Serializer[types.DerivativesStatus]("DerivativesStatus", labels=[
|
||||
DerivativesStatus = generate_labeler_serializer("DerivativesStatus", klass=types.DerivativesStatus, labels=[
|
||||
"KEY",
|
||||
"MTS",
|
||||
"_PLACEHOLDER",
|
||||
@@ -142,7 +142,7 @@ DerivativesStatus = _Serializer[types.DerivativesStatus]("DerivativesStatus", la
|
||||
"CLAMP_MAX"
|
||||
])
|
||||
|
||||
Liquidation = _Serializer[types.Liquidation]("Liquidation", labels=[
|
||||
Liquidation = generate_labeler_serializer("Liquidation", klass=types.Liquidation, labels=[
|
||||
"_PLACEHOLDER",
|
||||
"POS_ID",
|
||||
"MTS",
|
||||
@@ -157,7 +157,7 @@ Liquidation = _Serializer[types.Liquidation]("Liquidation", labels=[
|
||||
"PRICE_ACQUIRED"
|
||||
])
|
||||
|
||||
Leaderboard = _Serializer[types.Leaderboard]("Leaderboard", labels=[
|
||||
Leaderboard = generate_labeler_serializer("Leaderboard", klass=types.Leaderboard, labels=[
|
||||
"MTS",
|
||||
"_PLACEHOLDER",
|
||||
"USERNAME",
|
||||
@@ -170,7 +170,7 @@ Leaderboard = _Serializer[types.Leaderboard]("Leaderboard", labels=[
|
||||
"TWITTER_HANDLE"
|
||||
])
|
||||
|
||||
FundingStatistic = _Serializer[types.FundingStatistic]("FundingStatistic", labels=[
|
||||
FundingStatistic = generate_labeler_serializer("FundingStatistic", klass=types.FundingStatistic, labels=[
|
||||
"TIMESTAMP",
|
||||
"_PLACEHOLDER",
|
||||
"_PLACEHOLDER",
|
||||
@@ -189,7 +189,7 @@ FundingStatistic = _Serializer[types.FundingStatistic]("FundingStatistic", label
|
||||
|
||||
#region Serializers definition for Rest Authenticated Endpoints
|
||||
|
||||
Wallet = _Serializer[types.Wallet]("Wallet", labels=[
|
||||
Wallet = generate_labeler_serializer("Wallet", klass=types.Wallet, labels=[
|
||||
"WALLET_TYPE",
|
||||
"CURRENCY",
|
||||
"BALANCE",
|
||||
@@ -199,7 +199,7 @@ Wallet = _Serializer[types.Wallet]("Wallet", labels=[
|
||||
"TRADE_DETAILS"
|
||||
])
|
||||
|
||||
Order = _Serializer[types.Order]("Order", labels=[
|
||||
Order = generate_labeler_serializer("Order", klass=types.Order, labels=[
|
||||
"ID",
|
||||
"GID",
|
||||
"CID",
|
||||
@@ -234,7 +234,7 @@ Order = _Serializer[types.Order]("Order", labels=[
|
||||
"META"
|
||||
])
|
||||
|
||||
Position = _Serializer[types.Position]("Position", labels=[
|
||||
Position = generate_labeler_serializer("Position", klass=types.Position, labels=[
|
||||
"SYMBOL",
|
||||
"STATUS",
|
||||
"AMOUNT",
|
||||
@@ -257,7 +257,7 @@ Position = _Serializer[types.Position]("Position", labels=[
|
||||
"META"
|
||||
])
|
||||
|
||||
FundingOffer = _Serializer[types.FundingOffer]("FundingOffer", labels=[
|
||||
FundingOffer = generate_labeler_serializer("FundingOffer", klass=types.FundingOffer, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"MTS_CREATED",
|
||||
@@ -281,7 +281,7 @@ FundingOffer = _Serializer[types.FundingOffer]("FundingOffer", labels=[
|
||||
"_PLACEHOLDER"
|
||||
])
|
||||
|
||||
Trade = _Serializer[types.Trade]("Trade", labels=[
|
||||
Trade = generate_labeler_serializer("Trade", klass=types.Trade, labels=[
|
||||
"ID",
|
||||
"PAIR",
|
||||
"MTS_CREATE",
|
||||
@@ -296,7 +296,7 @@ Trade = _Serializer[types.Trade]("Trade", labels=[
|
||||
"CID"
|
||||
])
|
||||
|
||||
OrderTrade = _Serializer[types.OrderTrade]("OrderTrade", labels=[
|
||||
OrderTrade = generate_labeler_serializer("OrderTrade", klass=types.OrderTrade, labels=[
|
||||
"ID",
|
||||
"PAIR",
|
||||
"MTS_CREATE",
|
||||
@@ -311,7 +311,7 @@ OrderTrade = _Serializer[types.OrderTrade]("OrderTrade", labels=[
|
||||
"CID"
|
||||
])
|
||||
|
||||
Ledger = _Serializer[types.Ledger]("Ledger", labels=[
|
||||
Ledger = generate_labeler_serializer("Ledger", klass=types.Ledger, labels=[
|
||||
"ID",
|
||||
"CURRENCY",
|
||||
"_PLACEHOLDER",
|
||||
@@ -323,7 +323,7 @@ Ledger = _Serializer[types.Ledger]("Ledger", labels=[
|
||||
"DESCRIPTION"
|
||||
])
|
||||
|
||||
FundingCredit = _Serializer[types.FundingCredit]("FundingCredit", labels=[
|
||||
FundingCredit = generate_labeler_serializer("FundingCredit", klass=types.FundingCredit, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"SIDE",
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from . import types
|
||||
|
||||
from .. labeler import _Serializer
|
||||
from .. labeler import generate_labeler_serializer
|
||||
|
||||
from .. notification import _Notification
|
||||
|
||||
#region Serializers definition for Websocket Public Channels
|
||||
|
||||
TradingPairTicker = _Serializer[types.TradingPairTicker]("TradingPairTicker", labels=[
|
||||
TradingPairTicker = generate_labeler_serializer("TradingPairTicker", klass=types.TradingPairTicker, labels=[
|
||||
"BID",
|
||||
"BID_SIZE",
|
||||
"ASK",
|
||||
@@ -19,7 +19,7 @@ TradingPairTicker = _Serializer[types.TradingPairTicker]("TradingPairTicker", la
|
||||
"LOW"
|
||||
])
|
||||
|
||||
FundingCurrencyTicker = _Serializer[types.FundingCurrencyTicker]("FundingCurrencyTicker", labels=[
|
||||
FundingCurrencyTicker = generate_labeler_serializer("FundingCurrencyTicker", klass=types.FundingCurrencyTicker, labels=[
|
||||
"FRR",
|
||||
"BID",
|
||||
"BID_PERIOD",
|
||||
@@ -38,14 +38,14 @@ FundingCurrencyTicker = _Serializer[types.FundingCurrencyTicker]("FundingCurrenc
|
||||
"FRR_AMOUNT_AVAILABLE"
|
||||
])
|
||||
|
||||
TradingPairTrade = _Serializer[types.TradingPairTrade]("TradingPairTrade", labels=[
|
||||
TradingPairTrade = generate_labeler_serializer("TradingPairTrade", klass=types.TradingPairTrade, labels=[
|
||||
"ID",
|
||||
"MTS",
|
||||
"AMOUNT",
|
||||
"PRICE"
|
||||
])
|
||||
|
||||
FundingCurrencyTrade = _Serializer[types.FundingCurrencyTrade]("FundingCurrencyTrade", labels=[
|
||||
FundingCurrencyTrade = generate_labeler_serializer("FundingCurrencyTrade", klass=types.FundingCurrencyTrade, labels=[
|
||||
"ID",
|
||||
"MTS",
|
||||
"AMOUNT",
|
||||
@@ -53,33 +53,33 @@ FundingCurrencyTrade = _Serializer[types.FundingCurrencyTrade]("FundingCurrencyT
|
||||
"PERIOD"
|
||||
])
|
||||
|
||||
TradingPairBook = _Serializer[types.TradingPairBook]("TradingPairBook", labels=[
|
||||
TradingPairBook = generate_labeler_serializer("TradingPairBook", klass=types.TradingPairBook, labels=[
|
||||
"PRICE",
|
||||
"COUNT",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
FundingCurrencyBook = _Serializer[types.FundingCurrencyBook]("FundingCurrencyBook", labels=[
|
||||
FundingCurrencyBook = generate_labeler_serializer("FundingCurrencyBook", klass=types.FundingCurrencyBook, labels=[
|
||||
"RATE",
|
||||
"PERIOD",
|
||||
"COUNT",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
TradingPairRawBook = _Serializer[types.TradingPairRawBook]("TradingPairRawBook", labels=[
|
||||
TradingPairRawBook = generate_labeler_serializer("TradingPairRawBook", klass=types.TradingPairRawBook, labels=[
|
||||
"ORDER_ID",
|
||||
"PRICE",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
FundingCurrencyRawBook = _Serializer[types.FundingCurrencyRawBook]("FundingCurrencyRawBook", labels=[
|
||||
FundingCurrencyRawBook = generate_labeler_serializer("FundingCurrencyRawBook", klass=types.FundingCurrencyRawBook, labels=[
|
||||
"OFFER_ID",
|
||||
"PERIOD",
|
||||
"RATE",
|
||||
"AMOUNT"
|
||||
])
|
||||
|
||||
Candle = _Serializer[types.Candle]("Candle", labels=[
|
||||
Candle = generate_labeler_serializer("Candle", klass=types.Candle, labels=[
|
||||
"MTS",
|
||||
"OPEN",
|
||||
"CLOSE",
|
||||
@@ -88,7 +88,7 @@ Candle = _Serializer[types.Candle]("Candle", labels=[
|
||||
"VOLUME"
|
||||
])
|
||||
|
||||
DerivativesStatus = _Serializer[types.DerivativesStatus]("DerivativesStatus", labels=[
|
||||
DerivativesStatus = generate_labeler_serializer("DerivativesStatus", klass=types.DerivativesStatus, labels=[
|
||||
"TIME_MS",
|
||||
"_PLACEHOLDER",
|
||||
"DERIV_PRICE",
|
||||
@@ -118,7 +118,7 @@ DerivativesStatus = _Serializer[types.DerivativesStatus]("DerivativesStatus", la
|
||||
|
||||
#region Serializers definition for Websocket Authenticated Channels
|
||||
|
||||
Order = _Serializer[types.Order]("Order", labels=[
|
||||
Order = generate_labeler_serializer("Order", klass=types.Order, labels=[
|
||||
"ID",
|
||||
"GID",
|
||||
"CID",
|
||||
@@ -153,7 +153,7 @@ Order = _Serializer[types.Order]("Order", labels=[
|
||||
"META"
|
||||
])
|
||||
|
||||
Position = _Serializer[types.Position]("Position", labels=[
|
||||
Position = generate_labeler_serializer("Position", klass=types.Position, labels=[
|
||||
"SYMBOL",
|
||||
"STATUS",
|
||||
"AMOUNT",
|
||||
@@ -176,7 +176,7 @@ Position = _Serializer[types.Position]("Position", labels=[
|
||||
"META"
|
||||
])
|
||||
|
||||
TradeExecuted = _Serializer[types.TradeExecuted]("TradeExecuted", labels=[
|
||||
TradeExecuted = generate_labeler_serializer("TradeExecuted", klass=types.TradeExecuted, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"MTS_CREATE",
|
||||
@@ -191,7 +191,7 @@ TradeExecuted = _Serializer[types.TradeExecuted]("TradeExecuted", labels=[
|
||||
"CID"
|
||||
])
|
||||
|
||||
TradeExecutionUpdate = _Serializer[types.TradeExecutionUpdate]("TradeExecutionUpdate", labels=[
|
||||
TradeExecutionUpdate = generate_labeler_serializer("TradeExecutionUpdate", klass=types.TradeExecutionUpdate, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"MTS_CREATE",
|
||||
@@ -206,7 +206,7 @@ TradeExecutionUpdate = _Serializer[types.TradeExecutionUpdate]("TradeExecutionUp
|
||||
"CID"
|
||||
])
|
||||
|
||||
FundingOffer = _Serializer[types.FundingOffer]("FundingOffer", labels=[
|
||||
FundingOffer = generate_labeler_serializer("FundingOffer", klass=types.FundingOffer, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"MTS_CREATED",
|
||||
@@ -230,7 +230,7 @@ FundingOffer = _Serializer[types.FundingOffer]("FundingOffer", labels=[
|
||||
"_PLACEHOLDER"
|
||||
])
|
||||
|
||||
FundingCredit = _Serializer[types.FundingCredit]("FundingCredit", labels=[
|
||||
FundingCredit = generate_labeler_serializer("FundingCredit", klass=types.FundingCredit, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"SIDE",
|
||||
@@ -255,7 +255,7 @@ FundingCredit = _Serializer[types.FundingCredit]("FundingCredit", labels=[
|
||||
"POSITION_PAIR"
|
||||
])
|
||||
|
||||
FundingLoan = _Serializer[types.FundingLoan]("FundingLoan", labels=[
|
||||
FundingLoan = generate_labeler_serializer("FundingLoan", klass=types.FundingLoan, labels=[
|
||||
"ID",
|
||||
"SYMBOL",
|
||||
"SIDE",
|
||||
@@ -279,7 +279,7 @@ FundingLoan = _Serializer[types.FundingLoan]("FundingLoan", labels=[
|
||||
"NO_CLOSE"
|
||||
])
|
||||
|
||||
Wallet = _Serializer[types.Wallet]("Wallet", labels=[
|
||||
Wallet = generate_labeler_serializer("Wallet", klass=types.Wallet, labels=[
|
||||
"WALLET_TYPE",
|
||||
"CURRENCY",
|
||||
"BALANCE",
|
||||
@@ -289,7 +289,7 @@ Wallet = _Serializer[types.Wallet]("Wallet", labels=[
|
||||
"META"
|
||||
])
|
||||
|
||||
BalanceInfo = _Serializer[types.BalanceInfo]("BalanceInfo", labels=[
|
||||
BalanceInfo = generate_labeler_serializer("BalanceInfo", klass=types.BalanceInfo, labels=[
|
||||
"AUM",
|
||||
"AUM_NET",
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user