diff --git a/bfxapi/rest/BfxRestInterface.py b/bfxapi/rest/BfxRestInterface.py index 8fc5b07..6af32a4 100644 --- a/bfxapi/rest/BfxRestInterface.py +++ b/bfxapi/rest/BfxRestInterface.py @@ -7,7 +7,7 @@ from typing import List, Union, Literal, Optional, Any, cast from . import serializers from .typings import * -from .enums import Config, Precision, Sort +from .enums import OrderType, Config, Precision, Sort from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError class BfxRestInterface(object): @@ -47,8 +47,8 @@ class _Requests(object): if data[1] == 10020: raise RequestParametersError(f"The request was rejected with the following parameter error: <{data[2]}>") - if data[1] == None: - raise UnknownGenericError("The server replied to the request with a generic error.") + if data[1] == None or data[1] == 10000 or data[1] == 10001: + raise UnknownGenericError("The server replied to the request with a generic error with message: <{data[2]}>.") return data @@ -72,8 +72,8 @@ class _Requests(object): if data[1] == 10100: raise InvalidAuthenticationCredentials("Cannot authenticate with given API-KEY and API-SECRET.") - if data[1] == None: - raise UnknownGenericError("The server replied to the request with a generic error.") + if data[1] == None or data[1] == 10000 or data[1] == 10001: + raise UnknownGenericError(f"The server replied to the request with a generic error with message: <{data[2]}>.") return data @@ -237,4 +237,19 @@ class _RestAuthenticatedEndpoints(_Requests): return [ serializers.Wallet.parse(*subdata) for subdata in self._POST("auth/r/wallets") ] def retrieve_orders(self, ids: Optional[List[str]] = None) -> List[Order]: - return [ serializers.Order.parse(*subdata) for subdata in self._POST("auth/r/orders", data={ "id": ids }) ] \ No newline at end of file + return [ serializers.Order.parse(*subdata) for subdata in self._POST("auth/r/orders", data={ "id": ids }) ] + + def submit_order(self, type: OrderType, symbol: str, amount: Union[Decimal, str], + price: Optional[Union[Decimal, str]] = None, lev: Optional[Union[Int32, int]] = None, + price_trailing: Optional[Union[Decimal, str]] = None, price_aux_limit: Optional[Union[Decimal, str]] = None, price_oco_stop: Optional[Union[Decimal, str]] = None, + gid: Optional[Union[Int32, int]] = None, cid: Optional[Union[Int45, int]] = None, + flags: Optional[Union[Int16, int]] = None, tif: Optional[Union[datetime, str]] = None, meta: Optional[JSON] = None) -> Notification: + data = { + "type": type, "symbol": symbol, "amount": amount, + "price": price, "lev": lev, + "price_trailing": price_trailing, "price_aux_limit": price_aux_limit, "price_oco_stop": price_oco_stop, + "gid": gid, "cid": cid, + "flags": flags, "tif": tif, "meta": meta + } + + return self._POST("auth/w/order/submit", data=data) \ No newline at end of file diff --git a/bfxapi/rest/enums.py b/bfxapi/rest/enums.py index 70c2336..e1e3f49 100644 --- a/bfxapi/rest/enums.py +++ b/bfxapi/rest/enums.py @@ -1,5 +1,21 @@ from enum import Enum +class OrderType(str, Enum): + LIMIT = "LIMIT" + EXCHANGE_LIMIT = "EXCHANGE LIMIT" + MARKET = "MARKET" + EXCHANGE_MARKET = "EXCHANGE MARKET" + STOP = "STOP" + EXCHANGE_STOP = "EXCHANGE STOP" + STOP_LIMIT = "STOP LIMIT" + EXCHANGE_STOP_LIMIT = "EXCHANGE STOP LIMIT" + TRAILING_STOP = "TRAILING STOP" + EXCHANGE_TRAILING_STOP = "EXCHANGE TRAILING STOP" + FOK = "FOK" + EXCHANGE_FOK = "EXCHANGE FOK" + IOC = "IOC" + EXCHANGE_IOC = "EXCHANGE IOC" + class Config(str, Enum): MAP_CURRENCY_SYM = "pub:map:currency:sym" MAP_CURRENCY_LABEL = "pub:map:currency:label" diff --git a/bfxapi/rest/serializers.py b/bfxapi/rest/serializers.py index 70f0887..fe7d5a7 100644 --- a/bfxapi/rest/serializers.py +++ b/bfxapi/rest/serializers.py @@ -232,7 +232,6 @@ Order = _Serializer[typings.Order]("Order", labels=[ "META" ]) - #endregion #region Serializers definition for Notifications channel