Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 8ea4b1e

Browse files
authored
copy ccxt zip from source near binary to dotKelp/ccxt folder and proceed to unzipping step (#410)
1 parent bddb25a commit 8ea4b1e

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

cmd/server_amd64.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ func init() {
245245
filenameWithExt := fmt.Sprintf("%s.zip", ccxtFilenameNoExt)
246246

247247
// don't use explicit unix filepath here since it uses os.Stat and os.Create directly and won't work on windows
248-
ccxtZipDownloadPath := ccxtDirPath.Join(filenameWithExt)
249-
e = downloadCcxtBinary(kos, ccxtDirPath, ccxtZipDownloadPath, filenameWithExt)
248+
ccxtBundledZipPath := kos.GetBinDir().Join("ccxt").Join(filenameWithExt)
249+
ccxtZipDestPath := ccxtDirPath.Join(filenameWithExt)
250+
e = copyOrDownloadCcxtBinary(kos, ccxtBundledZipPath, ccxtDirPath, ccxtZipDestPath, filenameWithExt)
250251
if e != nil {
251252
panic(e)
252253
}
@@ -363,21 +364,43 @@ func setMiddleware(r *chi.Mux) {
363364
r.Use(middleware.Timeout(60 * time.Second))
364365
}
365366

366-
func downloadCcxtBinary(kos *kelpos.KelpOS, ccxtDirPath *kelpos.OSPath, ccxtZipDownloadPath *kelpos.OSPath, filenameWithExt string) error {
367+
func copyOrDownloadCcxtBinary(
368+
kos *kelpos.KelpOS,
369+
ccxtBundledZipPath *kelpos.OSPath,
370+
ccxtDirPath *kelpos.OSPath,
371+
ccxtZipDestPath *kelpos.OSPath,
372+
filenameWithExt string,
373+
) error {
367374
log.Printf("mkdir ccxtDirPath: %s ...", ccxtDirPath.AsString())
368375
e := kos.Mkdir(ccxtDirPath)
369376
if e != nil {
370377
return errors.Wrap(e, "could not mkdir for ccxtDirPath: "+ccxtDirPath.AsString())
371378
}
372379

373-
if _, e := os.Stat(ccxtZipDownloadPath.Native()); !os.IsNotExist(e) {
380+
if _, e := os.Stat(ccxtZipDestPath.Native()); !os.IsNotExist(e) {
381+
return nil
382+
}
383+
384+
if _, e := os.Stat(ccxtBundledZipPath.Native()); !os.IsNotExist(e) {
385+
log.Printf("copying ccxt from %s to location %s ...", ccxtBundledZipPath.Unix(), ccxtZipDestPath.Unix())
386+
387+
cpCmd := fmt.Sprintf("cp %s %s", ccxtBundledZipPath.Unix(), ccxtZipDestPath.Unix())
388+
_, e = kos.Blocking("cp-ccxt", cpCmd)
389+
if e != nil {
390+
return fmt.Errorf("unable to copy ccxt zip file from %s to %s: %s", ccxtBundledZipPath.Unix(), ccxtZipDestPath.Unix(), e)
391+
}
392+
log.Printf("... done copying ccxt from %s to location %s", ccxtBundledZipPath.Unix(), ccxtZipDestPath.Unix())
393+
374394
return nil
375395
}
396+
log.Printf("did not find ccxt zip file at source %s, proceeding to download", ccxtBundledZipPath.Unix())
397+
398+
// else download
376399
downloadURL := fmt.Sprintf("%s/%s", ccxtDownloadBaseURL, filenameWithExt)
377-
log.Printf("download ccxt from %s to location: %s ...", downloadURL, ccxtZipDownloadPath.AsString())
400+
log.Printf("download ccxt from %s to location: %s ...", downloadURL, ccxtZipDestPath.AsString())
378401
e = networking.DownloadFileWithGrab(
379402
downloadURL,
380-
ccxtZipDownloadPath.Native(),
403+
ccxtZipDestPath.Native(),
381404
downloadCcxtUpdateIntervalLogMillis,
382405
func(statusCode int, statusString string) {
383406
log.Printf(" response_status = %s, code = %d\n", statusString, statusCode)
@@ -396,7 +419,7 @@ func downloadCcxtBinary(kos *kelpos.KelpOS, ccxtDirPath *kelpos.OSPath, ccxtZipD
396419
},
397420
)
398421
if e != nil {
399-
return fmt.Errorf("could not download ccxt from '%s' to location '%s': %s", downloadURL, ccxtZipDownloadPath.AsString(), e)
422+
return fmt.Errorf("could not download ccxt from '%s' to location '%s': %s", downloadURL, ccxtZipDestPath.AsString(), e)
400423
}
401424
return nil
402425
}

0 commit comments

Comments
 (0)