-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exchanges/order: Added TimeInForce type and values #1382
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool update. Thanks big boss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. 🦸
Sorry for the delayed update on this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update, not much left over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. Things are looking good. Just need to test all endpoints associated with these changes.
The endpoints I can run are only those that are public. The change I made, TimeInForce is mostly used by the authenticated, order-related endpoints. I am open to hear any other alternative of running the authenticated tests you may suggest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating things!
exchanges/order/order_types.go
Outdated
ImmediateOrCancel bool | ||
FillOrKill bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to keep fields ImmediateOrCancel and FillOrKill with your new TimeInForce?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and post only.
exchanges/gateio/gateio_test.go
Outdated
@@ -3437,7 +3437,7 @@ func TestGetTimeInForce(t *testing.T) { | |||
require.NoError(t, err) | |||
assert.Equal(t, "gtc", ret) | |||
|
|||
ret, err = getTimeInForce(&order.Submit{Type: order.Market, FillOrKill: true}) | |||
ret, err = getTimeInForce(&order.Submit{Type: order.Market, TimeInForce: order.FOK}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… into update_tif # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice direction and clean. Just some nits and suggestions. Thanks heaps!
exchanges/order/order_types.go
Outdated
ImmediateOrCancel bool | ||
FillOrKill bool | ||
// TimeInForce holds time in force values | ||
TimeInForce TimeInForce | ||
|
||
PostOnly bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post only can be merged with TimeInForce across all order types as it conflicts with FOK, IOC and it implies limit order type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-only can be a value for either the Order Type or the Time In Force type. Some exchanges have a dedicated PostOnly field, and in such cases, we need to check whether either the Time In Force or the Order Type is set to Post-only. I left this as it is to avoid making that decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-only can be used with GTT, GTC, or GTD, and having it as a parameter here is restrictive. Some exchanges have TimeInForce and PostOnly as separate parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: You can either flag TimeInForce
values order.GTT | order.POSTONLY
or you can merge the entire TimeInForce values and flag everything together into order.Type
- order.Limit | order.GTT | order.PostOnly
and with both options update to parser functions to allow for delimited string values and methods for extraction. I will have a play around today and see if there are any caveats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging them altogether into order type is a bit of a mission. And can be circled around in a future update. In your other comment:
FOK and IOC has an order type replica.. So, I am not renaming these values.
However, I have renamed the rest
suggestion: Seems like a time in force policy as well as PostOnly and that should be removed from order types and moved to TIF. Could have a method Is(order.FillOrKill) bool
and Is(order.InstanceOrCancelled) bool
Just so its an easy catch all expression and self obvious.
There are a bunch of trigger conditionals in order type StopLimit which could be improved as it should just be Stop | Limit
as well as SpecialMode/exchange specific
e.g. TWAP
or MarketMakerProtection
(which has post only
variant which can be removed and handled) but that is out of scope.
So just keeping it time in force is a nice reviewable action but I am open to other perspectives and direction. If we proceed to merge them altogether we add in edge cases where they cannot be combined but if we refactor to keep them separate like
type Order struct {
Type OrderType
Condition ConditionType
TimeInForce TimeInForce
SpecialMode SpecialMode
}
might be impractical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delayed reply to this comments & Pardon me if I don't fully understand what you are saying here.
I have a point here: Three exchanges Okx, CoinbasePro, Deribit, and Huobi use PostOnly as an independent Order Type too. How do we handle these?
As it has to be directly mapped in the wrapper file between order.Type and String representation.
The same applies to FillOrKill and ImmediateOrCancel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Boss 👑. You would apply the same logic their end but from a submission perspective from the IBotInterface/wrapper funcs, an order would apply order.Limit as type and for the TimeInForce value as Post Only or FillOrKIll or Immediate Or Cancel we can extract the string that we need from that. That way we standardise the layer on our side and we segregate primary areas of concern. I will have a play today and see if that can be done while you are offline so I can give a concrete example.
exchanges/order/order_types.go
Outdated
POC // POC represents PendingOrCancel | ||
PostOnlyGTC // PostOnlyGCT represents PostOnlyGoodTilCancelled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POC and PostOnlyGTC can merged to PostOnly and all Abbreviations can be changed from GTC -> GoodTillCancel and comments removed etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOK and IOC has an order type replica.. So, I am not renaming these values.
However, I have renamed the rest
@@ -1234,6 +1254,37 @@ func StringToOrderStatus(status string) (Status, error) { | |||
} | |||
} | |||
|
|||
// StringToTimeInForce converts time in force string value to TimeInForce instance. | |||
func StringToTimeInForce(timeInForce string) (TimeInForce, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: This is a good easy catch all but it adds bloat and reduced performance there should be an umarshal json method or function to a type exchange side. So suggestion would be to remove this completely. This is just a suggestion doesn't need to be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it here and remove it for when we need the UnmarshalJSON method rather than this one
Please review and merge/cherry-pick changes from this commit @samuael boss this is regarding our conversation here |
I have done so and applied the changes. I will try to do further updates based on your recent approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, Heres some more nits for current state.
exchanges/binance/binance_wrapper.go
Outdated
var requestParamsOrderType RequestParamsOrderType | ||
switch s.Type { | ||
case order.Market: | ||
timeInForce = "" | ||
requestParamsOrderType = BinanceRequestParamsOrderMarket | ||
case order.Limit: | ||
if s.ImmediateOrCancel { | ||
timeInForce = BinanceRequestParamsTimeIOC | ||
if s.TimeInForce == order.ImmediateOrCancel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use IS method
@@ -1420,7 +1420,7 @@ func TestNewOrderTest(t *testing.T) { | |||
TradeType: BinanceRequestParamsOrderLimit, | |||
Price: 0.0025, | |||
Quantity: 100000, | |||
TimeInForce: BinanceRequestParamsTimeGTC, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Binance request params can be removed?
exchanges/btcmarkets/btcmarkets.go
Outdated
} | ||
if s.FillOrKill { | ||
return fillOrKill | ||
switch s.TimeInForce { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use method Is
if s.ImmediateOrCancel { | ||
timeInForce = CoinbaseRequestParamsTimeIOC | ||
timeInForce := order.GoodTillCancel.String() | ||
if s.TimeInForce == order.ImmediateOrCancel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use method Is
exchanges/deribit/deribit_wrapper.go
Outdated
timeInForce := "" | ||
if s.ImmediateOrCancel { | ||
var timeInForce string | ||
switch s.TimeInForce { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use method Is
as we are flagging and can be order.GoodTillDay | order.PostOnly
for example.
type TimeInForce uint16 | ||
|
||
// Is checks to see if the enum contains the flag | ||
func (t TimeInForce) Is(in TimeInForce) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PLease have a test for this and remove IsIOC method as this is more generic for that application.
exchanges/order/order_types.go
Outdated
FillOrKill // FOK represents FillOrKill | ||
ImmediateOrCancel // IOC represents ImmediateOrCancel | ||
PostOnly // PostOnlyGCT represents PostOnlyGoodTilCancelled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commentary
exchanges/order/orders.go
Outdated
} | ||
|
||
// IsIOC determines whether the TimeInForce value is set to IOC (Immediate or Cancel). | ||
func (t TimeInForce) IsIOC() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RM
@@ -740,6 +718,33 @@ func (t Type) String() string { | |||
} | |||
} | |||
|
|||
// String implements the stringer interface. | |||
func (t TimeInForce) String() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this can be flagged with Post only and GTT, GTD, GTC, it needs to be able to be a delimitated string and umarshal multiple options. Please add a test.
@@ -549,7 +549,7 @@ func (p *Poloniex) ModifyOrder(ctx context.Context, action *order.Modify) (*orde | |||
action.Price, | |||
action.Amount, | |||
action.PostOnly, | |||
action.ImmediateOrCancel) | |||
action.TimeInForce.IsIOC()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Is method
ሰላም፣ ወንድሞች
PR Description
This PR adds a type TimeInForce(TIF) to represent common Time In Force values. It affects some exchanges and packages that were using the ImmediateOrCancel and FillOrKill values. Units that were affected by the change are tested. Additionally, new unit tests are added for newly added functions.
Exchanges that are directly affected by the change are Binance, Bitrex, BTCMarket, CoinbasePro, Huobi, Kraken, Poloniex
Packages affected: Orders, Engine, cmd/exchange_wrapper_standards
Fixes # (issue)
Type of change
Please delete options that are not relevant and add an
x
in[]
as the item is complete.How has this been tested
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.
Checklist