Documentation
¶
Overview ¶
GPT Response: Sure, here's an example of a short-term trading strategy that uses Moving Averages to make buy and sell decisions:
{... CODE ...}
This strategy makes use of two moving averages with different time frames, 20 and 50 candles, to determine the trend of the market. If the short-term moving average crosses above the long-term moving average, it signals a buy opportunity. If the short-term moving average crosses below the long-term moving average, it signals a sell opportunity.
Index ¶
- Constants
- Variables
- type AccountResponse
- type AccountsResponse
- type AuthenticationTransport
- type BidAskPrice
- type Candle
- type Candles
- type CapitalClientAPI
- func (capClient *CapitalClientAPI) CreateNewSession() (newSessionResponse NewSessionResponse, headerTokens http.Header, err error)
- func (capClient *CapitalClientAPI) CreateWorkingOrder(epic string, direction Signal, orderType OrderType, targetPrice float64, ...) (createWorkingOrder WorkingOrderResponse, err error)
- func (capClient *CapitalClientAPI) DeleteWorkingOrder(dealReference string) (deleteWorkingResponse WorkingOrderResponse, err error)
- func (capClient *CapitalClientAPI) GetAllAccounts() (AccountsResponse, error)
- func (capClient *CapitalClientAPI) GetAllWorkingOrders() (workingOrdersResponse WorkingOrdersResponse, err error)
- func (capClient *CapitalClientAPI) GetEncriptionKey() (EncriptionResponse, error)
- func (capClient *CapitalClientAPI) GetEncryptedPassword(encriptionResponse EncriptionResponse) (string, error)
- func (capClient *CapitalClientAPI) GetHistoricalPrices(epic string, resolution Timeframe, numberOfCandles int) (pricesResponse PricesResponse, err error)
- func (capClient *CapitalClientAPI) GetMarketsDetails(epics []string) (MarketsDetailsResponse, error)
- func (capClient *CapitalClientAPI) GetPositionOrderConfirmation(dealReference string) (confirmation PositionOrderConfirmationResponse, err error)
- func (capClient *CapitalClientAPI) GetPositions() (positionsResponse PositionsResponse, err error)
- func (capClient *CapitalClientAPI) GetPreferredAccount() (AccountResponse, error)
- func (capClient *CapitalClientAPI) GetWatchLists() (WatchListsResponse, error)
- type CapitalClientUnathenticated
- type CapitalPrice
- type ConfirmationStatus
- type CreateWorkingOrderBody
- type EncriptionResponse
- type MarketsDetailsResponse
- type Minitrader
- type MinitraderMarketStatus
- type MinitraderPool
- type MinitraderStatus
- type NewSessionBody
- type NewSessionResponse
- type OrderType
- type PositionOrderConfirmationResponse
- type PositionsResponse
- type PricesResponse
- type Signal
- type Strategy
- type Timeframe
- type WatchListsResponse
- type WorkingOrderResponse
- type WorkingOrdersResponse
Constants ¶
View Source
const CAPITAL_DEBUG_DOMAIN_NAME = "https://demo-api-capital.backend-capital.com"
View Source
const CAPITAL_DOMAIN_NAME = "https://api-capital.backend-capital.com"
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AccountResponse ¶
type AccountResponse struct { AccountID string `json:"accountId"` AccountName string `json:"accountName"` Status string `json:"status"` AccountType string `json:"accountType"` Preferred bool `json:"preferred"` Balance struct { Balance float64 `json:"balance"` // maps to Equity Deposit float64 `json:"deposit"` // maps to Funds ProfitLoss float64 `json:"profitLoss"` // maps to P&L Available float64 `json:"available"` // maps to Available } `json:"balance"` Currency string `json:"currency"` }
type AccountsResponse ¶
type AccountsResponse struct {
Accounts []AccountResponse `json:"accounts"`
}
type AuthenticationTransport ¶
type AuthenticationTransport struct { http.RoundTripper X_SECURITY_TOKEN string CST string }
type BidAskPrice ¶
type Candle ¶
type Candle struct { Volume int64 Timestamp int64 Open BidAskPrice High BidAskPrice Low BidAskPrice Close BidAskPrice }
type Candles ¶
type Candles []Candle
func (*Candles) MarshalCapitalPrices ¶
func (candles *Candles) MarshalCapitalPrices(capitalPrices []CapitalPrice) error
type CapitalClientAPI ¶
type CapitalClientAPI struct { CAPITAL_EMAIL string CAPITAL_API_KEY string CAPITAL_API_KEY_PASSWORD string CapitalDomainName string HttpClient *http.Client }
func NewCapitalClient ¶
func (*CapitalClientAPI) CreateNewSession ¶
func (capClient *CapitalClientAPI) CreateNewSession() (newSessionResponse NewSessionResponse, headerTokens http.Header, err error)
func (*CapitalClientAPI) CreateWorkingOrder ¶
func (capClient *CapitalClientAPI) CreateWorkingOrder(epic string, direction Signal, orderType OrderType, targetPrice float64, orderSize float64) (createWorkingOrder WorkingOrderResponse, err error)
func (*CapitalClientAPI) DeleteWorkingOrder ¶
func (capClient *CapitalClientAPI) DeleteWorkingOrder(dealReference string) (deleteWorkingResponse WorkingOrderResponse, err error)
func (*CapitalClientAPI) GetAllAccounts ¶
func (capClient *CapitalClientAPI) GetAllAccounts() (AccountsResponse, error)
func (*CapitalClientAPI) GetAllWorkingOrders ¶
func (capClient *CapitalClientAPI) GetAllWorkingOrders() (workingOrdersResponse WorkingOrdersResponse, err error)
func (*CapitalClientAPI) GetEncriptionKey ¶
func (capClient *CapitalClientAPI) GetEncriptionKey() (EncriptionResponse, error)
func (*CapitalClientAPI) GetEncryptedPassword ¶
func (capClient *CapitalClientAPI) GetEncryptedPassword(encriptionResponse EncriptionResponse) (string, error)
func (*CapitalClientAPI) GetHistoricalPrices ¶
func (capClient *CapitalClientAPI) GetHistoricalPrices(epic string, resolution Timeframe, numberOfCandles int) (pricesResponse PricesResponse, err error)
func (*CapitalClientAPI) GetMarketsDetails ¶
func (capClient *CapitalClientAPI) GetMarketsDetails(epics []string) (MarketsDetailsResponse, error)
func (*CapitalClientAPI) GetPositionOrderConfirmation ¶
func (capClient *CapitalClientAPI) GetPositionOrderConfirmation(dealReference string) (confirmation PositionOrderConfirmationResponse, err error)
func (*CapitalClientAPI) GetPositions ¶
func (capClient *CapitalClientAPI) GetPositions() (positionsResponse PositionsResponse, err error)
func (*CapitalClientAPI) GetPreferredAccount ¶
func (capClient *CapitalClientAPI) GetPreferredAccount() (AccountResponse, error)
func (*CapitalClientAPI) GetWatchLists ¶
func (capClient *CapitalClientAPI) GetWatchLists() (WatchListsResponse, error)
type CapitalClientUnathenticated ¶
type CapitalClientUnathenticated struct{}
func (*CapitalClientUnathenticated) Error ¶
func (err *CapitalClientUnathenticated) Error() string
type CapitalPrice ¶
type CapitalPrice struct { SnapshotTime string `json:"snapshotTime"` SnapshotTimeUTC string `json:"snapshotTimeUTC"` OpenPrice struct { Bid float64 `json:"bid"` Ask float64 `json:"ask"` } `json:"openPrice"` ClosePrice struct { Bid float64 `json:"bid"` Ask float64 `json:"ask"` } `json:"closePrice"` HighPrice struct { Bid float64 `json:"bid"` Ask float64 `json:"ask"` } `json:"highPrice"` LowPrice struct { Bid float64 `json:"bid"` Ask float64 `json:"ask"` } `json:"lowPrice"` LastTradedVolume int `json:"lastTradedVolume"` }
type ConfirmationStatus ¶
type ConfirmationStatus string
const (
DELETED ConfirmationStatus = "DELETED"
)
type CreateWorkingOrderBody ¶
type EncriptionResponse ¶
type MarketsDetailsResponse ¶
type MarketsDetailsResponse struct { MarketDetails []struct { Instrument struct { Epic string `json:"epic"` Expiry string `json:"expiry"` Name string `json:"name"` LotSize int `json:"lotSize"` Type string `json:"type"` GuaranteedStopAllowed bool `json:"guaranteedStopAllowed"` StreamingPricesAvailable bool `json:"streamingPricesAvailable"` Currency string `json:"currency"` MarginFactor float64 `json:"marginFactor"` MarginFactorUnit string `json:"marginFactorUnit"` OpeningHours string `json:"openingHours"` Country string `json:"country"` } `json:"instrument"` DealingRules struct { MinStepDistance struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"minStepDistance"` MinDealSize struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"minDealSize"` MaxDealSize struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"maxDealSize"` MinSizeIncrement struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"minSizeIncrement"` MinGuaranteedStopDistance struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"minGuaranteedStopDistance"` MinStopOrProfitDistance struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"minStopOrProfitDistance"` MaxStopOrProfitDistance struct { Unit string `json:"unit"` Value float64 `json:"value"` } `json:"maxStopOrProfitDistance"` MarketOrderPreference string `json:"marketOrderPreference"` TrailingStopsPreference string `json:"trailingStopsPreference"` } `json:"dealingRules"` Snapshot struct { MarketStatus string `json:"marketStatus"` UpdateTime string `json:"updateTime"` DelayTime int `json:"delayTime"` Bid float64 `json:"bid"` Offer float64 `json:"offer"` DecimalPlacesFactor int `json:"decimalPlacesFactor"` ScalingFactor int `json:"scalingFactor"` } `json:"snapshot"` } `json:"marketDetails"` }
type Minitrader ¶
type Minitrader struct { Epic string Timeframe Timeframe Status MinitraderStatus MarketStatus MinitraderMarketStatus Strategy Strategy InvestmentPercentage float64 StopLossPercentage float64 ProfitPercentage float64 // contains filtered or unexported fields }
func NewMinitrader ¶
func (*Minitrader) Effect ¶
func (minitrader *Minitrader) Effect(signal Signal, price float64) error
func (*Minitrader) Start ¶
func (minitrader *Minitrader) Start(waitGroup *sync.WaitGroup)
type MinitraderMarketStatus ¶
type MinitraderMarketStatus string
const ( TRADEABLE MinitraderMarketStatus = "TRADEABLE" CLOSED MinitraderMarketStatus = "CLOSED" )
type MinitraderPool ¶
type MinitraderPool struct { Minitraders []*Minitrader CapitalClient *CapitalClientAPI // contains filtered or unexported fields }
func NewMinitraderPool ¶
func NewMinitraderPool(capitalClient *CapitalClientAPI, minitraders ...*Minitrader) (*MinitraderPool, error)
func (*MinitraderPool) AuthenticateSession ¶
func (pool *MinitraderPool) AuthenticateSession(sleepTime time.Duration)
func (*MinitraderPool) Pulse ¶
func (pool *MinitraderPool) Pulse()
func (*MinitraderPool) Start ¶
func (pool *MinitraderPool) Start()
func (*MinitraderPool) UpdateMarketStatus ¶
func (pool *MinitraderPool) UpdateMarketStatus(sleepTime time.Duration)
func (*MinitraderPool) UpdateMinitradersData ¶
func (pool *MinitraderPool) UpdateMinitradersData(sleepTime time.Duration)
type MinitraderStatus ¶
type MinitraderStatus string
const ( // healthy statuses NEW MinitraderStatus = "NEW" RUNNING MinitraderStatus = "RUNNING" HOLDING MinitraderStatus = "HOLDING" SELL_ORDER_ACTIVE MinitraderStatus = "SELL_ORDER_ACTIVE" BUY_ORDER_ACTIVE MinitraderStatus = "BUY_ORDER_ACTIVE" // error statuses ERROR_ON_UPDATE_CANDLES_DATA MinitraderStatus = "ERROR_ON_UPDATE_CANDLES_DATA" ERROR_ON_MAKING_ORDER MinitraderStatus = "ERROR_ON_MAKING_ORDER" ERROR_ON_DELETING_ORDER MinitraderStatus = "ERROR_ON_DELETING_ORDER" )
type NewSessionBody ¶
type NewSessionResponse ¶
type NewSessionResponse struct { AccountType string `json:"accountType"` CurrencyIsoCode string `json:"currencyIsoCode"` CurrencySymbol string `json:"currencySymbol"` CurrentAccountId string `json:"currentAccountId"` StreamingHost string `json:"streamingHost"` ClientId string `json:"clientId"` TimezoneOffset int `json:"timezoneOffset"` HasActiveDemoAccounts bool `json:"hasActiveDemoAccounts"` HasActiveLiveAccounts bool `json:"hasActiveLiveAccounts"` TrailingStopsEnabled bool `json:"trailingStopsEnabled"` Accounts []struct { AccountId string `json:"accountId"` AccountName string `json:"accountName"` Preferred bool `json:"preferred"` AccountType string `json:"accountType"` } `json:"accounts"` AccountInfo struct { Balance float64 `json:"balance"` Deposit float64 `json:"deposit"` ProfitLoss float64 `json:"profitLoss"` Available float64 `json:"available"` } `json:"accountInfo"` }
type PositionOrderConfirmationResponse ¶
type PositionOrderConfirmationResponse struct { Date string `json:"date"` Status string `json:"status"` Reason string `json:"reason"` DealStatus string `json:"dealStatus"` Epic string `json:"epic"` DealRef string `json:"dealReference"` DealID string `json:"dealId"` AffectedDeals []struct { ID string `json:"dealId"` Status string `json:"status"` } `json:"affectedDeals"` Level float64 `json:"level"` Size float64 `json:"size"` // maps to QTY (quantity) Direction string `json:"direction"` GuaranteedStop bool `json:"guaranteedStop"` TrailingStop bool `json:"trailingStop"` }
type PositionsResponse ¶
type PositionsResponse struct { Positions []struct { Position struct { ContractSize int `json:"contractSize"` CreatedDate time.Time `json:"createdDate"` CreatedDateUTC time.Time `json:"createdDateUTC"` DealID string `json:"dealId"` DealReference string `json:"dealReference"` Size int `json:"size"` Direction string `json:"direction"` Level float64 `json:"level"` Currency string `json:"currency"` GuaranteedStop bool `json:"guaranteedStop,omitempty"` ControlledRisk bool `json:"controlledRisk,omitempty"` } `json:"position"` Market struct { InstrumentName string `json:"instrumentName"` Expiry string `json:"expiry"` MarketStatus string `json:"marketStatus"` Epic string `json:"epic"` InstrumentType string `json:"instrumentType"` LotSize int `json:"lotSize"` High float64 `json:"high"` Low float64 `json:"low"` PercentageChange float64 `json:"percentageChange"` NetChange float64 `json:"netChange"` Bid float64 `json:"bid"` Offer float64 `json:"offer"` UpdateTime time.Time `json:"updateTime"` UpdateTimeUTC time.Time `json:"updateTimeUTC"` DelayTime int `json:"delayTime"` StreamingPricesAvail bool `json:"streamingPricesAvailable"` ScalingFactor int `json:"scalingFactor"` } `json:"market"` } `json:"positions"` }
type PricesResponse ¶
type PricesResponse struct {
Prices []CapitalPrice
}
type WatchListsResponse ¶
type WorkingOrderResponse ¶
type WorkingOrderResponse struct {
DealReference string `json:"dealReference"`
}
type WorkingOrdersResponse ¶
type WorkingOrdersResponse struct { WorkingOrders []struct { WorkingOrderData struct { DealID string `json:"dealId"` Direction string `json:"direction"` Epic string `json:"epic"` OrderSize int `json:"orderSize"` OrderLevel int `json:"orderLevel"` TimeInForce string `json:"timeInForce"` GoodTillDate string `json:"goodTillDate"` GoodTillDateUTC string `json:"goodTillDateUTC"` CreatedDate string `json:"createdDate"` CreatedDateUTC string `json:"createdDateUTC"` GuaranteedStop bool `json:"guaranteedStop"` OrderType string `json:"orderType"` StopDistance float64 `json:"stopDistance"` ProfitDistance float64 `json:"profitDistance"` CurrencyCode string `json:"currencyCode"` } `json:"workingOrderData"` MarketData struct { InstrumentName string `json:"instrumentName"` Expiry string `json:"expiry"` MarketStatus string `json:"marketStatus"` Epic string `json:"epic"` InstrumentType string `json:"instrumentType"` LotSize int `json:"lotSize"` High float64 `json:"high"` Low float64 `json:"low"` PercentageChange float64 `json:"percentageChange"` NetChange float64 `json:"netChange"` Bid float64 `json:"bid"` Offer float64 `json:"offer"` UpdateTime string `json:"updateTime"` UpdateTimeUTC string `json:"updateTimeUTC"` DelayTime int `json:"delayTime"` StreamingPricesAvailable bool `json:"streamingPricesAvailable"` ScalingFactor int `json:"scalingFactor"` } `json:"marketData"` } `json:"workingOrders"` }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.