Skip to content

Commit

Permalink
Python SDK: Add direct fill support #51
Browse files Browse the repository at this point in the history
  • Loading branch information
4TT1L4 committed May 28, 2024
1 parent a77b544 commit 7cb1aab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
31 changes: 22 additions & 9 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ def place_order(self, offered_amount : str, offered_token : str, price_token : s
body.price_token = price_token
body.price_amount = price_amount
response : Response[ErrorResponse | PostOrderResponse] = post_orders.sync_detailed(client=self.client, body=body)
self.logger.info(f"[PLACE-ORDER] Waiting {self.wait_for_confirmation} seconds for confirmation...")
time.sleep(self.wait_for_confirmation)
self.logger.info(f"[PLACE-ORDER] [OK] Done!")

if isinstance(response.parsed, PostOrderResponse):
self.logger.info(f"[PLACE-ORDER] Placed order: {response.parsed.transaction_id}")
self.logger.info(f"[PLACE-ORDER] Waiting {self.wait_for_confirmation} seconds for confirmation...")
time.sleep(self.wait_for_confirmation)
self.logger.info(f"[PLACE-ORDER] [OK] Done!")

if isinstance(response.parsed, ErrorResponse):
self.logger.info(f"[PLACE-ORDER] [FAILED] ⚠️ [{response.parsed.error_code}] {response.parsed.message}")

return cast(PostOrderResponse, self.process_response(response))

def cancel_order(self, order_reference : str):
Expand All @@ -98,9 +105,16 @@ def cancel_order(self, order_reference : str):
body.address=self.own_address
body.order_references=[order_reference]
response: Response[ErrorResponse | DeleteOrderResponse] = delete_orders.sync_detailed(client=self.client, body=body)
self.logger.info(f"[CANCEL-ORDER] Waiting {self.wait_for_confirmation} seconds for confirmation...")
time.sleep(self.wait_for_confirmation)
self.logger.info(f"[CANCEL-ORDER] [OK] Done!")

if isinstance(response.parsed, DeleteOrderResponse):
self.logger.info(f"[CANCEL-ORDER] [OK] Canceled: {response.parsed.transaction_id}")
self.logger.info(f"[CANCEL-ORDER] Waiting {self.wait_for_confirmation} seconds for confirmation...")
time.sleep(self.wait_for_confirmation)
self.logger.info(f"[CANCEL-ORDER] [OK] Done!")

if isinstance(response.parsed, ErrorResponse):
self.logger.info(f"[CANCEL-ORDER] [FAILED] ⚠️ [{response.parsed.error_code}] {response.parsed.message}")

return cast(DeleteOrderResponse, self.process_response(response))

def direct_fill(self, *fills: FillRequest):
Expand All @@ -127,7 +141,6 @@ def direct_fill(self, *fills: FillRequest):
for fill in fills:
body.order_references_with_amount.append([fill.order_ref, fill.amount])

self.logger.info(f"[DIRECT-FILL] POST BODY: {body}")
# Send the request:
response : Response[ErrorResponse | PostOrderFillResponse] = post_orders_fill.sync_detailed(client=self.client, body=body)

Expand All @@ -136,7 +149,7 @@ def direct_fill(self, *fills: FillRequest):
self.logger.info(f"[DIRECT-FILL] Waiting {self.wait_for_confirmation} seconds for confirmation...")
time.sleep(self.wait_for_confirmation)

if isinstance(response.parsed, PostOrderFillResponse):
self.logger.info(f"[DIRECT-FILL] [FAILED] {response.parsed.errorCode} {response.parsed.message}")
if isinstance(response.parsed, ErrorResponse):
self.logger.info(f"[DIRECT-FILL] [FAILED] ⚠️ [{response.parsed.error_code}] {response.parsed.message}")

return cast(PostOrderFillResponse, self.process_response(response))
19 changes: 7 additions & 12 deletions bot-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@ components:
ErrorResponse:
type: object
properties:
error:
type: object
properties:
errorCode:
type: integer
minimum: 0
maximum: 9999
format: int32
description: Numeric error code indicating the type of error.
message:
type: string
description: Unique identifier of the indicent instance (used for troubleshooting).
errorCode:
type: string
examples: ["MULTI_FILL_NOT_SAME_PAIR"]
message:
type: string
examples: ["Given orders are not having same payment token"]
required: [code, message]
examples: [{"errorCode": "MULTI_FILL_NOT_SAME_PAIR", "message": "Given orders are not having same payment token"}]
Settings:
type: object
properties: {
Expand Down

0 comments on commit 7cb1aab

Please sign in to comment.