github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/common/common.go (about) 1 package common 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 const ( 9 OrderFlagHidden int = 64 10 OrderFlagClose int = 512 11 OrderFlagPostOnly int = 4096 12 OrderFlagOCO int = 16384 13 Checksum int = 131072 14 OrderStatusActive = "ACTIVE" 15 OrderStatusExecuted = "EXECUTED" 16 OrderStatusPartiallyFilled = "PARTIALLY FILLED" 17 OrderStatusCanceled = "CANCELED" 18 OrderTypeExchangeLimit = "EXCHANGE LIMIT" 19 OrderTypeMarket = "MARKET" 20 OrderTypeExchangeMarket = "EXCHANGE MARKET" 21 OrderTypeLimit = "LIMIT" 22 OrderTypeStop = "STOP" 23 OrderTypeExchangeStop = "EXCHANGE STOP" 24 OrderTypeTrailingStop = "TRAILING STOP" 25 OrderTypeExchangeTrailingStop = "EXCHANGE TRAILING STOP" 26 OrderTypeFOK = "FOK" 27 OrderTypeExchangeFOK = "EXCHANGE FOK" 28 OrderTypeStopLimit = "STOP LIMIT" 29 OrderTypeExchangeStopLimit = "EXCHANGE STOP LIMIT" 30 PermissionRead = "r" 31 PermissionWrite = "w" 32 FundingPrefix = "f" 33 TradingPrefix = "t" 34 FundingSizeKey StatKey = "funding.size" 35 CreditSizeKey StatKey = "credits.size" 36 CreditSizeSymKey StatKey = "credits.size.sym" 37 PositionSizeKey StatKey = "pos.size" 38 Bid OrderSide = 1 39 Ask OrderSide = 2 40 Long OrderSide = 1 41 Short OrderSide = 2 42 OldestFirst SortOrder = 1 43 NewestFirst SortOrder = -1 44 OneMinute CandleResolution = "1m" 45 FiveMinutes CandleResolution = "5m" 46 FifteenMinutes CandleResolution = "15m" 47 ThirtyMinutes CandleResolution = "30m" 48 OneHour CandleResolution = "1h" 49 ThreeHours CandleResolution = "3h" 50 SixHours CandleResolution = "6h" 51 TwelveHours CandleResolution = "12h" 52 OneDay CandleResolution = "1D" 53 OneWeek CandleResolution = "7D" 54 TwoWeeks CandleResolution = "14D" 55 OneMonth CandleResolution = "1M" 56 Precision0 BookPrecision = "P0" // Aggregate precision levels 57 Precision1 BookPrecision = "P1" // Aggregate precision levels 58 Precision2 BookPrecision = "P2" // Aggregate precision levels 59 Precision3 BookPrecision = "P3" // Aggregate precision levels 60 PrecisionRawBook BookPrecision = "R0" // Raw precision 61 // FrequencyRealtime book frequency gives updates as they occur in real-time. 62 FrequencyRealtime BookFrequency = "F0" 63 // FrequencyTwoPerSecond delivers two book updates per second. 64 FrequencyTwoPerSecond BookFrequency = "F1" 65 // PriceLevelDefault provides a constant default price level for book subscriptions. 66 PriceLevelDefault int = 25 67 ) 68 69 var ( 70 ErrNotFound = errors.New("not found") 71 ) 72 73 // OrderSide provides a typed set of order sides. 74 type OrderSide byte 75 76 // CandleResolution provides a typed set of resolutions for candle subscriptions. 77 type CandleResolution string 78 79 // BookPrecision provides a typed book precision level. 80 type BookPrecision string 81 82 // BookFrequency provides a typed book frequency. 83 type BookFrequency string 84 85 type SortOrder int 86 87 type QueryLimit int 88 89 type PermissionType string 90 91 type Mts int64 92 93 type StatKey string 94 95 type StatusType string 96 97 type OrderType string 98 99 func CandleResolutionFromString(str string) (CandleResolution, error) { 100 switch str { 101 case string(OneMinute): 102 return OneMinute, nil 103 case string(FiveMinutes): 104 return FiveMinutes, nil 105 case string(FifteenMinutes): 106 return FifteenMinutes, nil 107 case string(ThirtyMinutes): 108 return ThirtyMinutes, nil 109 case string(OneHour): 110 return OneHour, nil 111 case string(ThreeHours): 112 return ThreeHours, nil 113 case string(SixHours): 114 return SixHours, nil 115 case string(TwelveHours): 116 return TwelveHours, nil 117 case string(OneDay): 118 return OneDay, nil 119 case string(OneWeek): 120 return OneWeek, nil 121 case string(TwoWeeks): 122 return TwoWeeks, nil 123 case string(OneMonth): 124 return OneMonth, nil 125 } 126 return OneMinute, fmt.Errorf("could not convert string to resolution: %s", str) 127 }