mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Add example to submit, cancel, edit order and adjust issue in labeler.py
This commit is contained in:
@@ -9,11 +9,9 @@ from typing import List, Union, Literal, Optional, Any, cast
|
||||
from . import serializers
|
||||
|
||||
from .typings import *
|
||||
from .enums import Config, Precision, Sort, OrderType, FundingOfferType, Error
|
||||
from .enums import Config, Sort, OrderType, FundingOfferType, Error
|
||||
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
|
||||
|
||||
from .. utils.integers import Int16, int32, int45, int64
|
||||
|
||||
from .. utils.encoder import JSONEncoder
|
||||
|
||||
class BfxRestInterface(object):
|
||||
@@ -64,7 +62,9 @@ class _Requests(object):
|
||||
if _append_authentication_headers:
|
||||
headers = { **headers, **self.__build_authentication_headers(endpoint, data) }
|
||||
|
||||
response = requests.post(f"{self.host}/{endpoint}", params=params, data=json.dumps(data, cls=JSONEncoder), headers=headers)
|
||||
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=data, headers=headers)
|
||||
|
||||
if response.status_code == HTTPStatus.NOT_FOUND:
|
||||
raise ResourceNotFound(f"No resources found at endpoint <{endpoint}>.")
|
||||
|
||||
4
bfxapi/utils/cid.py
Normal file
4
bfxapi/utils/cid.py
Normal file
@@ -0,0 +1,4 @@
|
||||
import time
|
||||
|
||||
def generate_unique_cid(multiplier: int = 1000) -> int:
|
||||
return int(round(time.time() * multiplier))
|
||||
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
|
||||
from bfxapi.client import Client, Constants
|
||||
from bfxapi.enums import FundingOfferType
|
||||
from bfxapi.utils.flags import calculate_offer_flags
|
||||
from bfxapi.rest.typings import List, FundingOffer, Notification
|
||||
|
||||
bfx = Client(
|
||||
REST_HOST=Constants.REST_HOST,
|
||||
@@ -10,8 +10,8 @@ bfx = Client(
|
||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
||||
)
|
||||
|
||||
notification: Notification = bfx.rest.auth.submit_funding_offer(
|
||||
type="LIMIT",
|
||||
notification = bfx.rest.auth.submit_funding_offer(
|
||||
type=FundingOfferType.LIMIT,
|
||||
symbol="fUSD",
|
||||
amount="123.45",
|
||||
rate="0.001",
|
||||
@@ -21,6 +21,6 @@ notification: Notification = bfx.rest.auth.submit_funding_offer(
|
||||
|
||||
print("Offer notification:", notification)
|
||||
|
||||
offers: List[FundingOffer] = bfx.rest.auth.get_active_funding_offers()
|
||||
offers = bfx.rest.auth.get_active_funding_offers()
|
||||
|
||||
print("Offers:", offers)
|
||||
36
examples/rest/create_order.py
Normal file
36
examples/rest/create_order.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
|
||||
from bfxapi.client import Client, Constants
|
||||
from bfxapi.enums import OrderType
|
||||
from bfxapi.utils.flags import calculate_order_flags
|
||||
|
||||
bfx = Client(
|
||||
REST_HOST=Constants.REST_HOST,
|
||||
API_KEY=os.getenv("BFX_API_KEY"),
|
||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
||||
)
|
||||
|
||||
# Create a new order
|
||||
submitted_order = bfx.rest.auth.submit_order(
|
||||
type=OrderType.EXCHANGE_LIMIT,
|
||||
symbol="tBTCUST",
|
||||
amount="0.015",
|
||||
price="10000",
|
||||
flags=calculate_order_flags(hidden=False)
|
||||
)
|
||||
|
||||
print("Submit Order Notification:", submitted_order)
|
||||
|
||||
# Update it
|
||||
updated_order = bfx.rest.auth.update_order(
|
||||
id=submitted_order["NOTIFY_INFO"]["ID"],
|
||||
amount="0.020",
|
||||
price="10100"
|
||||
)
|
||||
|
||||
print("Update Order Notification:", updated_order)
|
||||
|
||||
# Delete it
|
||||
canceled_order = bfx.rest.auth.cancel_order(id=submitted_order["NOTIFY_INFO"]["ID"])
|
||||
|
||||
print("Cancel Order Notification:", canceled_order)
|
||||
Reference in New Issue
Block a user