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

Bulk Insert of historical data - how to access private members? #47

Open
eugenefvdm opened this issue Jan 21, 2024 · 1 comment
Open

Comments

@eugenefvdm
Copy link

Proposal to amend code to allow bulk inserts

I would like to do a bulk insert of historical data. This is trivial using Laravel's Query helper:

$client = Scheb\YahooFinanceApi\ApiClientFactory::createApiClient();
$historicalPricing = $client->getHistoricalQuoteData(
  "msft",
  Scheb\YahooFinanceApi\ApiClient::INTERVAL_1_DAY,
  new \DateTime("-1 year"),
  new \DateTime("today")
);

DB::table("share_price_histories")->insert($newArray);

However, since ->getHistoricalQuoteData returns results as private members I'm lost as how to do it.

I could technically run for-next loop and convert everything to a new array, and then insert it, but having the for-next loop seems like a penalty.

I'm happy to do a pull request but I will need some guidance.

In theory one could make all the members as public access but I guess this will break some programming discipline.

Any assistance will be appreciated on how I could go about doing this.

@eugenefvdm eugenefvdm changed the title Bulk Insert Bulk Insert of historical data - how to access private members? Jan 21, 2024
@scheb
Copy link
Owner

scheb commented Jan 21, 2024

We could add a toArray function returning all properties as an array.

A function

public function toArray(): array {
    return get_object_vars($this);
}

should to the job and make it happen quite efficiently, as the data model only contains data fields and nothing else.

If we add this, it should be added to every model class (not only HistoricalData).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants