okane

package module
v0.0.0-...-922b6b1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXCHANGE_BITTREX  int = 1
	EXCHANGE_BINANCE  int = 2
	EXCHANGE_SIM      int = 3
	EXCHANGE_COINBASE int = 4
	EXCHANGE_KRAKEN   int = 5
)

Variables

View Source
var CoinLookup shared.LookupTable
View Source
var ExchangeBinance = Exchange{
	Id:   EXCHANGE_BINANCE,
	Name: "binance",
}
View Source
var ExchangeBittrex = Exchange{
	Id:   EXCHANGE_BITTREX,
	Name: "bittrex",
}
View Source
var ExchangeCoinbase = Exchange{
	Id:   EXCHANGE_COINBASE,
	Name: "coinbase",
}
View Source
var ExchangeKraken = Exchange{
	Id:   EXCHANGE_KRAKEN,
	Name: "kraken",
}
View Source
var ExchangeSimulator = Exchange{
	Id:   EXCHANGE_SIM,
	Name: "simulator",
}
View Source
var Exchanges struct {
	ById   map[int]*Exchange
	ByName map[string]*Exchange
}
View Source
var MarketLookup shared.LookupTable
View Source
var OrderTranslationMapBittrex = map[string]map[string]string{
	"LIMIT":  map[string]string{"SELL": "LIMIT_SELL", "BUY": "LIMIT_BUY"},
	"MARKET": map[string]string{"SELL": "MARKET_SELL", "BUY": "MARKET_BUY"},
}
View Source
var OrderTranslationMapCbpro = map[string]map[string]string{
	"":      map[string]string{"sell": "LIMIT_SELL", "buy": "LIMIT_BUY"},
	"limit": map[string]string{"sell": "LIMIT_SELL", "buy": "LIMIT_BUY"},
}
View Source
var OrderTranslationMapKraken = map[string]map[string]string{}

Functions

func DbInit

func DbInit(dbh *shared.DbHandle) error

func PrintAll

func PrintAll(channel string, data []byte) error

func SetCentralDb

func SetCentralDb(Db *shared.DbHandle)

func SetLogger

func SetLogger(l *slogger.Logger) *slogger.Logger

Types

type Account

type Account struct {
	User     *User
	Exchange *Exchange
	CredId   int
	Cache    struct {
		Pending    map[string]*ActionRequest
		PendingIds map[int]*ActionRequest
		ResultSub  map[int]chan *ActionRequest

		Open map[string]*Order

		Closed map[string]*Order
		// contains filtered or unexported fields
	}
	CacheCycle int
	X          map[string]interface{} `json:"-"`
}

Account is a downstream concept tied strictly to API keys

func (*Account) AwaitRequestResult

func (a *Account) AwaitRequestResult(Id int) chan *ActionRequest

func (*Account) AwaitUuidNotOpen

func (a *Account) AwaitUuidNotOpen(Uuid string) chan *Order

func (*Account) BalanceSnapshotInsert

func (a *Account) BalanceSnapshotInsert(Tx *sql.Tx, CoinId int, Balance decimal.Decimal, Available decimal.Decimal, Hold decimal.Decimal) (err error)

func (*Account) GetClosedOrder

func (a *Account) GetClosedOrder(uuid string) (*Order, error)

func (*Account) GetOpenOrderRequests

func (a *Account) GetOpenOrderRequests() (List []*ActionRequest, errors error)

func (*Account) GetOpenOrders

func (a *Account) GetOpenOrders() (List *OrderList, err error)

func (*Account) GetRequest

func (a *Account) GetRequest(Id int) (*ActionRequest, error)

func (*Account) Identifier

func (a *Account) Identifier() string

func (*Account) NewBalanceSnapshot

func (a *Account) NewBalanceSnapshot() *BalanceSnapshot

func (*Account) OrderUpdatePartialFill

func (a *Account) OrderUpdatePartialFill(o *Order) error

func (*Account) Publish

func (a *Account) Publish(reason EventReason, object interface{}) error

func (*Account) RecordStratOrder

func (a *Account) RecordStratOrder(r *ActionRequest) error

func (*Account) RunOrderCache

func (a *Account) RunOrderCache(duration time.Duration, Cycle *int)

func (*Account) SendOrderUpdate

func (a *Account) SendOrderUpdate(o *Order) *EvOrderUpdate

func (*Account) SendRequest

func (a *Account) SendRequest(o *ActionRequest) error

func (*Account) SetRequest

func (a *Account) SetRequest(o *ActionRequest, From string, To string) (bool, error)

func (*Account) WipeBalanceSnapshot

func (a *Account) WipeBalanceSnapshot(Tx *sql.Tx) (err error)

type ActionRequest

type ActionRequest struct {
	Account   *Account
	Id        int
	Command   string
	Status    string
	Uuid      string
	Market    *MarketDef
	Qty       float64
	Bidlimit  float64
	Stratid   int
	Label     string
	Requested time.Time
	Subscribe ActionRequestSub
	Error     error
}

func (*ActionRequest) Identifier

func (o *ActionRequest) Identifier() string

func (*ActionRequest) MarkAsHandled

func (o *ActionRequest) MarkAsHandled(status string) error

type ActionRequestSub

type ActionRequestSub struct {
	Id     chan int
	Result chan *ActionRequest
}

type BalState

type BalState struct {
	CoinId    int
	Balance   decimal.Decimal
	Available decimal.Decimal
	Hold      decimal.Decimal
}

type BalanceSnapshot

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

func (*BalanceSnapshot) Add

func (bs *BalanceSnapshot) Add(Coinid int, Balance decimal.Decimal, Available decimal.Decimal, Hold decimal.Decimal) *BalanceSnapshot

func (*BalanceSnapshot) UpdateDb

func (bs *BalanceSnapshot) UpdateDb() error

type Coin

type Coin interface {
	shared.LookupItem
}

type CoinBalance

type CoinBalance struct {
	Coin      Coin `json:"-"`
	Balance   decimal.Decimal
	Available decimal.Decimal
	Hold      decimal.Decimal
}

type EvMarketUpdate

type EvMarketUpdate struct {
	Event
	Market *MarketDef
}

type EvOrderOpen

type EvOrderOpen struct {
	Event
	Market MarketDef
}

type EvOrderUpdate

type EvOrderUpdate struct {
	Event
	Market *MarketDef
	Uuid   string
	Max    decimal.Decimal
	Filled decimal.Decimal
	Active bool
}

type Event

type Event interface{}

type EventChannel

type EventChannel struct {
	FpReceiver func(channel string, data []byte) error
	FpOnStart  func() error
	// contains filtered or unexported fields
}

func NewEventChannel

func NewEventChannel() *EventChannel

func (*EventChannel) Connect

func (ec *EventChannel) Connect() error

func (*EventChannel) Publish

func (ec *EventChannel) Publish(channel string, data ...interface{}) error

func (*EventChannel) PublishObj

func (ec *EventChannel) PublishObj(channel string, object interface{}) error

func (*EventChannel) StartListener

func (ec *EventChannel) StartListener(channels ...string) error

func (*EventChannel) SubscribeChannels

func (ec *EventChannel) SubscribeChannels(channels ...string) error

func (*EventChannel) WriteJson

func (ec *EventChannel) WriteJson(Rec *sjson.JSON) error

type EventReason

type EventReason string
const (
	EV_ORDER_OPEN   EventReason = "orderopen"
	EV_ORDER_UPDATE EventReason = "orderupdate"
	EV_ORDER_CLOSED EventReason = "orderclosed"
	EV_NEWRATES     EventReason = "newrates"
)

type Exchange

type Exchange struct {
	Id              int
	Name            string
	Markets         MarketDefsType `json:"-"`
	LastMarketFetch time.Time

	LastRateFetch time.Time
	LoadCount     int
	// contains filtered or unexported fields
}

func (*Exchange) BuyFee

func (exchange *Exchange) BuyFee() decimal.Decimal

func (*Exchange) GetMarketRatesDb

func (exchange *Exchange) GetMarketRatesDb()

func (*Exchange) GetMarketsDb

func (exchange *Exchange) GetMarketsDb(MaxAge time.Duration) MarketDefsType

func (*Exchange) Identifier

func (exchange *Exchange) Identifier() string

func (*Exchange) SellFee

func (exchange *Exchange) SellFee() decimal.Decimal

We presently simplify EVERYTHING to 0.25% fee everywhere.

type FiatMap

type FiatMap struct {
	BtcMarket  *MarketQuote
	EthMarket  *MarketQuote
	EuroMarket *MarketQuote
	GbpMarket  *MarketQuote
}

type IntervalSet

type IntervalSet map[string]*MarketRange

type MarketDef

type MarketDef struct {
	shared.LookupItem `json:"MarketId"`
	Exchange          *Exchange
	BaseCoin          Coin
	QuoteCoin         Coin
	Status            string
	Created           time.Time
	UsProhibited      bool
	Notice            string
	Precision         decimal.Decimal
	LastRate          *MarketQuote `json:"-"`
}

func (*MarketDef) Equals

func (md *MarketDef) Equals(B *MarketDef) bool

func (*MarketDef) GetLastRateDb

func (md *MarketDef) GetLastRateDb() *MarketQuote

func (*MarketDef) Identifier

func (md *MarketDef) Identifier() string

func (*MarketDef) Last

func (md *MarketDef) Last() decimal.Decimal

func (*MarketDef) LastUsd

func (md *MarketDef) LastUsd() decimal.Decimal

func (*MarketDef) SetSymbol

func (md *MarketDef) SetSymbol(s string)

type MarketDefsType

type MarketDefsType map[string]*MarketDef

func NewMarketDef

func NewMarketDef() MarketDefsType

func (MarketDefsType) ById

func (md MarketDefsType) ById(id int) (bool, *MarketDef)

func (MarketDefsType) ByName

func (md MarketDefsType) ByName(item string) (bool, *MarketDef)

func (MarketDefsType) ByNameOrDie

func (md MarketDefsType) ByNameOrDie(item string) *MarketDef

func (MarketDefsType) Equals

func (md MarketDefsType) Equals(Old *MarketDefsType) bool

func (*MarketDefsType) List

func (mdt *MarketDefsType) List() []string

func (*MarketDefsType) UpdateOmarketsTable

func (md *MarketDefsType) UpdateOmarketsTable(exchangeid int) error

type MarketQuote

type MarketQuote struct {
	MarketDef  *MarketDef
	Last       decimal.Decimal
	Bid        decimal.Decimal
	Ask        decimal.Decimal
	UsdRate    decimal.Decimal
	Volume     decimal.NullDecimal
	LastUpdate time.Time
}

type MarketRange

type MarketRange struct {
	MarketDef  *MarketDef
	MinRate    decimal.Decimal
	MinRateUsd decimal.Decimal
	MaxRate    decimal.Decimal
	MaxRateUsd decimal.Decimal
}

type MarketRatesType

type MarketRatesType map[string]*MarketQuote

func (*MarketRatesType) PublishRates

func (md *MarketRatesType) PublishRates(acct *Account) error

func (MarketRatesType) SetFiat

func (md MarketRatesType) SetFiat(fm *FiatMap)

func (*MarketRatesType) WriteMarketLast

func (md *MarketRatesType) WriteMarketLast(dbh *shared.DbHandle, Exchange *Exchange)

type Order

type Order struct {
	Account    *Account
	Uuid       string
	Label      string
	Type       string
	Market     *MarketDef `json:"-"`
	Base       Coin       `json:"-"`
	BaseCoin   string
	Quote      Coin `json:"-"`
	QuoteCoin  string
	Bidlimit   decimal.Decimal
	Quantity   decimal.Decimal
	Filled     decimal.Decimal
	Fee        decimal.Decimal
	UsdTotal   decimal.NullDecimal
	TotalPrice decimal.Decimal
	Created    time.Time
	Closed     time.Time
}

func NewOrder

func NewOrder(account *Account) *Order

func (*Order) ExchangeName

func (o *Order) ExchangeName() string

func (*Order) FormatOrderClosedChat

func (o *Order) FormatOrderClosedChat() string

func (*Order) FormatOrderOpenChat

func (o *Order) FormatOrderOpenChat() string

func (*Order) FormatOrderVanished

func (o *Order) FormatOrderVanished() string

func (*Order) Identifier

func (o *Order) Identifier() string

func (*Order) IsArchived

func (o *Order) IsArchived() bool

func (*Order) RecordClosedOrder

func (o *Order) RecordClosedOrder() error

func (*Order) RecordOpenOrder

func (o *Order) RecordOpenOrder() error

type OrderList

type OrderList struct {
	Orders         []*Order
	ByUuid         map[string]*Order
	ByDbid         map[int]*Order
	ActionSequence string
}

func (*OrderList) GetPL

func (list *OrderList) GetPL()

type Stairway

