mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 23:04:21 +01:00
Merge pull request #10 from itsdeka/fix-rest-feature
Fix mistakes in BfxRestInterface.py
This commit is contained in:
@@ -13,6 +13,7 @@ from .enums import Config, Sort, OrderType, FundingOfferType, Error
|
|||||||
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
|
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
|
||||||
|
|
||||||
from .. utils.encoder import JSONEncoder
|
from .. utils.encoder import JSONEncoder
|
||||||
|
from .. utils.cid import generate_unique_cid
|
||||||
|
|
||||||
class BfxRestInterface(object):
|
class BfxRestInterface(object):
|
||||||
def __init__(self, host, API_KEY = None, API_SECRET = None):
|
def __init__(self, host, API_KEY = None, API_SECRET = None):
|
||||||
@@ -62,9 +63,7 @@ class _Requests(object):
|
|||||||
if _append_authentication_headers:
|
if _append_authentication_headers:
|
||||||
headers = { **headers, **self.__build_authentication_headers(endpoint, data) }
|
headers = { **headers, **self.__build_authentication_headers(endpoint, data) }
|
||||||
|
|
||||||
data = (data and json.dumps({ key: value for key, value in data.items() if value != None}, cls=JSONEncoder) or None)
|
response = requests.post(f"{self.host}/{endpoint}", params=params, data=json.dumps(data, cls=JSONEncoder), headers=headers)
|
||||||
|
|
||||||
response = requests.post(f"{self.host}/{endpoint}", params=params, data=data, headers=headers)
|
|
||||||
|
|
||||||
if response.status_code == HTTPStatus.NOT_FOUND:
|
if response.status_code == HTTPStatus.NOT_FOUND:
|
||||||
raise ResourceNotFound(f"No resources found at endpoint <{endpoint}>.")
|
raise ResourceNotFound(f"No resources found at endpoint <{endpoint}>.")
|
||||||
@@ -248,29 +247,82 @@ class _RestAuthenticatedEndpoints(_Requests):
|
|||||||
def submit_order(self, type: OrderType, symbol: str, amount: Union[Decimal, str],
|
def submit_order(self, type: OrderType, symbol: str, amount: Union[Decimal, str],
|
||||||
price: Optional[Union[Decimal, str]] = None, lev: Optional[int] = None,
|
price: Optional[Union[Decimal, str]] = None, lev: Optional[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,
|
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[int] = None, cid: Optional[int] = None,
|
gid: Optional[int] = None,
|
||||||
flags: Optional[int] = 0, tif: Optional[Union[datetime, str]] = None, meta: Optional[JSON] = None) -> Notification:
|
flags: Optional[int] = 0, tif: Optional[Union[datetime, str]] = None, meta: Optional[JSON] = None) -> Notification:
|
||||||
|
cid = generate_unique_cid()
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"type": type, "symbol": symbol, "amount": amount,
|
"type": type, "symbol": symbol, "amount": str(amount), "price": str(price), "meta": meta, "cid": cid
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# add extra parameters
|
||||||
|
if flags:
|
||||||
|
data["flags"] = flags
|
||||||
|
|
||||||
|
if price_trailing:
|
||||||
|
data["price_trailing"] = str(price_trailing)
|
||||||
|
|
||||||
|
if price_aux_limit:
|
||||||
|
data["price_aux_limit"] = str(price_aux_limit)
|
||||||
|
|
||||||
|
if price_oco_stop:
|
||||||
|
data["oco_stop_price"] = str(price_oco_stop)
|
||||||
|
|
||||||
|
if tif:
|
||||||
|
data["tif"] = str(tif)
|
||||||
|
|
||||||
|
if gid:
|
||||||
|
data["gid"] = gid
|
||||||
|
|
||||||
|
if lev:
|
||||||
|
data["lev"] = str(lev)
|
||||||
|
|
||||||
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/submit", data=data))
|
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/submit", data=data))
|
||||||
|
|
||||||
def update_order(self, id: int, amount: Optional[Union[Decimal, str]] = None, price: Optional[Union[Decimal, str]] = None,
|
def update_order(self, id: int, amount: Optional[Union[Decimal, str]] = None,
|
||||||
|
price: Optional[Union[Decimal, str]] = None,
|
||||||
cid: Optional[int] = None, cid_date: Optional[str] = None, gid: Optional[int] = None,
|
cid: Optional[int] = None, cid_date: Optional[str] = None, gid: Optional[int] = None,
|
||||||
flags: Optional[int] = 0, lev: Optional[int] = None, delta: Optional[Union[Decimal, str]] = None,
|
flags: Optional[int] = 0, lev: Optional[int] = None, delta: Optional[Union[Decimal, str]] = None,
|
||||||
price_aux_limit: Optional[Union[Decimal, str]] = None, price_trailing: Optional[Union[Decimal, str]] = None, tif: Optional[Union[datetime, str]] = None) -> Notification:
|
price_aux_limit: Optional[Union[Decimal, str]] = None,
|
||||||
|
price_trailing: Optional[Union[Decimal, str]] = None,
|
||||||
|
tif: Optional[Union[datetime, str]] = None) -> Notification:
|
||||||
data = {
|
data = {
|
||||||
"id": id, "amount": amount, "price": price,
|
"id": id
|
||||||
"cid": cid, "cid_date": cid_date, "gid": gid,
|
|
||||||
"flags": flags, "lev": lev, "delta": delta,
|
|
||||||
"price_aux_limit": price_aux_limit, "price_trailing": price_trailing, "tif": tif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if amount:
|
||||||
|
data["amount"] = str(amount)
|
||||||
|
|
||||||
|
if price:
|
||||||
|
data["price"] = str(price)
|
||||||
|
|
||||||
|
if cid:
|
||||||
|
data["cid"] = cid
|
||||||
|
|
||||||
|
if cid_date:
|
||||||
|
data["cid_date"] = str(cid_date)
|
||||||
|
|
||||||
|
if gid:
|
||||||
|
data["gid"] = gid
|
||||||
|
|
||||||
|
if flags:
|
||||||
|
data["flags"] = flags
|
||||||
|
|
||||||
|
if lev:
|
||||||
|
data["lev"] = str(lev)
|
||||||
|
|
||||||
|
if delta:
|
||||||
|
data["deta"] = str(delta)
|
||||||
|
|
||||||
|
if price_aux_limit:
|
||||||
|
data["price_aux_limit"] = str(price_aux_limit)
|
||||||
|
|
||||||
|
if price_trailing:
|
||||||
|
data["price_trailing"] = str(price_trailing)
|
||||||
|
|
||||||
|
if tif:
|
||||||
|
data["tif"] = str(tif)
|
||||||
|
|
||||||
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/update", data=data))
|
return serializers._Notification(serializer=serializers.Order).parse(*self._POST("auth/w/order/update", data=data))
|
||||||
|
|
||||||
def cancel_order(self, id: Optional[int] = None, cid: Optional[int] = None, cid_date: Optional[str] = None) -> Notification:
|
def cancel_order(self, id: Optional[int] = None, cid: Optional[int] = None, cid_date: Optional[str] = None) -> Notification:
|
||||||
|
|||||||
Reference in New Issue
Block a user