Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Binance: margin trading #4475

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

eschava
Copy link
Contributor

@eschava eschava commented May 2, 2022

Adds new order flags to send margin order instead of spot one.
To cancel/retrieve margin order either custom order param structures could be used or account type could be included in order ID (if Include_Margin_Account_Type_In_OrderId exchange parameter is set to true)

@eschava
Copy link
Contributor Author

eschava commented May 2, 2022

If this approach is accepted then I would like to add support for margin trading to BinanceStreamingExchange. But I do not see examples where connect method accepts custom product subscription classes. And this is required because there should be two additional subscription types for two additional channels: margin trades and isolated margin trades

AUTO_REPAY;

@JsonCreator
public static MarginSideEffectType getSideEffectType(String s) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this method seams pointless as jacksons standard error handling will do a much at reporting an unknown value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, but this is how it's implemented for other Binance enums. So I just copied the same approach

return true;
} catch (BinanceException e) {
throw BinanceErrorAdapter.adapt(e);
}
}

private MarginAccountType getMarginAccountTypeFromOrderId(String orderId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

using order id to smuggle the margin accounts id look hacky

is this some kind of convention that comes from binance?

could you point to the documentation where its described?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a part of official documentation. It's a hack added by me to allow using regular cancelOrder/getOrder API for margin orders without any special parameter types. And it's optional though

# Conflicts:
#	xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceTradeService.java
streaming of margin trading and account data
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants