Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
90b9cf58
Commit
90b9cf58
authored
May 12, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update processor
parent
c1cf3bd2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
6 deletions
+17
-6
klinegenerator.go
exchain/exmonitor/klinegenerator.go
+1
-1
markethandle.go
exchain/exmonitor/markethandle.go
+2
-2
monitor.go
exchain/exmonitor/monitor.go
+1
-1
processor.go
exchain/exmonitor/processor.go
+13
-2
No files found.
exchain/exmonitor/klinegenerator.go
View file @
90b9cf58
...
...
@@ -25,7 +25,7 @@ type KLineGeneratorJob struct {
ProcessorFactory
CoinProcessorFactory
}
func
NewKLineGeneratorJob
(
factory
CoinProcessorFactory
,
service
MarketService
)
*
KLineGeneratorJob
{
func
NewKLineGeneratorJob
(
factory
CoinProcessorFactory
)
*
KLineGeneratorJob
{
return
&
KLineGeneratorJob
{
ProcessorFactory
:
factory
,
}
...
...
exchain/exmonitor/markethandle.go
View file @
90b9cf58
...
...
@@ -14,7 +14,7 @@ type mongoMarketHandler struct {
// HandleTrade inserts an ExchangeTrade into the corresponding collection
func
(
h
*
mongoMarketHandler
)
HandleTrade
(
symbol
string
,
trade
*
ExchangeTrade
)
error
{
collection
:=
h
.
db
.
Collection
(
"exchange_trade_"
+
symbol
)
collection
:=
h
.
db
.
Collection
(
tradePrefix
+
symbol
)
_
,
err
:=
collection
.
InsertOne
(
context
.
Background
(),
trade
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to insert trade: %v"
,
err
)
...
...
@@ -24,7 +24,7 @@ func (h *mongoMarketHandler) HandleTrade(symbol string, trade *ExchangeTrade) er
// HandleKLine inserts a KLine into the corresponding collection
func
(
h
*
mongoMarketHandler
)
HandleKLine
(
symbol
string
,
kline
*
KLine
)
error
{
collection
:=
h
.
db
.
Collection
(
"exchange_kline_"
+
symbol
+
"_"
+
kline
.
Period
)
collection
:=
h
.
db
.
Collection
(
klinePrefix
+
symbol
+
"_"
+
kline
.
Period
)
_
,
err
:=
collection
.
InsertOne
(
context
.
Background
(),
kline
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to insert KLine: %v"
,
err
)
...
...
exchain/exmonitor/monitor.go
View file @
90b9cf58
...
...
@@ -9,7 +9,7 @@ type Monitor struct {
func
NewMonitor
(
conf
*
config
.
Config
)
*
Monitor
{
service
:=
NewMarketService
(
conf
)
kline
:=
NewKLineGeneratorJob
(
&
coinProcessorFactory
{},
service
)
kline
:=
NewKLineGeneratorJob
(
NewCoinProcessorFactory
(
service
)
)
return
&
Monitor
{
kline
:
kline
,
...
...
exchain/exmonitor/processor.go
View file @
90b9cf58
...
...
@@ -41,7 +41,7 @@ type ExchangeTrade struct {
type
MarketHandler
interface
{
HandleTrade
(
symbol
string
,
trade
*
ExchangeTrade
)
error
HandleKLine
(
symbol
string
,
kline
*
KLine
)
HandleKLine
(
symbol
string
,
kline
*
KLine
)
error
}
type
MarketService
interface
{
...
...
@@ -50,6 +50,7 @@ type MarketService interface {
FindTradeByTimeRange
(
symbol
string
,
start
,
end
int64
)
[]
*
ExchangeTrade
FindAllKLineByTimeRange
(
symbol
string
,
fromTime
,
toTime
int64
,
period
string
)
[]
*
KLine
SaveKLine
(
symbol
string
,
kline
*
KLine
)
NewHandler
(
symbol
string
)
MarketHandler
}
type
DefaultCoinProcessor
struct
{
...
...
@@ -67,20 +68,30 @@ type DefaultCoinProcessor struct {
type
coinProcessorFactory
struct
{
mux
sync
.
Mutex
service
MarketService
coinProcessors
map
[
string
]
*
DefaultCoinProcessor
}
func
NewCoinProcessorFactory
(
service
MarketService
)
CoinProcessorFactory
{
return
&
coinProcessorFactory
{
service
:
service
,
coinProcessors
:
make
(
map
[
string
]
*
DefaultCoinProcessor
),
}
}
func
(
cpf
*
coinProcessorFactory
)
GetCoinProcessor
(
symbol
,
baseCoin
string
)
*
DefaultCoinProcessor
{
cpf
.
mux
.
Lock
()
defer
cpf
.
mux
.
Unlock
()
if
processor
,
exists
:=
cpf
.
coinProcessors
[
symbol
];
exists
{
return
processor
}
else
{
// todo: initialize the processor with the service.
processor
=
&
DefaultCoinProcessor
{
symbol
:
symbol
,
baseCoin
:
baseCoin
,
currentKLine
:
createNewKLine
(),
handlers
:
[]
MarketHandler
{}
,
handlers
:
make
([]
MarketHandler
,
0
)
,
coinThumb
:
&
CoinThumb
{},
isHalt
:
true
,
stopKLine
:
false
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment