mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* End of day commit moving packages and setting foundation into how trade processing will go * Conformity * tdd candle generation based on received trade data, renames orderbookbuffer back to buffer for now... * Formalises test functions and designs the trade processor * Theoretical amending old candles to allow any trades that were part of an old processed candle to be more accurate. Saving of candles will only occur on previous cycles, extending memory usage a bit longer * Figures out sqlboiler for sqlite. Updates websocket entries to process trade data * One more trade data * Adds more exchange support * Adds PSQL stuff * Begins creating sql implementation * End of day commit. Helper functions and understanding sql usage in GCT * Adds delete and cleans up table design * Finishes trades conceptually. Awaits candle data update in order to translate trades to candles * Initial handling of trades in coinbene * Proto * Fixing of some bugs, attempting to address coinbene asset type ws issues * Fixes up coinbene websocket implementation for the most part * finalises coinbene websocket implementation. Adds new ability to parse currencies without a delimiter * Implements rpc commands and adds testing * updates the following to be compatible with trade data update: Theoretical amending old candles to allow any trades that were part of an old processed candle to be more accurate. Saving of candles will only occur on previous cycles, extending memory usage a bit longer * Changes trade to be its own entity rather than attached to a websocket. * Adds coverage to trades. Changes signature of `AddTradesToBuffer` to return error. Now automatically shuts down without need for channel listening. Will automatically start up again if it gets data * Implements trade fetching at the wrapper level for a bunch of exchanges. Adds trade id to script updoot. Probably breaking change * Implements trade fetching for all wrappers hurray hurrah. Updates all the tests * Adds new interface func to get recent trades. Ensures GetExchangeHistory continues until conditions are met * Adds new readme, tests all new wrapper endpoints, updates exchange_wrapper_issues to test new endpoints. Updates exchange_wrapper_coverage with new coverage... Fixes lame bug causing wrapper tests to fail from being poorly setup. Adds loopy loop to ensure that all data is captured when requesting exchange history * Bugfix on psql migrations. Rebases latest changes, updates table design to use base and quote, updates trades to use exchange_name_id * Adds new config field for saving trades to the database per exchange. Now exits trade processing when trade saving is not enabled. Similarly for wrapper, does not save if not enabled * Minor bitfinex trade fixes. continues on buffer processing errors, now saves transactionid to the db * Adds support for generating candles from candlesextended. May extend it further, idk * Updates trade candles to be able to fill missing data with trades. Adds more tests. Also does a thing where you can forcefully override a candle based on internal trade data instead of API data * Fixes bug where force deletions did not follow up with insertions. Adds force to candle commands * Fixes specific exchange based issues. Extends recent trades to 24 hours where possible * Fixes issue with saved tests. Fixes tests for trades. Adds parallel to tests. Pre-fixes people's nits * Adds new GRPC functions to find out what data is missing from trades and candles. Fixes some assumptions from missing period code. * Adds unique constraint. Fixes up niggling issues for wrappers and websockets * Fixes issues with using unix times in the database trying to retrieve data via the CLI. Reduces save time to 15 seconds * Updates trades to use timestamps instead of int64 unix * Adds missing FTX wrapper implementation. Regens docs * Linting the linters. Updating readme * Adds new command to set whether an exchange can process trades * Doc update * Adds recent trades and historic trade endpoints to grpc * formats pair_test.go to appease linter gods * Addresses data race. Removes logging of missing intervals on unrelated function (now that it has its own rpc command). The buffer time isnt customisable, but I don't feel it needs to be at a config level at all really. * Fixes a few niterinos regarding spacing, type conversion, a weird Bitmex 0 trade value error, unsubscriptions and cli command references * Reduces map lookups. Adds base func and moves wrappers to use it * Uses better currency formatter. Adds time based validation to trade history. Reverts configtest.json * Reverts config and updates test names. Also WAYYYYY LESS SPAMMY * oopsie doopsie missed a whoopsie * mint flavoured lint * Fixes issues caused by rebase * Fixes issue with timestamps not converting properly from command to RPCServer. Adds new error type. Adds shorthand entries to some commands. Removes os.Exit from tests. Makes Gemini test rolling. Adds enabled exchange check to RPC function. Escapes timestamp on bitstamp. Renames var * fixes whoopsie oopsie doopsie I forgot to remove code shoopsie * missed a line * 🎉 🎉 :tada:Breaks everything in an end of day commit 🎉 🎉 🎉 * Modifies function 'createlocaloffset' to return a string instead. Uses strings for all time based start and end commands. Uses UTC times in RPC server and updates SQLITE to use formatted time based queries * Adds concurrency-safe way of changing SaveTradeData and checking it. Fixes embarrassing typo * End of day fix, adds bitfinex update to loop until either the return trades shows no new dates, or meets specifications. Fixes egregious typo * Improves testing and handling of historical trades function * Fixes tests after latest changes * Fix potential fatal err now that db is enabled in test config now * Fixes up some database settings to use a local engine instead of global var * DELICIOUS LINT CHOCOLATE FIXES * Fixes data race by slashing competitor's tyres * Adds mock test fixes to allow for live and stored data test * Removes verbosity in engine level tests. Adds new timezone format to highlight the timezone for RPC functions. Removes reference to Preix index fund * Oopsie doopsie, fixed a whoopsie * Loggers can no longer do data drag races on my lawn 👴 * Removes bad lock * Addresses command nits. End of day conceptual commit, trying to calculate spans of time in the context of missing periods. Tests will fail * Adds new stream response for retrieving trade history as it can take time to do. Unsuccessfully attempts to simplify time range calculation for missing trades response * Adds new timeperiods package to calculate time periods, time ranges and whether data is in those ranges. Removes kline basic implementation of same concept * Fixes lint issues. Fixes test. Moves trade cli commands to their own trade subcommands * Updates lakebtc to no longer have gethistorictrades as it is unsupported. Adds more validation to rpc functions * Removes requirement to have trades when testing trade wrapper functions. Doesn't really prove it works if there are no trades for a given currency in a time period. * Addresses nits, runs linting fix and ensures a test is consistent * Fix merge issues * Moves sort to timeperiods. Adds test coverage. Fixes typo * Removes log package in CLI * Fixes `GetTrades` url * Reorders all instances of validation occuring after settingup RPC connection * Fixes test to ensure that it is setup before testing that it is setup * Fixed issue with bool retrieval. Removes double append * Fixes Binance times, fixes bitfinex sell sides, fixes huobi times, sorts all responses * Fixes poloniex trade id consistency. Makes recent trade for poloniex consistent with others (15 minutes). Fixes coinbene. Fixes localbitcoins to use quote currency. Fixes coinut times. Updates huobi trade id, saves okgroup trades. Fixes bid and ask to buy and sell * Removes websocket trades for lakebtc as it did not meet our requirements for processing. Adds new constraints to the database to ensure we have uniqueness on trades where ID doesn't exist and doesn't trigger errors for trades where the tid does * Fixes migration for postgres to downscale properly * Really really fixes the psql index changes * Fixes broken tests * Now with working tests and no pocket lint * Makes the side column nullable with no more constraint for it. adds migrations and runs generation. comments lakebtc * Lint & Sprüngli * Updates zb to use more appropriate side * Fixes oopsie * Attempts to address a data race from globals * Fixes build * Fixes missed regen rpc files * Updates readme to point to trade readme. Fixes exchange_wrapper_coverage wrapper count and untested panics, tests bitfinex funding pair test for `fUSD`, adds shiny new param `tradeprocessinginterval` * mint flavoured lint * Uses the real default to set the default value by default * Fixes some extra tests surrounding email sending and number incompatibility * Reverts test config * re-adds gom2/usdt currency * Fixes typo, don't look! * Fixes minor codelingo pickups * Adds more precision to handling of trade data from Kraken. Expands test * interface christmas tree * lint
209 lines
7.2 KiB
Go
209 lines
7.2 KiB
Go
package exchange
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/config"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
|
|
)
|
|
|
|
// Endpoint authentication types
|
|
const (
|
|
RestAuthentication uint8 = 0
|
|
WebsocketAuthentication uint8 = 1
|
|
// Repeated exchange strings
|
|
// FeeType custom type for calculating fees based on method
|
|
WireTransfer InternationalBankTransactionType = iota
|
|
PerfectMoney
|
|
Neteller
|
|
AdvCash
|
|
Payeer
|
|
Skrill
|
|
Simplex
|
|
SEPA
|
|
Swift
|
|
RapidTransfer
|
|
MisterTangoSEPA
|
|
Qiwi
|
|
VisaMastercard
|
|
WebMoney
|
|
Capitalist
|
|
WesternUnion
|
|
MoneyGram
|
|
Contact
|
|
// Const declarations for fee types
|
|
BankFee FeeType = iota
|
|
InternationalBankDepositFee
|
|
InternationalBankWithdrawalFee
|
|
CryptocurrencyTradeFee
|
|
CyptocurrencyDepositFee
|
|
CryptocurrencyWithdrawalFee
|
|
OfflineTradeFee
|
|
// Definitions for each type of withdrawal method for a given exchange
|
|
NoAPIWithdrawalMethods uint32 = 0
|
|
NoAPIWithdrawalMethodsText string = "NONE, WEBSITE ONLY"
|
|
AutoWithdrawCrypto uint32 = (1 << 0)
|
|
AutoWithdrawCryptoWithAPIPermission uint32 = (1 << 1)
|
|
AutoWithdrawCryptoWithSetup uint32 = (1 << 2)
|
|
AutoWithdrawCryptoText string = "AUTO WITHDRAW CRYPTO"
|
|
AutoWithdrawCryptoWithAPIPermissionText string = "AUTO WITHDRAW CRYPTO WITH API PERMISSION"
|
|
AutoWithdrawCryptoWithSetupText string = "AUTO WITHDRAW CRYPTO WITH SETUP"
|
|
WithdrawCryptoWith2FA uint32 = (1 << 3)
|
|
WithdrawCryptoWithSMS uint32 = (1 << 4)
|
|
WithdrawCryptoWithEmail uint32 = (1 << 5)
|
|
WithdrawCryptoWithWebsiteApproval uint32 = (1 << 6)
|
|
WithdrawCryptoWithAPIPermission uint32 = (1 << 7)
|
|
WithdrawCryptoWith2FAText string = "WITHDRAW CRYPTO WITH 2FA"
|
|
WithdrawCryptoWithSMSText string = "WITHDRAW CRYPTO WITH SMS"
|
|
WithdrawCryptoWithEmailText string = "WITHDRAW CRYPTO WITH EMAIL"
|
|
WithdrawCryptoWithWebsiteApprovalText string = "WITHDRAW CRYPTO WITH WEBSITE APPROVAL"
|
|
WithdrawCryptoWithAPIPermissionText string = "WITHDRAW CRYPTO WITH API PERMISSION"
|
|
AutoWithdrawFiat uint32 = (1 << 8)
|
|
AutoWithdrawFiatWithAPIPermission uint32 = (1 << 9)
|
|
AutoWithdrawFiatWithSetup uint32 = (1 << 10)
|
|
AutoWithdrawFiatText string = "AUTO WITHDRAW FIAT"
|
|
AutoWithdrawFiatWithAPIPermissionText string = "AUTO WITHDRAW FIAT WITH API PERMISSION"
|
|
AutoWithdrawFiatWithSetupText string = "AUTO WITHDRAW FIAT WITH SETUP"
|
|
WithdrawFiatWith2FA uint32 = (1 << 11)
|
|
WithdrawFiatWithSMS uint32 = (1 << 12)
|
|
WithdrawFiatWithEmail uint32 = (1 << 13)
|
|
WithdrawFiatWithWebsiteApproval uint32 = (1 << 14)
|
|
WithdrawFiatWithAPIPermission uint32 = (1 << 15)
|
|
WithdrawFiatWith2FAText string = "WITHDRAW FIAT WITH 2FA"
|
|
WithdrawFiatWithSMSText string = "WITHDRAW FIAT WITH SMS"
|
|
WithdrawFiatWithEmailText string = "WITHDRAW FIAT WITH EMAIL"
|
|
WithdrawFiatWithWebsiteApprovalText string = "WITHDRAW FIAT WITH WEBSITE APPROVAL"
|
|
WithdrawFiatWithAPIPermissionText string = "WITHDRAW FIAT WITH API PERMISSION"
|
|
WithdrawCryptoViaWebsiteOnly uint32 = (1 << 16)
|
|
WithdrawFiatViaWebsiteOnly uint32 = (1 << 17)
|
|
WithdrawCryptoViaWebsiteOnlyText string = "WITHDRAW CRYPTO VIA WEBSITE ONLY"
|
|
WithdrawFiatViaWebsiteOnlyText string = "WITHDRAW FIAT VIA WEBSITE ONLY"
|
|
NoFiatWithdrawals uint32 = (1 << 18)
|
|
NoFiatWithdrawalsText string = "NO FIAT WITHDRAWAL"
|
|
UnknownWithdrawalTypeText string = "UNKNOWN"
|
|
)
|
|
|
|
// FeeType is the type for holding a custom fee type (International withdrawal fee)
|
|
type FeeType uint8
|
|
|
|
// InternationalBankTransactionType custom type for calculating fees based on fiat transaction types
|
|
type InternationalBankTransactionType uint8
|
|
|
|
// FeeBuilder is the type which holds all parameters required to calculate a fee
|
|
// for an exchange
|
|
type FeeBuilder struct {
|
|
FeeType FeeType
|
|
// Used for calculating crypto trading fees, deposits & withdrawals
|
|
Pair currency.Pair
|
|
IsMaker bool
|
|
// Fiat currency used for bank deposits & withdrawals
|
|
FiatCurrency currency.Code
|
|
BankTransactionType InternationalBankTransactionType
|
|
// Used to multiply for fee calculations
|
|
PurchasePrice float64
|
|
Amount float64
|
|
}
|
|
|
|
// FundHistory holds exchange funding history data
|
|
type FundHistory struct {
|
|
ExchangeName string
|
|
Status string
|
|
TransferID string
|
|
Description string
|
|
Timestamp time.Time
|
|
Currency string
|
|
Amount float64
|
|
Fee float64
|
|
TransferType string
|
|
CryptoToAddress string
|
|
CryptoFromAddress string
|
|
CryptoTxID string
|
|
BankTo string
|
|
BankFrom string
|
|
}
|
|
|
|
// Features stores the supported and enabled features
|
|
// for the exchange
|
|
type Features struct {
|
|
Supports FeaturesSupported
|
|
Enabled FeaturesEnabled
|
|
}
|
|
|
|
// FeaturesEnabled stores the exchange enabled features
|
|
type FeaturesEnabled struct {
|
|
AutoPairUpdates bool
|
|
Kline kline.ExchangeCapabilitiesEnabled
|
|
SaveTradeData bool
|
|
}
|
|
|
|
// FeaturesSupported stores the exchanges supported features
|
|
type FeaturesSupported struct {
|
|
REST bool
|
|
RESTCapabilities protocol.Features
|
|
Websocket bool
|
|
WebsocketCapabilities protocol.Features
|
|
WithdrawPermissions uint32
|
|
Kline kline.ExchangeCapabilitiesSupported
|
|
}
|
|
|
|
// API stores the exchange API settings
|
|
type API struct {
|
|
AuthenticatedSupport bool
|
|
AuthenticatedWebsocketSupport bool
|
|
PEMKeySupport bool
|
|
|
|
Endpoints struct {
|
|
URL string
|
|
URLDefault string
|
|
URLSecondary string
|
|
URLSecondaryDefault string
|
|
WebsocketURL string
|
|
}
|
|
|
|
Credentials struct {
|
|
Key string
|
|
Secret string
|
|
ClientID string
|
|
PEMKey string
|
|
}
|
|
|
|
CredentialsValidator struct {
|
|
// For Huobi (optional)
|
|
RequiresPEM bool
|
|
|
|
RequiresKey bool
|
|
RequiresSecret bool
|
|
RequiresClientID bool
|
|
RequiresBase64DecodeSecret bool
|
|
}
|
|
}
|
|
|
|
// Base stores the individual exchange information
|
|
type Base struct {
|
|
Name string
|
|
Enabled bool
|
|
Verbose bool
|
|
LoadedByConfig bool
|
|
SkipAuthCheck bool
|
|
API API
|
|
BaseCurrencies currency.Currencies
|
|
CurrencyPairs currency.PairsManager
|
|
Features Features
|
|
HTTPTimeout time.Duration
|
|
HTTPUserAgent string
|
|
HTTPRecording bool
|
|
HTTPDebugging bool
|
|
WebsocketResponseCheckTimeout time.Duration
|
|
WebsocketResponseMaxLimit time.Duration
|
|
WebsocketOrderbookBufferLimit int64
|
|
Websocket *stream.Websocket
|
|
*request.Requester
|
|
Config *config.ExchangeConfig
|
|
settingsMutex sync.RWMutex
|
|
}
|