fnmbroker

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 15 Imported by: 0

README

finam-broker

An implementation of trengin.Broker using Finam Trade API for creating automated trading robots.

Features

  • Opens position, changes stop loss and take profit, closes position.
  • Tracks open position.
  • Supports multiple open positions at the same time.

How to use

Create a new Finam object using constructor New. Pass full-access token, client id.

package main

import (
	"context"
	"log"

	"github.com/evsamsonov/trengin/v2"
	"github.com/evsamsonov/finam-broker"
)

func main() {
	finamBroker := fnmbroker.New(
		"token",
		"123",
		// options...
	)

	tradingEngine := trengin.New(&Strategy{}, finamBroker)
	if err := tradingEngine.Run(context.Background()); err != nil {
		log.Fatal("Trading engine crashed")
	}
}

type Strategy struct{}
func (s *Strategy) Run(ctx context.Context, actions trengin.Actions) error { panic("implement me") }

See more details in trengin documentation.

Option

You can configure Finam to use Option

Methods Returns Option which
WithLogger Sets logger. The default logger is no-op Logger.
WithProtectiveSpreadPercent Sets protective spread in percent for executing orders. The default value is 1%.
WithUseCredit Sets using credit funds for executing orders.
WithSecurityCacheFile Sets path to securities cache file. Default is ./securities.json

Checkup

Use finam-checkup for checking the ability to trade with a specific token and client id.

How to install
go install github.com/evsamsonov/finam-broker/cmd/finam-checkup@latest
How to use
finam-checkup [CLIENT_ID] [SECURITY_BOARD] [SECURITY_CODE] [-v]
Flag Description
-v Print logger output

Development

Makefile

Makefile tasks are required docker and golang.

$ make help    
doc                            Run doc server using docker
lint                           Run golang lint using docker
pre-push                       Run golang lint and test
test                           Run tests
TODO
  • Use protective spread for open position
  • Add commission to position
  • Remove duplicate events in order trade listener
  • Add unit tests

Documentation

Overview

Package fnmbroker implements trengin.Broker using Finam Trade API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finam

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

func New

func New(token, clientID string, opts ...Option) *Finam

New creates a new Finam object. It takes full-access token, client id.

func (*Finam) ChangeConditionalOrder

func (f *Finam) ChangeConditionalOrder(
	_ context.Context,
	action trengin.ChangeConditionalOrderAction,
) (trengin.Position, error)

func (*Finam) ClosePosition

func (f *Finam) ClosePosition(
	ctx context.Context,
	action trengin.ClosePositionAction,
) (trengin.Position, error)

func (*Finam) OpenPosition

func (f *Finam) OpenPosition(
	ctx context.Context,
	action trengin.OpenPositionAction,
) (trengin.Position, trengin.PositionClosed, error)

OpenPosition see https://finamweb.github.io/trade-api-docs/grpc/orders

func (*Finam) Run

func (f *Finam) Run(ctx context.Context) error

Run initializes required objects and starts to track an open positions

type Option

type Option func(*Finam)

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger returns Option which sets logger. The default logger is no-op Logger

func WithProtectiveSpreadPercent

func WithProtectiveSpreadPercent(protectiveSpread float64) Option

WithProtectiveSpreadPercent returns Option which sets protective spread in percent for executing orders. The default value is 1%

func WithSecurityCacheFile

func WithSecurityCacheFile(securityCacheFile string) Option

WithSecurityCacheFile returns Option which sets path to securities cache file. The default value is securities.json in current directory

func WithUseCredit

func WithUseCredit(useCredit bool) Option

WithUseCredit returns Option which sets using credit funds for executing orders. The default value is true

Directories

Path Synopsis
cmd
finam-checkup
Finam-checkup checks all methods of Finam Broker.
Finam-checkup checks all methods of Finam Broker.

Jump to

Keyboard shortcuts

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