Skip to content

feat(upbit): defined new Unified API editOrder#20

Open
LambdaBen wants to merge 1 commit intomasterfrom
feature/upbit-edit-order
Open

feat(upbit): defined new Unified API editOrder#20
LambdaBen wants to merge 1 commit intomasterfrom
feature/upbit-edit-order

Conversation

@LambdaBen
Copy link
Collaborator

editOrder 관련 PR 입니다.

request의 key 값만 차이가 있는 정도고 로직은 CCXT에 머지된 createOrder와 동일합니다. 따라서 우선 이 코드로 CCXT에 PR을 요청하고
신규로 올려야하는 PR을 다 올린 후, createOrder와 editOrder 리팩토링하는 작업 진행하도록 하겠습니다.

업비트 API의 취소 후 재주문 API는 취소된 order 객체에 'new_order_uuid', 'new_identifier' 2개의 값만 신규 주문의 값으로 추가한 형태의 응답을 반환합니다.

  • 응답 예시
        //   {
        //     uuid: '63b38774-27db-4439-ac20-1be16a24d18e',        //previous order data
        //     side: 'bid',                                         //previous order data
        //     ord_type: 'limit',                                   //previous order data
        //     price: '100000000',                                  //previous order data
        //     state: 'wait',                                       //previous order data
        //     market: 'KRW-BTC',                                   //previous order data
        //     created_at: '2025-04-01T15:30:47+09:00',             //previous order data
        //     volume: '0.00008',                                   //previous order data
        //     remaining_volume: '0.00008',                         //previous order data
        //     reserved_fee: '4',                                   //previous order data
        //     remaining_fee: '4',                                  //previous order data
        //     paid_fee: '0',                                       //previous order data
        //     locked: '8004',                                      //previous order data
        //     executed_volume: '0',                                //previous order data
        //     trades_count: '0',                                   //previous order data
        //     identifier: '21',                                    //previous order data
        //     new_order_uuid: 'cb1cce56-6237-4a78-bc11-4cfffc1bb4c2',  // new order data
        //     new_order_identifier: '22'                               // new order data
        //   }

이 값들 중에 'new_order_uuid', 'new_identifier', 'side', 'market'은 신규 주문에 대한 응답으로 사용할 수 있는 값이라 result라는 객체를 추가해 신규 객체로 이 값들을 받고 parseOrder로 order 관련 메서드의 응답 형태를 만들었습니다.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @LambdaBen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces the editOrder method to the Upbit exchange API. This new method allows users to cancel an existing order and create a new order with the same side and symbol. The PR also includes necessary parameter validations and error handling, ensuring that the new order is created with the correct parameters. The response from the Upbit API includes data from the cancelled order, along with the new_order_uuid and new_order_identifier for the newly created order. The code constructs a result object containing the new order's UUID, identifier, side, and market, which is then parsed using the existing parseOrder method.

Highlights

  • New Feature: editOrder: Implements the editOrder method for the Upbit exchange, enabling users to modify existing orders by cancelling them and creating new ones.
  • Parameter Validation: Adds validation checks for required parameters such as order type, price, and amount, ensuring that the editOrder method is used correctly.
  • Response Parsing: Parses the response from the Upbit API, extracting the new order's UUID and identifier to create a new order object.

Changelog

  • ts/src/upbit.ts
    • Introduces the editOrder method with comprehensive documentation and parameter handling.
    • Adds validation for required parameters like type, price, and amount.
    • Implements logic to handle different order types (limit, market, best) and their specific requirements.
    • Parses the API response to extract new order details and constructs a new order object.
    • Adds a code example of the API response for cancel and new order.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A trade's course we refine,
Old order, new design,
Upbit's dance,
Second chance,
With edit, trades align.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces the editOrder function to the Upbit exchange, enabling users to modify existing orders. The implementation appears to mirror the logic of createOrder, with necessary adjustments for the edit order API endpoint. The code includes comprehensive documentation and error handling, which is commendable.

