Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't detect the nonexistance of update rules in stock trade conditions #471

Open
aimscreenname opened this issue Nov 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@aimscreenname
Copy link

Describe the bug
It's not possible to detect the nonexistance of stock trade condition "update rules". This is necessary for conditions like condition 60 that don't have update_rules in returned JSON responses.

To Reproduce

package main

import (
	"context"
	"fmt"

	polygonrest "github.com/polygon-io/client-go/rest"
	polygonrestmodels "github.com/polygon-io/client-go/rest/models"
)

const polygonAPIKey = "API_KEY"

func main() {
	client := polygonrest.New(polygonAPIKey)
	params := polygonrestmodels.ListConditionsParams{}.
		WithAssetClass(polygonrestmodels.AssetStocks).
		WithDataType(polygonrestmodels.DataTrade).
		WithID(60)
	iter := client.ReferenceClient.ListConditions(context.Background(), params)
	for iter.Next() {
		fmt.Println(iter.Item().UpdateRules)
	}
	if err := iter.Err(); err != nil {
		panic(err)
	}
}

Result:

{{false false false} {false false false}}

Expected behavior
Making UpdateRules nillable would enable existance checks.

-	UpdateRules  UpdateRules `json:"update_rules,omitempty"`
+	UpdateRules  *UpdateRules `json:"update_rules,omitempty"`

Result:

<nil>

Additional context
Note that this proposed implementation would silently break downstream code by compiling without error and causing runtime panics. I care more that I can determine existence at all than how it's surfaced in the client. I drew this solution from the Python and Typescript implementations.

I'm constructing bars from trades by assuming update rules for each trade are true unless any conditions indicate false. Condition 60 showed up consistently on trades for TGT today, resulting in "frozen" bars that never updated even though Polygon aggs did update over time.

@aimscreenname aimscreenname added the bug Something isn't working label Nov 20, 2024
@justinpolygon
Copy link
Contributor

Hey @aimscreenname, are you building your own bars based on trade data and wanted to look for trades that are eligible? Just trying to figure out the use-case here. I think you could likely do something in reverse in that say all trade are not eligible unless they are. Just wanted to see if that's what you're trying to solve for or not first before looking into this.

@aimscreenname
Copy link
Author

@justinpolygon That's right, my goal is to build my own bars based on trade data. Going reverse produced volume inconsistent with Polygon aggs bars for me in the past. This blog post talks about the "eligible unless" approach, too.

That said, I'm only proposing existence checks based on public APIs I'm seeing. Maybe only "type": "sale_condition" conditions affect eligibility? An official code example of reconstructing bars from trades could clear up confusion on my side.

@justinpolygon
Copy link
Contributor

Hey @aimscreenname, thanks for the reply. I'm going to check this out and see the impact. I just don't want to make a breaking change here so want to explore the options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants