Last active
May 25, 2020 19:33
-
-
Save DannyvdSluijs/8fa3743cc10121bed65e57df87724e2a to your computer and use it in GitHub Desktop.
Map Bitstamp using Symfony Serializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Illuminate\Support\Facades\Http; | |
| use Symfony\Component\Serializer\Encoder\JsonEncoder; | |
| use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | |
| use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; | |
| use Symfony\Component\Serializer\Serializer; | |
| use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; | |
| class TradingPair { | |
| public string $name; | |
| public string $description; | |
| public int $baseDecimals; | |
| public int $counterDecimals; | |
| public string $minimumOrder; | |
| public string $trading; | |
| public string $urlSymbol; | |
| } | |
| $response = Http::get('https://www.bitstamp.net/api/v2/trading-pairs-info/'); | |
| $serializer = new Serializer( | |
| [ | |
| new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter()), | |
| new ArrayDenormalizer() | |
| ], | |
| [ | |
| new JsonEncoder() | |
| ] | |
| ); | |
| $pairs = $serializer->deserialize($response, TradingPair::class . '[]', 'json'); | |
| dd($pairs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment