bbgo_origin/pkg/exchange/ftx/convert_test.go
2021-03-07 12:51:13 +08:00

52 lines
1.2 KiB
Go

package ftx
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/types"
)
func Test_toGlobalOrderFromOpenOrder(t *testing.T) {
input := `
{
"createdAt": "2019-03-05T09:56:55.728933+00:00",
"filledSize": 10,
"future": "XRP-PERP",
"id": 9596912,
"market": "XRP-PERP",
"price": 0.306525,
"avgFillPrice": 0.306526,
"remainingSize": 31421,
"side": "sell",
"size": 31431,
"status": "open",
"type": "limit",
"reduceOnly": false,
"ioc": false,
"postOnly": false,
"clientId": "client-id-123"
}
`
var r order
assert.NoError(t, json.Unmarshal([]byte(input), &r))
o, err := toGlobalOrderFromOpenOrder(r)
assert.NoError(t, err)
assert.Equal(t, "client-id-123", o.ClientOrderID)
assert.Equal(t, "XRP-PERP", o.Symbol)
assert.Equal(t, types.SideTypeSell, o.Side)
assert.Equal(t, types.OrderTypeLimit, o.Type)
assert.Equal(t, float64(31431), o.Quantity)
assert.Equal(t, 0.306525, o.Price)
assert.Equal(t, "GTC", o.TimeInForce)
assert.Equal(t, types.ExchangeFTX.String(), o.Exchange)
assert.True(t, o.IsWorking)
assert.Equal(t, uint64(9596912), o.OrderID)
assert.Equal(t, types.OrderStatusPartiallyFilled, o.Status)
assert.Equal(t, float64(10), o.ExecutedQuantity)
}