Merge pull request #874 from ankion/fix_binance_futures

Fix binance futures
This commit is contained in:
Yo-An Lin 2022-08-12 01:43:15 +08:00 committed by GitHub
commit dad562db97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View File

@ -42,6 +42,11 @@ func toGlobalFuturesPositions(futuresPositions []*futures.AccountPosition) types
for _, futuresPosition := range futuresPositions { for _, futuresPosition := range futuresPositions {
retFuturesPositions[futuresPosition.Symbol] = types.FuturesPosition{ // TODO: types.FuturesPosition retFuturesPositions[futuresPosition.Symbol] = types.FuturesPosition{ // TODO: types.FuturesPosition
Isolated: futuresPosition.Isolated, Isolated: futuresPosition.Isolated,
AverageCost: fixedpoint.MustNewFromString(futuresPosition.EntryPrice),
ApproximateAverageCost: fixedpoint.MustNewFromString(futuresPosition.EntryPrice),
Base: fixedpoint.MustNewFromString(futuresPosition.PositionAmt),
Quote: fixedpoint.MustNewFromString(futuresPosition.Notional),
PositionRisk: &types.PositionRisk{ PositionRisk: &types.PositionRisk{
Leverage: fixedpoint.MustNewFromString(futuresPosition.Leverage), Leverage: fixedpoint.MustNewFromString(futuresPosition.Leverage),
}, },

View File

@ -1041,7 +1041,7 @@ func (e *Exchange) submitFuturesOrder(ctx context.Context, order types.SubmitOrd
req.TimeInForce(futures.TimeInForceType(order.TimeInForce)) req.TimeInForce(futures.TimeInForceType(order.TimeInForce))
} else { } else {
switch order.Type { switch order.Type {
case types.OrderTypeLimit, types.OrderTypeStopLimit: case types.OrderTypeLimit, types.OrderTypeLimitMaker, types.OrderTypeStopLimit:
req.TimeInForce(futures.TimeInForceTypeGTC) req.TimeInForce(futures.TimeInForceTypeGTC)
} }
} }

View File

@ -268,6 +268,17 @@ func (s *Stream) handleOrderTradeUpdateEvent(e *OrderTradeUpdateEvent) {
s.EmitTradeUpdate(*trade) s.EmitTradeUpdate(*trade)
order, err := e.OrderFutures()
if err != nil {
log.WithError(err).Error("futures order convert error")
return
}
// Update Order with FILLED event
if order.Status == types.OrderStatusFilled {
s.EmitOrderUpdate(*order)
}
case "CALCULATED - Liquidation Execution": case "CALCULATED - Liquidation Execution":
log.Infof("CALCULATED - Liquidation Execution not support yet.") log.Infof("CALCULATED - Liquidation Execution not support yet.")
} }

View File

@ -257,8 +257,6 @@ type FuturesPosition struct {
Isolated bool `json:"isolated"` Isolated bool `json:"isolated"`
UpdateTime int64 `json:"updateTime"` UpdateTime int64 `json:"updateTime"`
PositionRisk *PositionRisk PositionRisk *PositionRisk
sync.Mutex
} }
func NewPositionFromMarket(market Market) *Position { func NewPositionFromMarket(market Market) *Position {