Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@ivopetiz
CreatedJune 9, 2018 22:43
    • Star(3)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist
    Save ivopetiz/051eb8dcef769e655254df21a093831a to your computer and use it in GitHub Desktop.
    Saves data from Bittrex markets to csv.
    package main
    import (
    "os"
    //"fmt"
    "log"
    "time"
    "strings"
    "strconv"
    "encoding/csv"
    "github.com/jyap808/go-bittrex"
    //"github.com/shopspring/decimal"
    )
    const (
    count=10
    API_KEY=""
    API_SECRET=""
    HOME="/home/machine/market/"
    )
    var (
    num=0
    _bittrex=true
    //intrvl = 5
    // MARKETS
    _BTC=true
    _USDT=true
    )
    funcmain() {
    f,err:=os.OpenFile("/logs/altdb_coin_alt.log",os.O_WRONLY|os.O_CREATE|os.O_APPEND,0644)
    iferr!=nil {
    log.Println(err)
    }
    deferf.Close()
    log.SetOutput(f)
    // BITTREX
    bittrex:=bittrex.New(API_KEY,API_SECRET)
    interval:=5*time.Second
    fortrue {
    start_time:=time.Now()
    // BITTREX PART
    if_bittrex {
    marketSummaries,err:=bittrex.GetMarketSummaries()
    iferr!=nil {
    log.Println(err)
    }
    today:=time.Now()
    file_name:="_"+today.Format("02-01-2006")+".csv"
    for_,coin:=rangemarketSummaries {
    // Check non desired markets.
    ifstrings.HasPrefix(coin.MarketName,"ETH") {continue}
    // Create file or append to an existing csv file.
    file,err:=os.OpenFile(HOME+"data/"+coin.MarketName+file_name,os.O_WRONLY|os.O_CREATE|os.O_APPEND,0644)
    iferr!=nil {
    log.Println(err)
    }
    writer:=csv.NewWriter(file)
    fileInfo,err:=os.Stat(HOME+"data/"+coin.MarketName+file_name)
    iferr!=nil {log.Fatal(err)}
    iffileInfo.Size()==0 {
    writer.Write([]string{"","Ask","BaseVolume","Bid","High","Last","Low","OpenBuy","OpenSell","time"})
    }
    vardata= []string{
    strconv.Itoa(num),
    strconv.FormatFloat(coin.Ask,'E',-1,64),
    strconv.FormatFloat(coin.BaseVolume,'E',-1,64),
    strconv.FormatFloat(coin.Bid,'E',-1,64),
    strconv.FormatFloat(coin.High,'E',-1,64),
    strconv.FormatFloat(coin.Last,'E',-1,64),
    strconv.FormatFloat(coin.Low,'E',-1,64),
    strconv.Itoa(coin.OpenBuyOrders),
    strconv.Itoa(coin.OpenSellOrders),
    coin.TimeStamp}
    err=writer.Write(data)
    iferr!=nil {
    log.Println(err)
    }
    writer.Flush()
    file.Close()
    }
    }
    num++
    elapsed:=time.Since(start_time)
    ifelapsed<interval {
    time.Sleep(interval-elapsed)
    }
    }
    }
    @cryptodogofmax
    Copy link

    Thanks for sharing. May I know how to run this .go file for the crypto repository?

    @ivopetiz
    Copy link
    Author

    hello. Just need to 'go run' it and it will generate csv files with data from Bittrex.

    @vpolimenov
    Copy link

    what about collecting data from Binance?

    @ivopetiz
    Copy link
    Author

    I didn't need to for now. Maybe implement it later but the code shouldn't vary much from the Bittrex version.

    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp