trade

package
v0.0.0-...-c17c338 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 15 Imported by: 0

README

GoCryptoTrader package Trade

Build Status Software License GoDoc Coverage Status Go Report Card

This trade package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for trade

  • The trade package contains a processor for both REST and websocket trade history processing
    • Its primary purpose is to collect trade data from multiple sources and save it to the database's trade table
    • If you do not have database enabled, then trades will not be processed
Requirements to save a trade to the database
  • Database has to be enabled
  • Under config.json, under your selected exchange, enable the field saveTradeData
    • This will enable trade processing to occur for that specific exchange
    • This can also be done via gRPC under the SetExchangeTradeProcessing command
Usage
  • To send trade data to be processed, use the following example:
err := trade.AddTradesToBuffer(b.Name, trade.Data{
    Exchange:     b.Name,
    TID:          strconv.FormatInt(tradeData[i].TID, 10),
    CurrencyPair: p,
    AssetType:    assetType,
    Side:         side,
    Price:        tradeData[i].Price,
    Amount:       tradeData[i].Amount,
    Timestamp:    tradeTS,
})

b in this context is an IBotExchange implemented struct

Rules
  • If the trade processor has not started, it will automatically start upon being sent trade data.
  • The processor will add all received trades to a buffer
  • After 15 seconds, the trade processor will parse and save all trades on the buffer to the trade table
    • This is to save on constant writing to the database. Trade data, especially when received via websocket would cause massive issues on the round trip of saving data for every trade
  • If the processor has not received any trades in that 15 second timeframe, it will shut down.
    • Sending trade data to it later will automatically start it up again

Exchange Support Table

Exchange Recent Trades via REST Live trade updates via Websocket Trade history via REST
Alphapoint No No No
Binance Yes Yes Yes
Bitfinex Yes Yes Yes
Bitflyer Yes No No
Bithumb Yes Yes No
BitMEX Yes Yes Yes
Bitstamp Yes Yes No
Bittrex Yes Yes No
BTCMarkets Yes Yes No
BTSE Yes Yes No
Coinbene Yes Yes No
CoinbasePro Yes Yes No
COINUT Yes Yes No
Exmo Yes NA No
FTX Yes Yes Yes
GateIO Yes Yes No
Gemini Yes Yes Yes
HitBTC Yes Yes Yes
Huobi.Pro Yes Yes No
ItBit Yes NA No
Kraken Yes Yes No
Lbank Yes No Yes
LocalBitcoins Yes NA No
OKCoin International Yes Yes No
OKEX Yes Yes No
Poloniex Yes Yes Yes
Yobit Yes NA No
ZB.COM Yes Yes No
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

View Source
const DefaultProcessorIntervalTime = time.Second * 15

DefaultProcessorIntervalTime is the default timer to process queued trades and save them to the database

Variables

View Source
var (

	// BufferProcessorIntervalTime is the interval to save trade buffer data to the database.
	// Change this by changing the runtime param `-tradeprocessinginterval=15s`
	BufferProcessorIntervalTime = DefaultProcessorIntervalTime
	// ErrNoTradesSupplied is returned when an attempt is made to process trades, but is an empty slice
	ErrNoTradesSupplied = errors.New("no trades supplied")
)

Functions

func AddTradesToBuffer

func AddTradesToBuffer(exchangeName string, data ...Data) error

AddTradesToBuffer will push trade data onto the buffer

func ConvertTradesToCandles

func ConvertTradesToCandles(interval kline.Interval, trades ...Data) (kline.Item, error)

ConvertTradesToCandles turns trade data into kline.Items

func HasTradesInRanges

func HasTradesInRanges(exchangeName, assetType, base, quote string, rangeHolder *kline.IntervalRangeHolder) error

HasTradesInRanges Creates an executes an SQL query to verify if a trade exists within a timeframe

func SaveTradesToDatabase

func SaveTradesToDatabase(trades ...Data) error

SaveTradesToDatabase converts trades and saves results to database

Types

type ByDate

type ByDate []Data

ByDate sorts trades by date ascending

func (ByDate) Len

func (b ByDate) Len() int

func (ByDate) Less

func (b ByDate) Less(i, j int) bool

func (ByDate) Swap

func (b ByDate) Swap(i, j int)

type Data

type Data struct {
	ID           uuid.UUID `json:"ID,omitempty"`
	TID          string
	Exchange     string
	CurrencyPair currency.Pair
	AssetType    asset.Item
	Side         order.Side
	Price        float64
	Amount       float64
	Timestamp    time.Time
}

Data defines trade data

func FilterTradesByTime

func FilterTradesByTime(trades []Data, startTime, endTime time.Time) []Data

FilterTradesByTime removes any trades that are not between the start and end times

func GetTradesInRange

func GetTradesInRange(exchangeName, assetType, base, quote string, startDate, endDate time.Time) ([]Data, error)

GetTradesInRange calls db function to return trades in range to minimise tradesql package usage

func SQLDataToTrade

func SQLDataToTrade(dbTrades ...tradesql.Data) (result []Data, err error)

SQLDataToTrade converts sql data to glorious trade data

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor used for processing trade data in batches and saving them to the database

func (*Processor) Run

func (p *Processor) Run(wg *sync.WaitGroup)

Run will save trade data to the database in batches

type Trade

type Trade struct {
	// contains filtered or unexported fields
}

Trade used to hold data and methods related to trade dissemination and storage

func (*Trade) Setup

func (t *Trade) Setup(exchangeName string, tradeFeedEnabled bool, c chan interface{})

Setup configures necessary fields to the `Trade` structure that govern trade data processing.

func (*Trade) Update

func (t *Trade) Update(save bool, data ...Data) error

Update processes trade data, either by saving it or routing it through the data channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL