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