exsim

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PositionSizeLimit = 1000000 // Position size limit
)

Variables

This section is empty.

Functions

func CalcInitialMargin

func CalcInitialMargin(sizeCurrency float64) float64

少于此保证金,则爆仓

func CalcMaintMargin

func CalcMaintMargin(sizeCurrency float64) float64

少于此保证金,则强制挂平仓单

func CalcPnl

func CalcPnl(side Direction, positionSize float64, entryPrice float64, exitPrice float64, forwardContract bool) (pnl float64, pnlUsd float64)

计算收益 pnl: 收益(BTC/ETH) pnlUsd: 收益(USD)

Types

type ExSim

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

ExSim the exchange for backtest

func NewExSim

func NewExSim(data *dataloader.Data, cash float64, makerFeeRate float64, takerFeeRate float64, valueOfContract float64, hedgedPosition bool, forwardContract bool) *ExSim

NewExSim 创建模拟交易所 cash: 初始资金 makerFeeRate: Maker 费率 takerFeeRate: Taker 费率 valueOfContract: 合约单张面值 hedgedPosition: 双向持仓 forwardContract: true-正向合约 false-反向合约

func (*ExSim) AmendOrder

func (b *ExSim) AmendOrder(symbol string, id string, price float64, size float64, opts ...OrderOption) (result *Order, err error)

func (*ExSim) CancelAllOrders

func (b *ExSim) CancelAllOrders(symbol string, opts ...OrderOption) (err error)

func (*ExSim) CancelOrder

func (b *ExSim) CancelOrder(symbol string, id string, opts ...OrderOption) (result *Order, err error)

func (*ExSim) CloseLong

func (b *ExSim) CloseLong(symbol string, orderType OrderType, price float64, size float64) (result *Order, err error)

func (*ExSim) CloseShort

func (b *ExSim) CloseShort(symbol string, orderType OrderType, price float64, size float64) (result *Order, err error)

func (*ExSim) GetBalance

func (b *ExSim) GetBalance(symbol string) (result *Balance, err error)

func (*ExSim) GetContractID

func (b *ExSim) GetContractID() (symbol string, err error)

func (*ExSim) GetName

func (b *ExSim) GetName() (name string)

func (*ExSim) GetOpenOrders

func (b *ExSim) GetOpenOrders(symbol string, opts ...OrderOption) (result []*Order, err error)

func (*ExSim) GetOrder

func (b *ExSim) GetOrder(symbol string, id string, opts ...OrderOption) (result *Order, err error)

func (*ExSim) GetOrderBook

func (b *ExSim) GetOrderBook(symbol string, depth int) (result *OrderBook, err error)

func (*ExSim) GetPValue added in v1.2.6

func (b *ExSim) GetPValue(symbol string) float64

返回面值

func (*ExSim) GetPositions

func (b *ExSim) GetPositions(symbol string) (result []*Position, err error)

func (*ExSim) GetRecords

func (b *ExSim) GetRecords(symbol string, period string, from int64, end int64, limit int) (records []*Record, err error)

func (*ExSim) GetTime

func (b *ExSim) GetTime() (tm int64, err error)

func (*ExSim) IO added in v1.2.12

func (b *ExSim) IO(name string, params string) (string, error)

func (*ExSim) OpenLong

func (b *ExSim) OpenLong(symbol string, orderType OrderType, price float64, size float64) (result *Order, err error)

func (*ExSim) OpenShort

func (b *ExSim) OpenShort(symbol string, orderType OrderType, price float64, size float64) (result *Order, err error)

func (*ExSim) PlaceOrder

func (b *ExSim) PlaceOrder(symbol string, direction Direction, orderType OrderType, price float64,
	size float64, opts ...PlaceOrderOption) (result *Order, err error)

func (*ExSim) RunEventLoopOnce

func (b *ExSim) RunEventLoopOnce() (err error)

func (*ExSim) SetBacktest added in v1.2.3

func (b *ExSim) SetBacktest(backtest IBacktest)

func (*ExSim) SetContractType

func (b *ExSim) SetContractType(pair string, contractType string) (err error)

func (*ExSim) SetExchangeLogger

func (b *ExSim) SetExchangeLogger(l ExchangeLogger)

func (*ExSim) SetLeverRate

func (b *ExSim) SetLeverRate(value float64) (err error)

func (*ExSim) SubscribeLevel2Snapshots

func (b *ExSim) SubscribeLevel2Snapshots(market Market, callback func(ob *OrderBook)) error

func (*ExSim) SubscribeOrders

func (b *ExSim) SubscribeOrders(market Market, callback func(orders []*Order)) error

func (*ExSim) SubscribePositions

func (b *ExSim) SubscribePositions(market Market, callback func(positions []*Position)) error

func (*ExSim) SubscribeTrades

func (b *ExSim) SubscribeTrades(market Market, callback func(trades []*Trade)) error

type MarginInfo

type MarginInfo struct {
	Leverage              float64
	MaintMargin           float64
	LiquidationPriceLong  float64
	LiquidationPriceShort float64
}

func CalcMarginInfo

func CalcMarginInfo(balance float64, entryPrice float64, positionSize float64) (result MarginInfo)

计算保证金参数

type Positions

type Positions []*Position // 单向持仓只有一项; 双向持仓 Index: 0-Long Index: 1-Short

持仓,用于多仓

Jump to

Keyboard shortcuts

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