type Stairway struct {
	Delta   decimal.Decimal
	Ratio   decimal.Decimal
	Minimum decimal.Decimal
	// contains filtered or unexported fields
}

func NewStairway

func NewStairway(Ratio decimal.Decimal, Minimum decimal.Decimal) *Stairway

func NewStairwayF

func NewStairwayF(Delta float64, Minimum float64) *Stairway

func (*Stairway) AllSteps

func (Sta *Stairway) AllSteps() []decimal.Decimal

func (*Stairway) AllStepsF

func (Sta *Stairway) AllStepsF() []float64

func (*Stairway) FindStepByVal

func (Sta *Stairway) FindStepByVal(V decimal.Decimal) int

func (*Stairway) FindStepByValF64

func (Sta *Stairway) FindStepByValF64(V float64) int

func (*Stairway) StepV

func (Sta *Stairway) StepV(c int) decimal.Decimal

func (*Stairway) StepVf

func (Sta *Stairway) StepVf(c int) float64

func (*Stairway) String

func (Sta *Stairway) String() string

type StratLastUpdate

type StratLastUpdate map[int]time.Time

type StratList

type StratList []*Strategy

func (StratList) ToMap

func (List StratList) ToMap() map[int]*Strategy

type Strategy

type Strategy struct {
	Id          int
	Exchange    *Exchange
	Name        string
	User        *User
	Market      *MarketDef
	Active      bool
	Suspended   bool
	Data        sjson.JSON
	SkipBecause error
}

func (*Strategy) GetOrderList

func (strat *Strategy) GetOrderList() (*OrderList, error)

func (*Strategy) Identifier

func (Strat *Strategy) Identifier() string

type User

type User struct {
	Username string
	Notices  *shared.ChatTarget `json:"-"`
	Accounts []*Account         `json:"-"`
	Db       *shared.DbHandle   `json:"-"`

	ClosedOrders map[string]bool `json:"-"`
	Events       *EventChannel   `json:"-"`
	// contains filtered or unexported fields
}

User represents an individual; a user may have many accounts, but one db only. Strategies may cross accounts if they're playing cross-exchange shenanigans like arb.

func NewUser

func NewUser(db *shared.DbHandle) *User

func (*User) DbInit

func (u *User) DbInit(Db *shared.DbHandle)

func (*User) GetStrats

func (u *User) GetStrats() (StratList, error)

func (*User) Identifier

func (u *User) Identifier() string

func (*User) LastStratCloses

func (u *User) LastStratCloses() map[int]time.Time

func (*User) LoadAccountsForExchange

func (u *User) LoadAccountsForExchange(exchange *Exchange) []*Account

func (*User) LoadAllAccounts

func (u *User) LoadAllAccounts() []*Account

func (*User) RemoveOpenOrder

func (u *User) RemoveOpenOrder(Uuid string) error

func (*User) UuidCloseRecorded

func (u *User) UuidCloseRecorded(Uuid string) bool

type UserPreparedQueries_ro

type UserPreparedQueries_ro struct {
	CredSelectByExchangeId *shared.Stmt
	OrderArchivePresent    *shared.Stmt
	CheckLogpoints         *shared.Stmt
	CheckTableMaxId        *shared.Stmt
	CredSelectAll          *shared.Stmt
	GetUserStrats          *shared.Stmt
	GetLastStratCloses     *shared.Stmt
	GetOpenRequests        *shared.Stmt
	GetRequest             *shared.Stmt
	GetOpenOrders          *shared.Stmt
	GetStratOrders         *shared.Stmt
	GetClosedOrder         *shared.Stmt
}

type UserPreparedQueries_rw

type UserPreparedQueries_rw struct {
	BalanceWipeForAccount *shared.Stmt
	BalanceInsert         *shared.Stmt
	OrderOpenDelete       *shared.Stmt
	OrderOpenInsert       *shared.Stmt
	OrderOpenUpdateFill   *shared.Stmt
	OrderArchiveInsert    *shared.Stmt
	StratOrderUpdate      *shared.Stmt
	UpdateLogpoint        *shared.Stmt
	SetRequestStatusFrom  *shared.Stmt
	SetRequestMarkHandled *shared.Stmt
	SetRequestProcessed   *shared.Stmt
	RequestInsert         *shared.Stmt
	InsertStratOrder      *shared.Stmt
}

Jump to

Keyboard shortcuts

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