Code Monkey home page Code Monkey logo

Comments (5)

Reidmcc avatar Reidmcc commented on July 18, 2024

I'm planning to work on this; can you clarify how the double-quoted formatting ties into the case change?

from kelp.

nikhilsaraf avatar nikhilsaraf commented on July 18, 2024

@Reidmcc thanks for taking this on.

You would need to use the toml tag with the ALL_CAPS version of the field name, like so:

tradingSecretSeed     string `toml:"TRADING_SECRET_SEED"`

(see the examples section of the BurntSushi/toml parser)

You can keep the existing valid tag for now and add the second toml tag using a space to separate them. Here's an example

from kelp.

Reidmcc avatar Reidmcc commented on July 18, 2024

This doesn't seem to work; the executable builds but throws a Unknown fields error when attempting to parse the strategy config. If you leave one of the fields as ALL_CAPS that fields parses but the changed fields do not. For example, if the struct is:

type balancedConfig struct {
	PRICE_TOLERANCE               float64 `valid:"-" toml:"PRICE_TOLERANCE"`
	amountTolerance               float64 `valid:"-" toml:"AMOUNT_TOLERANCE"`
	spread                        float64 `valid:"-" toml:"SPREAD"`                       
	minAmountSpread               float64 `valid:"-" toml:"MIN_AMOUNT_SPREAD"`            
	maxAmountSpread               float64 `valid:"-" toml:"MAX_AMOUNT_SPREAD"`        
	maxLevels                     int16   `valid:"-" toml:"MAX_LEVELS"`                    
	levelDensity                  float64 `valid:"-" toml:"LEVEL_DENSITY"`                   
	ensureFirstNLevels            int16   `valid:"-" toml:"ENSURE_FIRST_N_LEVELS"`           
	minAmountCarryoverSpread      float64 `valid:"-" toml:"MIN_AMOUNT_CARRYOVER_SPREAD"`     
	maxAmountCarryoverSpread      float64 `valid:"-" toml:"MAX_AMOUNT_CARRYOVER_SPREAD"`     
	carryoverInclusionProbability float64 `valid:"-" toml:"CARRYOVER_INCLUSION_PROBABILITY"`
	virtualBalanceBase            float64 `valid:"-" toml:"VIRTUAL_BALANCE_BASE"`           
	virtualBalanceQuote           float64 `valid:"-" toml:"VIRTUAL_BALANCE_QUOTE"`
}

The error comes back with everything except PRICE_TOLERANCE as unknown:

parse_err

Am I missing something?

from kelp.

nikhilsaraf avatar nikhilsaraf commented on July 18, 2024

@Reidmcc the field name inside the struct needs to be exported. i.e. TradingSecretSeed instead of tradingSecretSeed. My bad on the above example that used a unexported struct variable.


You'll need to fix the StructString() function in support/utils/configs.go to use the correct display name for the config so they are displayed with the ALL_CAPS version of the toml string.

Additionally, we should keep the transformations intact. Currently the transforms map takes in values based on the field name. This is used to convert secret keys to public keys for display. We need to update the StructString() method to map this based on the config ALL_CAPS name.

To sum up these changes we should introduce a new variable fieldDisplayName in StructString(), line 29-48 in support/utils/configs.go should be something like this:

for i := 0; i < numFields; i++ {
	field := reflect.TypeOf(s).Field(i)
	fieldName := field.Name
	fieldDisplayName := field.Tag.Get("toml")
	if fieldDisplayName == "" {
		fieldDisplayName = fieldName
	}

	// set the transformation function
	transformFn := passthrough
	if fn, ok := transforms[fieldDisplayName]; ok {
		transformFn = fn
	}

	if reflect.ValueOf(s).Field(i).CanInterface() {
		value := reflect.ValueOf(s).Field(i).Interface()
		transformedValue := transformFn(value)
		buf.WriteString(fmt.Sprintf("%s: %+v\n", fieldDisplayName, transformedValue))
	}
}

from kelp.

Reidmcc avatar Reidmcc commented on July 18, 2024

I didn't see the full text of this message separately from the PR message. I'll finish the rest of this soon.

from kelp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.