-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(perp)!: PositionChangedEvent
MarginToUser
(#1427)
* refactor(perp): PositionChangedEvent * Update CHANGELOG.md
- Loading branch information
Showing
9 changed files
with
218 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package types | ||
|
||
import "encoding/json" | ||
|
||
type customProtobufType interface { | ||
Marshal() ([]byte, error) | ||
MarshalTo(data []byte) (n int, err error) | ||
Unmarshal(data []byte) error | ||
Size() int | ||
|
||
MarshalJSON() ([]byte, error) | ||
UnmarshalJSON(data []byte) error | ||
} | ||
|
||
var _ customProtobufType = (*ChangeReason)(nil) | ||
|
||
type ChangeReason string | ||
|
||
const ( | ||
ChangeReason_OpenPosition ChangeReason = "open_position" | ||
ChangeReason_ClosePosition ChangeReason = "close_position" | ||
ChangeReason_AddMargin ChangeReason = "add_margin" | ||
ChangeReason_RemoveMargin ChangeReason = "remove_margin" | ||
ChangeReason_Liquidate ChangeReason = "liquidate" | ||
) | ||
|
||
func (c *ChangeReason) Size() int { | ||
return len(*c) | ||
} | ||
|
||
func (c *ChangeReason) Marshal() ([]byte, error) { | ||
return []byte(*c), nil | ||
} | ||
|
||
func (c *ChangeReason) MarshalTo(data []byte) (n int, err error) { | ||
return copy(data, *c), nil | ||
} | ||
|
||
func (c *ChangeReason) Unmarshal(data []byte) error { | ||
*c = ChangeReason(data) | ||
return nil | ||
} | ||
|
||
func (c *ChangeReason) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(*c) | ||
} | ||
|
||
func (c *ChangeReason) UnmarshalJSON(data []byte) error { | ||
var s string | ||
|
||
err := json.Unmarshal(data, &s) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*c = ChangeReason(s) | ||
return nil | ||
} |
Oops, something went wrong.