Summary of Findings

  • Duplicated Error Message: The error message in the market type order condition within the editOrder function is duplicated from the createOrder function. This could lead to confusion and should be updated to reflect the context of editing an order.
  • Inconsistent Error Message: The error message for the 'best' type order in editOrder is also duplicated from createOrder. This message should be updated to reflect that it's within the context of editing an order.
  • Redundant checks for new_ord_type: The code checks if request['new_ord_type'] !== 'market' && request['new_ord_type'] !== 'price' which seems redundant since the code already handles the cases where the type is limit, market, or best. This condition might not be necessary and could be simplified.
  • Missing Error Handling: The code does not handle the scenario where the API returns an error for the new order creation part of the cancel and new order request. It assumes that if the request is successful, the new order is always created. Error handling should be added to ensure that the new order was created successfully.

Merge Readiness

The pull request introduces a valuable feature to the Upbit exchange integration. However, there are a few issues that should be addressed before merging. Specifically, the duplicated error messages should be updated to provide more context, and the redundant checks for new_ord_type should be reviewed for simplification. Additionally, error handling for the new order creation part of the cancel and new order request should be added to ensure that the new order was created successfully. I am unable to approve this pull request, and recommend that another reviewer approves this code before merging.

Comment on lines +1392 to +1419
const response = await this.privatePostOrdersCancelAndNew (this.extend (request, params));
// {
// uuid: '63b38774-27db-4439-ac20-1be16a24d18e', //previous order data
// side: 'bid', //previous order data
// ord_type: 'limit', //previous order data
// price: '100000000', //previous order data
// state: 'wait', //previous order data
// market: 'KRW-BTC', //previous order data
// created_at: '2025-04-01T15:30:47+09:00', //previous order data
// volume: '0.00008', //previous order data
// remaining_volume: '0.00008', //previous order data
// reserved_fee: '4', //previous order data
// remaining_fee: '4', //previous order data
// paid_fee: '0', //previous order data
// locked: '8004', //previous order data
// executed_volume: '0', //previous order data
// trades_count: '0', //previous order data
// identifier: '21', //previous order data
// new_order_uuid: 'cb1cce56-6237-4a78-bc11-4cfffc1bb4c2', // new order data
// new_order_identifier: '22' // new order data
// }
const result: Dict = {};
result['uuid'] = this.safeString (response, 'new_order_uuid');
result['identifier'] = this.safeString (response, 'new_order_identifier');
result['side'] = this.safeString (response, 'side');
result['market'] = this.safeString (response, 'market');
return this.parseOrder (result);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Consider adding error handling for the privatePostOrdersCancelAndNew API call. The current implementation assumes that if the request is successful, the new order is always created. However, the API might return an error for the new order creation part of the cancel and new order request. Adding error handling would ensure that the code handles this scenario gracefully.

Copy link
Collaborator

@baileySoobinPark baileySoobinPark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new editOrder method for the Upbit API that cancels an existing order and creates a new one, reusing much of the logic from createOrder.

  • Implements editOrder with parameters to support both limit and market orders.
  • Maps new order identifiers from the API response and prepares a new order object via parseOrder.
Comments suppressed due to low confidence (1)

ts/src/upbit.ts:1310

  • [nitpick] The docstring refers to 'new_order_id' while the code and example use 'new_order_uuid'. Consider unifying the naming for clarity.
* @description canceled existing order and create new order. It's only generated same side and symbol as the canceled order. it returns the data of the canceled order, except for `new_order_id` and `new_identifier`. to get the details of the new order, use `fetchOrder(new_order_id)`.

@LambdaBen LambdaBen force-pushed the feature/upbit-edit-order branch from 1d6c602 to b6abc54 Compare April 30, 2025 01:44
Upbit supports cancel and new API (https://global-docs.upbit.com/reference/cancel-and-new)

so, I defined the editOrder API using the cancel and new API.
@LambdaBen LambdaBen force-pushed the feature/upbit-edit-order branch from b6abc54 to 7601c1e Compare April 30, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants