mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
remove trade sync from environ init
This commit is contained in:
parent
84775652fe
commit
724dad70bb
|
@ -22,7 +22,9 @@ import (
|
|||
|
||||
func main() {
|
||||
noChangeDir := false
|
||||
portNum := 0
|
||||
flag.BoolVar(&noChangeDir, "no-chdir", false, "do not change directory")
|
||||
flag.IntVar(&portNum, "port", 0, "server port")
|
||||
flag.Parse()
|
||||
|
||||
if !noChangeDir {
|
||||
|
@ -116,7 +118,7 @@ func main() {
|
|||
}
|
||||
|
||||
// find a free port for binding the server
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:" + strconv.Itoa(portNum))
|
||||
if err != nil {
|
||||
log.WithError(err).Error("can not bind listener")
|
||||
return
|
||||
|
|
|
@ -15,6 +15,11 @@ import CssBaseline from '@material-ui/core/CssBaseline';
|
|||
import theme from '../src/theme';
|
||||
import '../styles/globals.css'
|
||||
import {querySessions, querySyncStatus} from "../api/bbgo";
|
||||
import {Sync} from "@material-ui/icons";
|
||||
|
||||
const SyncNotStarted = 0
|
||||
const Syncing = 1
|
||||
const SyncDone = 2
|
||||
|
||||
export default function MyApp(props) {
|
||||
const {Component, pageProps} = props;
|
||||
|
@ -37,10 +42,17 @@ export default function MyApp(props) {
|
|||
let poller = null
|
||||
const pollSyncStatus = () => {
|
||||
querySyncStatus((status) => {
|
||||
if (status === false) {
|
||||
setLoading(false)
|
||||
setSyncing(false)
|
||||
clearInterval(poller)
|
||||
switch (status) {
|
||||
case SyncNotStarted:
|
||||
break
|
||||
case Syncing:
|
||||
setSyncing(true);
|
||||
break;
|
||||
case SyncDone:
|
||||
setLoading(false);
|
||||
setSyncing(false);
|
||||
clearInterval(poller);
|
||||
break;
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
|
|
|
@ -50,6 +50,15 @@ func RegisterStrategy(key string, s interface{}) {
|
|||
|
||||
var emptyTime time.Time
|
||||
|
||||
|
||||
type SyncStatus int
|
||||
|
||||
const (
|
||||
SyncNotStarted SyncStatus = iota
|
||||
Syncing
|
||||
SyncDone
|
||||
)
|
||||
|
||||
// Environment presents the real exchange data layer
|
||||
type Environment struct {
|
||||
// Notifiability here for environment is for the streaming data notification
|
||||
|
@ -70,7 +79,7 @@ type Environment struct {
|
|||
syncMutex sync.Mutex
|
||||
|
||||
syncStatusMutex sync.Mutex
|
||||
syncing bool
|
||||
syncStatus SyncStatus
|
||||
|
||||
sessions map[string]*ExchangeSession
|
||||
}
|
||||
|
@ -478,15 +487,16 @@ func (environ *Environment) Connect(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (environ *Environment) IsSyncing() bool {
|
||||
func (environ *Environment) IsSyncing() (status SyncStatus) {
|
||||
environ.syncStatusMutex.Lock()
|
||||
defer environ.syncStatusMutex.Unlock()
|
||||
return environ.syncing
|
||||
status = environ.syncStatus
|
||||
environ.syncStatusMutex.Unlock()
|
||||
return status
|
||||
}
|
||||
|
||||
func (environ *Environment) setSyncing(syncing bool) {
|
||||
func (environ *Environment) setSyncing(status SyncStatus) {
|
||||
environ.syncStatusMutex.Lock()
|
||||
environ.syncing = syncing
|
||||
environ.syncStatus = status
|
||||
environ.syncStatusMutex.Unlock()
|
||||
}
|
||||
|
||||
|
@ -495,8 +505,8 @@ func (environ *Environment) Sync(ctx context.Context) error {
|
|||
environ.syncMutex.Lock()
|
||||
defer environ.syncMutex.Unlock()
|
||||
|
||||
environ.setSyncing(true)
|
||||
defer environ.setSyncing(false)
|
||||
environ.setSyncing(Syncing)
|
||||
defer environ.setSyncing(SyncDone)
|
||||
|
||||
for _, session := range environ.sessions {
|
||||
if err := environ.syncSession(ctx, session); err != nil {
|
||||
|
@ -511,8 +521,8 @@ func (environ *Environment) SyncSession(ctx context.Context, session *ExchangeSe
|
|||
environ.syncMutex.Lock()
|
||||
defer environ.syncMutex.Unlock()
|
||||
|
||||
environ.setSyncing(true)
|
||||
defer environ.setSyncing(false)
|
||||
environ.setSyncing(Syncing)
|
||||
defer environ.setSyncing(SyncDone)
|
||||
|
||||
return environ.syncSession(ctx, session, defaultSymbols...)
|
||||
}
|
||||
|
|
|
@ -292,11 +292,6 @@ func (session *ExchangeSession) InitSymbol(ctx context.Context, environ *Environ
|
|||
var err error
|
||||
var trades []types.Trade
|
||||
if environ.TradeSync != nil {
|
||||
log.Infof("syncing trades from %s for symbol %s...", session.Exchange.Name(), symbol)
|
||||
if err := environ.TradeSync.SyncTrades(ctx, session.Exchange, symbol); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tradingFeeCurrency := session.Exchange.PlatformFeeCurrency()
|
||||
if strings.HasPrefix(symbol, tradingFeeCurrency) {
|
||||
trades, err = environ.TradeService.QueryForTradingFeeCurrency(session.Exchange.Name(), symbol, tradingFeeCurrency)
|
||||
|
|
Loading…
Reference in New Issue
Block a user