Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/account_asset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
defer tradeContext.Close()
ctx := context.Background()
// Get AccountBalance infomation
ab, err := tradeContext.AccountBalance(ctx)
ab, err := tradeContext.AccountBalance(ctx, &trade.GetAccountBalance{Currency: trade.CurrencyHKD})
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/longportapp/openapi-go

go 1.17
go 1.20

retract [v0.0.1, v0.7.1]

Expand All @@ -11,7 +11,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/joho/godotenv v1.4.0
github.com/longbridgeapp/assert v0.1.0
github.com/longportapp/openapi-protobufs/gen/go v0.5.0
github.com/longportapp/openapi-protobufs/gen/go v0.6.0
github.com/longportapp/openapi-protocol/go v0.4.1
github.com/pkg/errors v0.9.1
github.com/shopspring/decimal v1.3.1
Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand All @@ -23,16 +22,12 @@ github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/longbridgeapp/assert v0.1.0 h1:KkQlHUJSpuUFkUDjwBJgghFl31+wwSDHTq/WRrvLjko=
github.com/longbridgeapp/assert v0.1.0/go.mod h1:ew3umReliXtk1bBG4weVURxdvR0tsN+rCEfjnA4YfxI=
github.com/longportapp/openapi-protobufs/gen/go v0.4.0/go.mod h1:/chiEwEW4CnOVgKTaCf8rQUwes00Ku8q1CvRpOueWfo=
github.com/longportapp/openapi-protobufs/gen/go v0.5.0 h1:mKnkhI/D2X8+BKPEqRLjqkRpyAoCqjh8mIkYwl2gRv4=
github.com/longportapp/openapi-protobufs/gen/go v0.5.0/go.mod h1:/chiEwEW4CnOVgKTaCf8rQUwes00Ku8q1CvRpOueWfo=
github.com/longportapp/openapi-protobufs/gen/go v0.6.0 h1:qCFi1E9/QECdsCGaYWWrherZTHBrdD/UQz8tlFb7How=
github.com/longportapp/openapi-protobufs/gen/go v0.6.0/go.mod h1:41uJm1Fap9jGtXiuuaH2neFZxjsCBpOX1ehUzMAjlH0=
github.com/longportapp/openapi-protocol/go v0.4.1 h1:H+sFW7kK8g10AAD6ZTGiKd7YaV5kZGCsEhGfd9JVyFY=
github.com/longportapp/openapi-protocol/go v0.4.1/go.mod h1:reREZxZflXsxFQ/VR4Uca25pMHyJ3nCYy86tp1hXva4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -46,15 +41,11 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 4 additions & 4 deletions quote/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ func (c *QuoteContext) Candlesticks(ctx context.Context, symbol string, period P
// qctx, err := quote.NewFromEnv()
// dateTime := time.Date(2022, 5, 10, 11, 10, 0, 0, time.UTC)
// klines, err := qctx.HistoryCandlesticksByOffset(context.Background(), "AAPL.US", quote.PeriodDay, quote.AdjustTypeNo, true, &dateTime, 100)
func (c *QuoteContext) HistoryCandlesticksByOffset(ctx context.Context, symbol string, period Period, adjustType AdjustType, isForward bool, dateTime *time.Time, count int32) (sticks []*Candlestick, err error) {
return c.core.HistoryCandlesticksByOffset(ctx, symbol, period, adjustType, isForward, dateTime, count)
func (c *QuoteContext) HistoryCandlesticksByOffset(ctx context.Context, symbol string, period Period, adjustType AdjustType, isForward bool, dateTime *time.Time, count int32, opts ...CandlestickRequestOption) (sticks []*Candlestick, err error) {
return c.core.HistoryCandlesticksByOffset(ctx, symbol, period, adjustType, isForward, dateTime, count, opts...)
}

// HistoryCandlesticksByOffset obtains the history candlestick data of security after or before an offset time.
Expand All @@ -263,8 +263,8 @@ func (c *QuoteContext) HistoryCandlesticksByOffset(ctx context.Context, symbol s
// startDate := time.Date(2022, 5, 10, 0, 0, 0, 0, time.UTC)
// endDate := time.Date(2022, 6, 10, 0, 0, 0, 0, time.UTC)
// klines, err := qctx.HistoryCandlesticksByDate(context.Background(), "AAPL.US", quote.PeriodDay, quote.AdjustTypeNo, &startDate, &endDate)
func (c *QuoteContext) HistoryCandlesticksByDate(ctx context.Context, symbol string, period Period, adjustType AdjustType, startDate *time.Time, endDate *time.Time) (sticks []*Candlestick, err error) {
return c.core.HistoryCandlesticksByDate(ctx, symbol, period, adjustType, startDate, endDate)
func (c *QuoteContext) HistoryCandlesticksByDate(ctx context.Context, symbol string, period Period, adjustType AdjustType, startDate *time.Time, endDate *time.Time, opts ...CandlestickRequestOption) (sticks []*Candlestick, err error) {
return c.core.HistoryCandlesticksByDate(ctx, symbol, period, adjustType, startDate, endDate, opts...)
}

// OptionChainExpiryDateList obtain the the list of expiration dates of option chain
Expand Down
14 changes: 12 additions & 2 deletions quote/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (c *core) Candlesticks(ctx context.Context, symbol string, period Period, c
return
}

func (c *core) HistoryCandlesticksByOffset(ctx context.Context, symbol string, period Period, adjustType AdjustType, isForward bool, dateTime *time.Time, count int32) (sticks []*Candlestick, err error) {
func (c *core) HistoryCandlesticksByOffset(ctx context.Context, symbol string, period Period, adjustType AdjustType, isForward bool, dateTime *time.Time, count int32, options ...CandlestickRequestOption) (sticks []*Candlestick, err error) {
direction := quotev1.Direction_BACKWARD
if isForward {
direction = quotev1.Direction_FORWARD
Expand All @@ -410,10 +410,15 @@ func (c *core) HistoryCandlesticksByOffset(ctx context.Context, symbol string, p
Count: int32(count),
},
}

for _, option := range options {
option(req)
}

return c.historyCandlesticks(ctx, req)
}

func (c *core) HistoryCandlesticksByDate(ctx context.Context, symbol string, period Period, adjustType AdjustType, startDate *time.Time, endDate *time.Time) (sticks []*Candlestick, err error) {
func (c *core) HistoryCandlesticksByDate(ctx context.Context, symbol string, period Period, adjustType AdjustType, startDate *time.Time, endDate *time.Time, options ...CandlestickRequestOption) (sticks []*Candlestick, err error) {
req := &quotev1.SecurityHistoryCandlestickRequest{
Symbol: symbol,
Period: quotev1.Period(period),
Expand All @@ -424,6 +429,11 @@ func (c *core) HistoryCandlesticksByDate(ctx context.Context, symbol string, per
EndDate: util.FormatDateSimple(endDate),
},
}

for _, option := range options {
option(req)
}

return c.historyCandlesticks(ctx, req)
}

Expand Down
16 changes: 16 additions & 0 deletions quote/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const (
AdjustTypeNo = AdjustType(quotev1.AdjustType_NO_ADJUST)
AdjustTypeForward = AdjustType(quotev1.AdjustType_FORWARD_ADJUST)

// TradeSession
TradeSessionNormal = TradeSession(quotev1.TradeSession_NORMAL_TRADE)
TradeSessionPreTrade = TradeSession(quotev1.TradeSession_PRE_TRADE)
TradeSessionPostTrade = TradeSession(quotev1.TradeSession_POST_TRADE)
TradeSessionOvernight = TradeSession(quotev1.TradeSession_OVERNIGHT_TRADE)

// CalcIndex
CalcIndexUnknown CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_UNKNOWN)
CalcIndexLastDone CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_LAST_DONE)
Expand Down Expand Up @@ -663,3 +669,13 @@ type MarketPackageDetail struct {
Limit int32
Burst int32
}

// CandlestickRequestOption is the option for the candlestick request
type CandlestickRequestOption func(*quotev1.SecurityHistoryCandlestickRequest)

// CandlestickRequestTradeSession sets the trade session of the candlestick request
func CandlestickRequestTradeSession(session TradeSession) CandlestickRequestOption {
return func(req *quotev1.SecurityHistoryCandlestickRequest) {
req.TradeSession = int32(session)
}
}