-
Notifications
You must be signed in to change notification settings - Fork 874
codebase: Consolidate orders functionality and other minor fixes #1957
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
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.
Pull Request Overview
This PR standardizes timestamp parsing by introducing a new DateTime
type alongside the existing Time
wrapper, and applies these types across the codebase to replace raw numeric/unparse logic. It also streamlines exchange wrappers and WebSocket handlers to use strongly typed fields for order sides, statuses, and times, eliminating repetitive manual parsing.
- Added
DateTime
type with JSON unmarshal support and tests. - Replaced raw
int64
/float64
timestamps withtypes.Time
/types.DateTime
in exchange models. - Simplified wrapper and WS code by using direct
.Time()
and typedorder.Side
/order.Type
/order.Status
fields.
Reviewed Changes
Copilot reviewed 121 out of 121 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
types/time.go | Added DateTime type and UnmarshalJSON implementation |
types/time_test.go | New tests for DateTime unmarshalling |
exchanges/yobit/yobit_wrapper.go | Switched raw timestamps to types.Time and removed manual parsing |
exchanges/yobit/yobit_types.go | Updated model fields to use types.Time and order.Side |
exchanges/order/orders.go | Extended StringToOrderSide/Type/Status and JSON hooks |
Comments suppressed due to low confidence (2)
types/time.go:86
- The
UnmarshalJSON
method usesfmt.Errorf
but thefmt
package is not imported. Addimport "fmt"
at the top.
func (d *DateTime) UnmarshalJSON(data []byte) error {
exchanges/order/orders.go:1086
- The code calls
reflect.TypeFor
but thereflect
package is not imported. Addimport "reflect"
to this file.
return &json.UnmarshalTypeError{Value: string(data), Type: reflect.TypeFor[Side](), Offset: 1}
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.
Sexy clean. Here have some nits.
exchanges/binance/binance_types.go
Outdated
CommissionAsset currency.Code `json:"N"` | ||
TransactionTime types.Time `json:"T"` | ||
TradeID int64 `json:"t"` | ||
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'. |
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.
int64 -> json.RawMessage
exchanges/binance/binance_types.go
Outdated
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'. | ||
IsOnOrderBook bool `json:"w"` | ||
IsMaker bool `json:"m"` | ||
Ignored2 bool `json:"M"` // See the comment for "I". |
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.
bool -> json.RawMessage
CommissionAsset currency.Code `json:"N"` | ||
TransactionTime types.Time `json:"T"` | ||
TradeID int64 `json:"t"` | ||
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'. |
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.
type to json.RawMessage
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'. | ||
IsOnOrderBook bool `json:"w"` | ||
IsMaker bool `json:"m"` | ||
Ignored2 bool `json:"M"` // See the comment for "I". |
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.
type to json.RawMessage
case len(channels) == 5: | ||
// on the “5-item” feed we always treat every push as a snapshot | ||
return d.Websocket.Orderbook.LoadSnapshot(book) | ||
|
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 spaces between cases
}) | ||
|
||
case len(channels) == 5: |
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.
merge with first case and only allocate orderbook.Book on LoadSnapshot call.
} | ||
asks := buildLevels(ob.Asks) | ||
bids := buildLevels(ob.Bids) | ||
if len(asks) == 0 && len(bids) == 0 { |
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.
This happening a lot? If you can check that the LastUpdateID is sequential even when no action has occurred on the books between the update frequency window we can actually load zero values in now.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1957 +/- ##
==========================================
+ Coverage 39.70% 39.94% +0.24%
==========================================
Files 434 434
Lines 171748 170185 -1563
==========================================
- Hits 68185 67979 -206
+ Misses 96417 95166 -1251
+ Partials 7146 7040 -106
🚀 New features to boost your workflow:
|
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 cleanup! 🎉
A few 🚧 changes, 🐒 nitpicks and 🦍 groomings.
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.
The PR looks grea. just added minor reviews for now
@@ -61,7 +62,7 @@ type TransactionHistory struct { | |||
Data []struct { | |||
ContNumber int64 `json:"cont_no,string"` | |||
TransactionDate types.DateTime `json:"transaction_date"` | |||
Type string `json:"type"` | |||
Side order.Side `json:"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.
Is this really a side or 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.
Yep this and other exchanges have their order side as "type" https://apidocs.bithumb.com/v1.2.0/reference/%EA%B1%B0%EB%9E%98-%EC%A3%BC%EB%AC%B8%EB%82%B4%EC%97%AD-%EC%A1%B0%ED%9A%8C
"%s GetOrderInfo unable to parse currency pair: %s\n", | ||
e.Name, | ||
err) | ||
} | ||
od.Exchange = e.Name |
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't we instantiate this like ```
od = order.Detail{
Exchange: e.Name,
...
}
Amount float64 `json:"amount"` | ||
TradeID int64 `json:"trade_id"` | ||
Date types.Time `json:"date"` | ||
Side order.Side `json:"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.
side
or 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.
Side, despite them using type
as well 😆
json
{
"BTC_USD": [
{
"order_id": "14",
"client_id": "100500",
"created": "1435517311",
"type": "buy",
"pair": "BTC_USD",
"price": "100",
"quantity": "1",
"amount": "100"
}
]
}
Timestamp types.Time `json:"dt"` | ||
Type string `json:"type"` | ||
Currency currency.Code `json:"curr"` | ||
Status string `json:"status"` |
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.
Is this not order.Status?
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.
Nope this one is for wallet transactions
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.
What a slog! 😴
Tried to focus on areas where custom functions were used versus straight type replacement occurred.
resp.Status = order.Cancelled | ||
case orderPartiallyCancelled: | ||
resp.Status = order.PartiallyCancelled | ||
case orderFailed: |
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.
This and a few other strings here are unused as a result of this change and should be removed
@@ -161,7 +162,7 @@ type TradeHistory struct { | |||
Amount float64 `json:"amount,string"` | |||
Timestamp types.Time `json:"timestamp"` | |||
TimestampMS types.Time `json:"timestampms"` | |||
Type string `json:"type"` | |||
Side order.Side `json:"side"` |
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.
@@ -140,7 +141,7 @@ type Order struct { | |||
Exchange string `json:"exchange"` | |||
Price float64 `json:"price,string"` | |||
AvgExecutionPrice float64 `json:"avg_execution_price,string"` | |||
Side string `json:"side"` | |||
Side order.Side `json:"side"` | |||
Type string `json:"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.
@@ -344,7 +345,7 @@ type wsTrade struct { | |||
Timestamp types.Time `json:"timestamp"` | |||
Price float64 `json:"price,string"` | |||
Quantity float64 `json:"quantity,string"` | |||
Side string `json:"side"` | |||
Side order.Side `json:"side"` |
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.
Not sure I see this type even present in Gemini api docs
|
||
func stringToOrderType(oType string) (order.Type, error) { | ||
switch oType { | ||
case "exchange limit", "auction-only limit", "indication-of-interest limit": |
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.
Auction only limit support dropped by 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.
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.
Has the API changed?AUCTION-ONLY LIMIT
YOU MAY BE HOLDING DOWN SHIFT TO YELL INTO THE IDE
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.
Ah I see now, it needs a -
} | ||
orderType, tif, err := orderTypeFromString(orderDetail.OrderType) | ||
|
||
_, tif, err := orderTypeFromString(orderDetail.OrderType.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.
Could have changed param to order.Type and calledString()
from the func once, instead of 4 times. FAR OUT 😄
Function could be improved further: GetTIFFromOrderType
seems better
func setOrderTypeAndSide(rawOrderType string, origSide order.Side, d *order.Detail) error { | ||
var err error | ||
if origSide == order.UnknownSide { | ||
d.Side, err = stringToOrderSide(rawOrderType) |
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.
Looks like a typo, therefore you should add a test for this function
PR Description
Introduces order status and type unmarshalling and rolls it out across the codebase where possible and some other minor fixes along the way.
Depends on #1948
Type of change
How has this been tested
Checklist