diff --git a/client/blockchainservice/blockchain_service.go b/client/blockchainservice/blockchain_service.go index 03d832b..82157fd 100644 --- a/client/blockchainservice/blockchain_service.go +++ b/client/blockchainservice/blockchain_service.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.8.5 +// goctl 1.8.1 // Source: blockchain.proto package blockchainservice @@ -15,6 +15,7 @@ import ( type ( HistoryReq = app_cloudep_blockchain.HistoryReq + Kline = app_cloudep_blockchain.Kline ListCandleDataResp = app_cloudep_blockchain.ListCandleDataResp ListSymbolsRequest = app_cloudep_blockchain.ListSymbolsRequest ListSymbolsResponse = app_cloudep_blockchain.ListSymbolsResponse diff --git a/etc/blockchain.yaml b/etc/blockchain.yaml index bf54ed8..ae152f7 100644 --- a/etc/blockchain.yaml +++ b/etc/blockchain.yaml @@ -13,13 +13,13 @@ Binance: RedisCluster: Host: localhost:6379 - Type: nodeda + Type: node Cassandra: Hosts: - - 10.0.0.13 + - localhost Port: 9042 - Keyspace: digimon + Keyspace: kline UseAuth: true Username: cassdandra Password: cassandra diff --git a/gen_result/pb/code.30cm.net/digimon/app-cloudep-blockchain/blockchain.pb.go b/gen_result/pb/code.30cm.net/digimon/app-cloudep-blockchain/blockchain.pb.go index 5260b8a..7adfdb8 100644 --- a/gen_result/pb/code.30cm.net/digimon/app-cloudep-blockchain/blockchain.pb.go +++ b/gen_result/pb/code.30cm.net/digimon/app-cloudep-blockchain/blockchain.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.5 +// protoc-gen-go v1.36.1 // protoc v3.19.4 // source: generate/rpc/blockchain.proto @@ -11,7 +11,6 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" - unsafe "unsafe" ) const ( @@ -333,6 +332,7 @@ func (x *HistoryReq) GetEndTime() string { type ListCandleDataResp struct { state protoimpl.MessageState `protogen:"open.v1"` + Data []*Kline `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -367,9 +367,157 @@ func (*ListCandleDataResp) Descriptor() ([]byte, []int) { return file_generate_rpc_blockchain_proto_rawDescGZIP(), []int{6} } +func (x *ListCandleDataResp) GetData() []*Kline { + if x != nil { + return x.Data + } + return nil +} + +// 單根 K 線 +type Kline struct { + state protoimpl.MessageState `protogen:"open.v1"` + OpenTime int64 `protobuf:"varint,1,opt,name=open_time,json=openTime,proto3" json:"open_time,omitempty"` // 開盤時間(毫秒) + Open string `protobuf:"bytes,2,opt,name=open,proto3" json:"open,omitempty"` // 開盤價 + High string `protobuf:"bytes,3,opt,name=high,proto3" json:"high,omitempty"` // 最高價 + Low string `protobuf:"bytes,4,opt,name=low,proto3" json:"low,omitempty"` // 最低價 + Close string `protobuf:"bytes,5,opt,name=close,proto3" json:"close,omitempty"` // 收盤價 + Volume string `protobuf:"bytes,6,opt,name=volume,proto3" json:"volume,omitempty"` // 成交量 + CloseTime int64 `protobuf:"varint,7,opt,name=close_time,json=closeTime,proto3" json:"close_time,omitempty"` // 收盤時間(毫秒) + QuoteAssetVolume string `protobuf:"bytes,8,opt,name=quote_asset_volume,json=quoteAssetVolume,proto3" json:"quote_asset_volume,omitempty"` // 成交額(以報價資產計) + NumberOfTrades int32 `protobuf:"varint,9,opt,name=number_of_trades,json=numberOfTrades,proto3" json:"number_of_trades,omitempty"` // 交易筆數 + TakerBuyBaseAssetVolume string `protobuf:"bytes,10,opt,name=taker_buy_base_asset_volume,json=takerBuyBaseAssetVolume,proto3" json:"taker_buy_base_asset_volume,omitempty"` // 主動買入成交量 + TakerBuyQuoteAssetVolume string `protobuf:"bytes,11,opt,name=taker_buy_quote_asset_volume,json=takerBuyQuoteAssetVolume,proto3" json:"taker_buy_quote_asset_volume,omitempty"` // 主動買入成交額 + Symbol string `protobuf:"bytes,12,opt,name=symbol,proto3" json:"symbol,omitempty"` // 交易對 (partition key) + Interval string `protobuf:"bytes,13,opt,name=interval,proto3" json:"interval,omitempty"` // K 線區間 (partition key) e.g. 1d, 4h, 15m + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Kline) Reset() { + *x = Kline{} + mi := &file_generate_rpc_blockchain_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Kline) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Kline) ProtoMessage() {} + +func (x *Kline) ProtoReflect() protoreflect.Message { + mi := &file_generate_rpc_blockchain_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Kline.ProtoReflect.Descriptor instead. +func (*Kline) Descriptor() ([]byte, []int) { + return file_generate_rpc_blockchain_proto_rawDescGZIP(), []int{7} +} + +func (x *Kline) GetOpenTime() int64 { + if x != nil { + return x.OpenTime + } + return 0 +} + +func (x *Kline) GetOpen() string { + if x != nil { + return x.Open + } + return "" +} + +func (x *Kline) GetHigh() string { + if x != nil { + return x.High + } + return "" +} + +func (x *Kline) GetLow() string { + if x != nil { + return x.Low + } + return "" +} + +func (x *Kline) GetClose() string { + if x != nil { + return x.Close + } + return "" +} + +func (x *Kline) GetVolume() string { + if x != nil { + return x.Volume + } + return "" +} + +func (x *Kline) GetCloseTime() int64 { + if x != nil { + return x.CloseTime + } + return 0 +} + +func (x *Kline) GetQuoteAssetVolume() string { + if x != nil { + return x.QuoteAssetVolume + } + return "" +} + +func (x *Kline) GetNumberOfTrades() int32 { + if x != nil { + return x.NumberOfTrades + } + return 0 +} + +func (x *Kline) GetTakerBuyBaseAssetVolume() string { + if x != nil { + return x.TakerBuyBaseAssetVolume + } + return "" +} + +func (x *Kline) GetTakerBuyQuoteAssetVolume() string { + if x != nil { + return x.TakerBuyQuoteAssetVolume + } + return "" +} + +func (x *Kline) GetSymbol() string { + if x != nil { + return x.Symbol + } + return "" +} + +func (x *Kline) GetInterval() string { + if x != nil { + return x.Interval + } + return "" +} + var File_generate_rpc_blockchain_proto protoreflect.FileDescriptor -var file_generate_rpc_blockchain_proto_rawDesc = string([]byte{ +var file_generate_rpc_blockchain_proto_rawDesc = []byte{ 0x0a, 0x1d, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x22, 0x08, 0x0a, 0x06, 0x4f, @@ -401,45 +549,75 @@ var file_generate_rpc_blockchain_proto_rawDesc = string([]byte{ 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, - 0x43, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x32, 0xa1, - 0x02, 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x12, 0x4e, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x79, 0x6d, 0x62, - 0x6f, 0x6c, 0x73, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f, - 0x72, 0x79, 0x4b, 0x6c, 0x69, 0x6e, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, - 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, - 0x2e, 0x4f, 0x4b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x48, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x43, - 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, - 0x71, 0x1a, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4c, - 0x69, 0x73, 0x74, 0x43, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, - 0x70, 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x13, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4e, 0x6f, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x12, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4f, 0x4b, 0x52, 0x65, - 0x73, 0x70, 0x42, 0x2e, 0x5a, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x33, 0x30, 0x63, 0x6d, 0x2e, - 0x6e, 0x65, 0x74, 0x2f, 0x64, 0x69, 0x67, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x70, 0x2d, - 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x65, 0x70, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, - 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -}) + 0x07, 0x65, 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x3b, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, + 0x43, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, + 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4b, 0x6c, 0x69, 0x6e, 0x65, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xb5, 0x03, 0x0a, 0x05, 0x4b, 0x6c, 0x69, 0x6e, 0x65, 0x12, + 0x1b, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x08, 0x6f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x6f, 0x70, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6f, 0x70, 0x65, 0x6e, + 0x12, 0x12, 0x0a, 0x04, 0x68, 0x69, 0x67, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x68, 0x69, 0x67, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x6c, 0x6f, 0x77, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x6c, 0x6f, 0x77, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x76, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x5f, 0x74, 0x69, + 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x54, + 0x69, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x12, 0x71, 0x75, 0x6f, 0x74, 0x65, 0x5f, 0x61, 0x73, 0x73, + 0x65, 0x74, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x10, 0x71, 0x75, 0x6f, 0x74, 0x65, 0x41, 0x73, 0x73, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x6f, 0x66, 0x5f, 0x74, + 0x72, 0x61, 0x64, 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x6e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x4f, 0x66, 0x54, 0x72, 0x61, 0x64, 0x65, 0x73, 0x12, 0x3c, 0x0a, 0x1b, 0x74, + 0x61, 0x6b, 0x65, 0x72, 0x5f, 0x62, 0x75, 0x79, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x61, 0x73, + 0x73, 0x65, 0x74, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x17, 0x74, 0x61, 0x6b, 0x65, 0x72, 0x42, 0x75, 0x79, 0x42, 0x61, 0x73, 0x65, 0x41, 0x73, + 0x73, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x3e, 0x0a, 0x1c, 0x74, 0x61, 0x6b, + 0x65, 0x72, 0x5f, 0x62, 0x75, 0x79, 0x5f, 0x71, 0x75, 0x6f, 0x74, 0x65, 0x5f, 0x61, 0x73, 0x73, + 0x65, 0x74, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x18, 0x74, 0x61, 0x6b, 0x65, 0x72, 0x42, 0x75, 0x79, 0x51, 0x75, 0x6f, 0x74, 0x65, 0x41, 0x73, + 0x73, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x6d, + 0x62, 0x6f, 0x6c, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x79, 0x6d, 0x62, 0x6f, + 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x18, 0x0d, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x32, 0xa1, 0x02, + 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x4e, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x79, 0x6d, 0x62, 0x6f, + 0x6c, 0x73, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, + 0x79, 0x4b, 0x6c, 0x69, 0x6e, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x52, + 0x65, 0x71, 0x1a, 0x12, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, + 0x4f, 0x4b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x48, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x61, + 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, + 0x1a, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4c, 0x69, + 0x73, 0x74, 0x43, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, + 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x13, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4e, 0x6f, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x12, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x2e, 0x4f, 0x4b, 0x52, 0x65, 0x73, + 0x70, 0x42, 0x2e, 0x5a, 0x2c, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x33, 0x30, 0x63, 0x6d, 0x2e, 0x6e, + 0x65, 0x74, 0x2f, 0x64, 0x69, 0x67, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x70, 0x2d, 0x63, + 0x6c, 0x6f, 0x75, 0x64, 0x65, 0x70, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} var ( file_generate_rpc_blockchain_proto_rawDescOnce sync.Once - file_generate_rpc_blockchain_proto_rawDescData []byte + file_generate_rpc_blockchain_proto_rawDescData = file_generate_rpc_blockchain_proto_rawDesc ) func file_generate_rpc_blockchain_proto_rawDescGZIP() []byte { file_generate_rpc_blockchain_proto_rawDescOnce.Do(func() { - file_generate_rpc_blockchain_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_generate_rpc_blockchain_proto_rawDesc), len(file_generate_rpc_blockchain_proto_rawDesc))) + file_generate_rpc_blockchain_proto_rawDescData = protoimpl.X.CompressGZIP(file_generate_rpc_blockchain_proto_rawDescData) }) return file_generate_rpc_blockchain_proto_rawDescData } -var file_generate_rpc_blockchain_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_generate_rpc_blockchain_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_generate_rpc_blockchain_proto_goTypes = []any{ (*OKResp)(nil), // 0: blockchain.OKResp (*NoneReq)(nil), // 1: blockchain.NoneReq @@ -448,22 +626,24 @@ var file_generate_rpc_blockchain_proto_goTypes = []any{ (*Symbol)(nil), // 4: blockchain.Symbol (*HistoryReq)(nil), // 5: blockchain.HistoryReq (*ListCandleDataResp)(nil), // 6: blockchain.ListCandleDataResp + (*Kline)(nil), // 7: blockchain.Kline } var file_generate_rpc_blockchain_proto_depIdxs = []int32{ 4, // 0: blockchain.ListSymbolsResponse.symbols:type_name -> blockchain.Symbol - 2, // 1: blockchain.BlockchainService.ListSymbols:input_type -> blockchain.ListSymbolsRequest - 5, // 2: blockchain.BlockchainService.GetHistoryKlineData:input_type -> blockchain.HistoryReq - 5, // 3: blockchain.BlockchainService.ListCandleData:input_type -> blockchain.HistoryReq - 1, // 4: blockchain.BlockchainService.Ping:input_type -> blockchain.NoneReq - 3, // 5: blockchain.BlockchainService.ListSymbols:output_type -> blockchain.ListSymbolsResponse - 0, // 6: blockchain.BlockchainService.GetHistoryKlineData:output_type -> blockchain.OKResp - 6, // 7: blockchain.BlockchainService.ListCandleData:output_type -> blockchain.ListCandleDataResp - 0, // 8: blockchain.BlockchainService.Ping:output_type -> blockchain.OKResp - 5, // [5:9] is the sub-list for method output_type - 1, // [1:5] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 7, // 1: blockchain.ListCandleDataResp.data:type_name -> blockchain.Kline + 2, // 2: blockchain.BlockchainService.ListSymbols:input_type -> blockchain.ListSymbolsRequest + 5, // 3: blockchain.BlockchainService.GetHistoryKlineData:input_type -> blockchain.HistoryReq + 5, // 4: blockchain.BlockchainService.ListCandleData:input_type -> blockchain.HistoryReq + 1, // 5: blockchain.BlockchainService.Ping:input_type -> blockchain.NoneReq + 3, // 6: blockchain.BlockchainService.ListSymbols:output_type -> blockchain.ListSymbolsResponse + 0, // 7: blockchain.BlockchainService.GetHistoryKlineData:output_type -> blockchain.OKResp + 6, // 8: blockchain.BlockchainService.ListCandleData:output_type -> blockchain.ListCandleDataResp + 0, // 9: blockchain.BlockchainService.Ping:output_type -> blockchain.OKResp + 6, // [6:10] is the sub-list for method output_type + 2, // [2:6] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_generate_rpc_blockchain_proto_init() } @@ -475,9 +655,9 @@ func file_generate_rpc_blockchain_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: unsafe.Slice(unsafe.StringData(file_generate_rpc_blockchain_proto_rawDesc), len(file_generate_rpc_blockchain_proto_rawDesc)), + RawDescriptor: file_generate_rpc_blockchain_proto_rawDesc, NumEnums: 0, - NumMessages: 7, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, @@ -486,6 +666,7 @@ func file_generate_rpc_blockchain_proto_init() { MessageInfos: file_generate_rpc_blockchain_proto_msgTypes, }.Build() File_generate_rpc_blockchain_proto = out.File + file_generate_rpc_blockchain_proto_rawDesc = nil file_generate_rpc_blockchain_proto_goTypes = nil file_generate_rpc_blockchain_proto_depIdxs = nil } diff --git a/generate/rpc/blockchain.proto b/generate/rpc/blockchain.proto index 189334c..a3168b0 100644 --- a/generate/rpc/blockchain.proto +++ b/generate/rpc/blockchain.proto @@ -34,9 +34,27 @@ message HistoryReq { } message ListCandleDataResp { - + repeated Kline data=1; } +// 單根 K 線 +message Kline { + int64 open_time = 1; // 開盤時間(毫秒) + string open = 2; // 開盤價 + string high = 3; // 最高價 + string low = 4; // 最低價 + string close = 5; // 收盤價 + string volume = 6; // 成交量 + int64 close_time = 7; // 收盤時間(毫秒) + string quote_asset_volume = 8; // 成交額(以報價資產計) + int32 number_of_trades = 9; // 交易筆數 + string taker_buy_base_asset_volume = 10; // 主動買入成交量 + string taker_buy_quote_asset_volume = 11; // 主動買入成交額 + string symbol = 12; // 交易對 (partition key) + string interval = 13; // K 線區間 (partition key) e.g. 1d, 4h, 15m +} + + service BlockchainService{ // ListSymbols retrieves all available trading symbols. rpc ListSymbols(ListSymbolsRequest) returns(ListSymbolsResponse); diff --git a/internal/domain/blockchain/binance.go b/internal/domain/blockchain/binance.go index 815111b..ac2e0f4 100644 --- a/internal/domain/blockchain/binance.go +++ b/internal/domain/blockchain/binance.go @@ -2,3 +2,5 @@ package blockchain const BinanceHistoryDataBase = "https://data.binance.vision" const BinanceHistoryDataKlines = "/data/spot/daily/klines" + +const BinanceHistoryMonthlyKLines = "/data/spot/monthly/klines" diff --git a/internal/logic/blockchainservice/list_candle_data_logic.go b/internal/logic/blockchainservice/list_candle_data_logic.go index 960eafa..d5df84f 100644 --- a/internal/logic/blockchainservice/list_candle_data_logic.go +++ b/internal/logic/blockchainservice/list_candle_data_logic.go @@ -46,8 +46,27 @@ func (l *ListCandleDataLogic) ListCandleData(in *app_cloudep_blockchain.HistoryR if err != nil { return nil, err } + res := make([]*app_cloudep_blockchain.Kline, 0, len(kline)) - fmt.Println(kline) + for _, item := range kline { + res = append(res, &app_cloudep_blockchain.Kline{ + OpenTime: item.OpenTime, + Open: item.Open, + High: item.High, + Low: item.Low, + Close: item.Close, + Volume: item.Volume, + CloseTime: item.OpenTime, + QuoteAssetVolume: item.QuoteAssetVolume, + NumberOfTrades: int32(item.NumberOfTrades), + TakerBuyBaseAssetVolume: item.TakerBuyBaseAssetVolume, + TakerBuyQuoteAssetVolume: item.TakerBuyQuoteAssetVolume, + Symbol: item.Symbol, + Interval: item.Interval, + }) + } - return &app_cloudep_blockchain.ListCandleDataResp{}, nil + return &app_cloudep_blockchain.ListCandleDataResp{ + Data: res, + }, nil } diff --git a/internal/repository/data_source_binance.go b/internal/repository/data_source_binance.go index 4f90726..3497e3e 100644 --- a/internal/repository/data_source_binance.go +++ b/internal/repository/data_source_binance.go @@ -143,19 +143,34 @@ func (repo *BinanceRepository) GetSymbols(ctx context.Context) ([]*entity.Symbol func (repo *BinanceRepository) FetchHistoryKline(ctx context.Context, param repository.QueryKline) ([]*entity.Kline, error) { start := time.Unix(0, param.StartTime) end := time.Unix(0, param.EndTime) + const weeks = 168 * time.Hour var allKLines []*entity.Kline - // 產生所有天的任務 - for d := start; !d.After(end); d = d.AddDate(0, 0, 1) { - day := d - a, err := repo.fetchHistoryKline(ctx, param.Symbol, param.Interval, day.Format(time.DateOnly)) - if err != nil { - logx.Errorf("failed to get history of kline : %v", err) + if end.Sub(start) >= weeks { + // 用 monthly + for t := start; t.Before(end); t = t.AddDate(0, 1, 0) { + month := t + ks, err := repo.fetchHistoryKline(ctx, param.Symbol, param.Interval, month.Format("2006-01"), blockchain.BinanceHistoryMonthlyKLines) + if err != nil { + logx.Errorf("failed to get history of kline : %v", err) - continue + continue + } + allKLines = append(allKLines, ks...) + } + } else { + // 產生所有天的任務 + for d := start; !d.After(end); d = d.AddDate(0, 0, 1) { + day := d + a, err := repo.fetchHistoryKline(ctx, param.Symbol, param.Interval, day.Format(time.DateOnly), blockchain.BinanceHistoryDataKlines) + if err != nil { + logx.Errorf("failed to get history of kline : %v", err) + + continue + } + allKLines = append(allKLines, a...) } - allKLines = append(allKLines, a...) } return allKLines, nil @@ -237,8 +252,8 @@ func (repo *BinanceRepository) getSymbolsFromSource(ctx context.Context) ([]bina return info.Symbols, nil } -func (repo *BinanceRepository) fetchHistoryKline(ctx context.Context, symbol string, interval string, date string) ([]*entity.Kline, error) { - baseURL := fmt.Sprintf("%s%s", blockchain.BinanceHistoryDataBase, blockchain.BinanceHistoryDataKlines) +func (repo *BinanceRepository) fetchHistoryKline(ctx context.Context, symbol string, interval string, date string, kType string) ([]*entity.Kline, error) { + baseURL := fmt.Sprintf("%s%s", blockchain.BinanceHistoryDataBase, kType) symbol = strings.ToUpper(symbol) zipFile := fmt.Sprintf("%s-%s-%s.zip", symbol, interval, date) url := fmt.Sprintf("%s/%s/%s/%s", baseURL, symbol, interval, zipFile) diff --git a/internal/server/blockchainservice/blockchain_service_server.go b/internal/server/blockchainservice/blockchain_service_server.go index 581dbf7..586be34 100644 --- a/internal/server/blockchainservice/blockchain_service_server.go +++ b/internal/server/blockchainservice/blockchain_service_server.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.8.5 +// goctl 1.8.1 // Source: blockchain.proto package server