-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
340 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/defipod/mochi/pkg/config" | ||
"github.com/defipod/mochi/pkg/entities" | ||
"github.com/defipod/mochi/pkg/job" | ||
"github.com/defipod/mochi/pkg/logger" | ||
) | ||
|
||
func main() { | ||
cfg := config.LoadConfig(config.DefaultConfigLoaders()) | ||
log := logger.NewLogrusLogger() | ||
// *** entities *** | ||
err := entities.Init(cfg, log) | ||
if err != nil { | ||
log.Fatal(err, "failed to init entities") | ||
} | ||
entity := entities.Get() | ||
defer entity.GetSvc().Sentry.Flush(2 * time.Second) | ||
|
||
if err := job.NewCrawlBinanceSpotTransactionsJob(entity, log).Run(); err != nil { | ||
log.Fatal(err, "failed to run job") | ||
} | ||
|
||
log.Info("done") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
migrations/schemas/20240423200849-create_binance_tracking_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
-- +migrate Up | ||
create table if not exists binance_trackings ( | ||
id serial primary key, | ||
profile_id text, | ||
spot_last_time timestamp | ||
); | ||
|
||
create table binance_spot_transactions ( | ||
id serial, | ||
profile_id text, | ||
symbol text, | ||
order_id integer, | ||
order_list_id integer, | ||
client_order_id text, | ||
price text, | ||
orig_qty text, | ||
executed_qty text, | ||
cumulative_quote_qty text, | ||
status text, | ||
time_in_force text, | ||
type text, | ||
side text, | ||
stop_price text, | ||
iceberg_qty text, | ||
time timestamp, | ||
update_time timestamp, | ||
is_working boolean, | ||
orig_quote_order_qty text, | ||
working_time timestamp, | ||
self_trade_prevention_mode text | ||
); | ||
|
||
create unique index binance_spot_transactions_profile_id_order_id_index on binance_spot_transactions (profile_id, order_id); | ||
-- +migrate Down | ||
drop table if exists binance_trackings; | ||
drop index if exists binance_spot_transactions_profile_id_order_id_index; | ||
drop table if exists binance_spot_transactions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package job | ||
|
||
import ( | ||
"github.com/defipod/mochi/pkg/entities" | ||
"github.com/defipod/mochi/pkg/logger" | ||
) | ||
|
||
type crawlBinanceSpotTransactions struct { | ||
entity *entities.Entity | ||
log logger.Logger | ||
} | ||
|
||
func NewCrawlBinanceSpotTransactionsJob(e *entities.Entity, l logger.Logger) Job { | ||
return &crawlBinanceSpotTransactions{ | ||
entity: e, | ||
log: l, | ||
} | ||
} | ||
|
||
func (j *crawlBinanceSpotTransactions) Run() error { | ||
j.log.Infof("Start crawling binance spot transaction ...") | ||
j.entity.CrawlBinanceSpotTransactions() | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type BinanceSpotTransaction struct { | ||
ID int64 `json:"id"` | ||
ProfileId string `json:"profile_id"` | ||
Symbol string `json:"symbol"` | ||
OrderId int64 `json:"order_id"` | ||
OrderListId int64 `json:"order_list_id"` | ||
ClientOrderId string `json:"client_order_id"` | ||
Price string `json:"price"` | ||
OrigQty string `json:"orig_qty"` | ||
ExecutedQty string `json:"executed_qty"` | ||
CummulativeQuoteQty string `json:"cummulative_quote_qty"` | ||
Status string `json:"status"` | ||
TimeInForce string `json:"time_in_force"` | ||
Type string `json:"type"` | ||
Side string `json:"side"` | ||
StopPrice string `json:"stop_price"` | ||
IcebergQty string `json:"iceberg_qty"` | ||
Time time.Time `json:"time"` | ||
UpdateTime time.Time `json:"update_time"` | ||
IsWorking bool `json:"is_working"` | ||
OrigQuoteOrderQty string `json:"orig_quote_order_qty"` | ||
WorkingTime time.Time `json:"working_time"` | ||
SelfTradePreventionMode string `json:"self_trade_prevention_mode"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type BinanceTracking struct { | ||
ID int64 `json:"id"` | ||
ProfileId string `json:"profile_id"` | ||
SpotLastTime time.Time `json:"spot_last_time"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package binancespottransaction | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
|
||
"github.com/defipod/mochi/pkg/model" | ||
) | ||
|
||
type pg struct { | ||
db *gorm.DB | ||
} | ||
|
||
func NewPG(db *gorm.DB) Store { | ||
return &pg{db: db} | ||
} | ||
|
||
func (pg *pg) Create(tx *model.BinanceSpotTransaction) error { | ||
return pg.db.Create(&tx).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package binancespottransaction | ||
|
||
import "github.com/defipod/mochi/pkg/model" | ||
|
||
type Store interface { | ||
Create(tx *model.BinanceSpotTransaction) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package binancetracking | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
|
||
"github.com/defipod/mochi/pkg/model" | ||
) | ||
|
||
type pg struct { | ||
db *gorm.DB | ||
} | ||
|
||
func NewPG(db *gorm.DB) Store { | ||
return &pg{db: db} | ||
} | ||
|
||
func (pg *pg) FirstOrCreate(binanceTracking *model.BinanceTracking) (*model.BinanceTracking, error) { | ||
return binanceTracking, pg.db.Where("profile_id = ?", binanceTracking.ProfileId).FirstOrCreate(&binanceTracking).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package binancetracking | ||
|
||
import "github.com/defipod/mochi/pkg/model" | ||
|
||
type Store interface { | ||
FirstOrCreate(binanceTracking *model.BinanceTracking) (*model.BinanceTracking, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.