mockexchange

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

README

MockExchange

介绍

高频策略用现有回测框架都没有意义,所以想实现一个用实时行情数据模拟交易来初步评估策略效果. 单买单价格大于等于卖一时成交,卖单价格小于等于买一时成交。使用很简单,可以看下源码

使用说明
// MarkerFeeRate 限价单费率 TakerFeeRate 市价单费率 Record 是否开启用日志记录交易记录
e := m.MockExchange{
	Symbol:        "BTC/USD",
	Record:        true,
	MarkerFeeRate: 0.0002,
	TakerFeeRate:  0.0004,
}
e.Init() // 初始化,会加载已经存在的信息
e.QuoteUpdate(100.0, 99.8) // 更新行情,分别是卖一、买一

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockExchange

type MockExchange struct {
	Symbol        string              //交易对
	OrderDic      map[string]ex.Order //订单薄
	Record        bool                //是否用日志记录交易记录
	Hold          float64             // 持仓
	CostPrice     float64             //持仓成本
	Profit        float64             //盈利
	TradeAmount   float64             //累计交易额
	TotalFee      float64             //累计手续费
	MarkerFeeRate float64             //挂单费率
	TakerFeeRate  float64             //吃单费率
	AskPrice      float64             //卖一价格
	BidPrice      float64             //买一价格
}

MockExchange 模拟交易所对象.

func (*MockExchange) AmendOrder

func (m *MockExchange) AmendOrder(id string, price, amount float64) (ex.Order, error)

AmendOrder 修改订单.

func (*MockExchange) CancelOrder

func (m *MockExchange) CancelOrder(id string) error

CancelOrder 取消订单id.

func (*MockExchange) Init

func (m *MockExchange) Init() error

Init 初始化.

func (*MockExchange) LimitBuy

func (m *MockExchange) LimitBuy(price, amount float64) ex.Order

LimitBuy 限价单买.

func (*MockExchange) LimitSell

func (m *MockExchange) LimitSell(price, amount float64) ex.Order

LimitSell 限价单卖.

func (*MockExchange) MarketBuy

func (m *MockExchange) MarketBuy(amount float64) ex.Order

MarketBuy 市价买.

func (*MockExchange) MarketSell

func (m *MockExchange) MarketSell(amount float64) ex.Order

MarketSell 市价卖.

func (*MockExchange) OpenOrders

func (m *MockExchange) OpenOrders() []ex.Order

OpenOrders 未成交的订单.

func (*MockExchange) QuoteUpdate

func (m *MockExchange) QuoteUpdate(askPrice, bidPrice float64) error

QuoteUpdate 行情更新.

Jump to

Keyboard shortcuts

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