|
1 | | -[](https://gitpod.io/#https://github.com/vegaprotocol/sample-api-scripts) |
2 | 1 |
|
3 | | -# Sample API scripts |
| 2 | +# Sample API Scripts |
4 | 3 |
|
5 | | -This repo contains sample scripts in various languages. These scripts use the |
6 | | -Vega core and wallet APIs to interact with Vega core nodes and wallet servers. |
| 4 | +This repo contains Vega code examples in Python. These scripts use the Vega data-node and wallet APIs to interact with a Vega network. |
7 | 5 |
|
8 | | -# Gitpod |
| 6 | +With Vega users can consume APIs on the network using three different options (navigate through to your desired set of scripts): |
| 7 | + |
| 8 | + * **[REST](./rest#readme)** |
| 9 | + * **[GraphQL](./graphql#readme)** |
| 10 | + * gRPC - *coming soon!* |
| 11 | + |
| 12 | +The purpose of these samples is to give simple and clear code that can be used to illustrate how to do something via Vega's APIs. |
9 | 13 |
|
10 | | -Get started with the sample API scripts with zero configuration. Click on the |
11 | | -"Gitpod ready-to-code" button above. |
| 14 | +For example, show me a list of trades on a particular market, stream my latest orders or submit a new liquidity commitment, etc. |
12 | 15 |
|
13 | | -# Getting started for Unix based systems (Mac OS & Linux) |
14 | | -1. Clone this repo onto your local machine so you have access to all the files and can change them as you need. |
| 16 | +If these scripts do not provide what you're looking for there are even more tutorials, code and further examples on how to integrate with Vega (including API reference docs) at **https://docs.vega.xyz** |
| 17 | + |
| 18 | +## Gitpod |
| 19 | + |
| 20 | +This repo has been designed to be quick for a user to get started with. If you do not want to clone the code locally, you can use [Gitpod](https://gitpod.io/) to get started with zero configuration in your browser. |
| 21 | + |
| 22 | +[](https://gitpod.io/#https://github.com/vegaprotocol/sample-api-scripts) |
| 23 | + |
| 24 | +Click on the "Gitpod ready-to-code" button above to load a browser based linux development environment and start experimenting straight away. |
| 25 | + |
| 26 | +## Getting started for Unix based systems (Gitpod, Mac OS & Linux) |
| 27 | + |
| 28 | +1. Load up a Gitpod environment (above) OR Clone this repo onto your local machine so you have access to all the files and can change them as you need. |
15 | 29 | ```bash |
16 | 30 | git clone https://github.com/vegaprotocol/sample-api-scripts.git |
17 | 31 | ``` |
18 | | - This should create you a folder named `sample-api-scripts` that you will use for the rest of this README. |
19 | | -1. Copy or rename the `credentials-template` file as `credentials`. |
| 32 | + This should create you a folder named `sample-api-scripts` that you will use for the rest of this README. |
20 | 33 | *Note: When running on Gitpod this is already done for you.* |
21 | | - ```bash |
22 | | - cp credentials-template credentials |
23 | | - ``` |
24 | | -1. Edit the `credentials` file. (`nano` and `vim` are installed, or use the built-in Gitpod text editor.) |
25 | | - ```bash |
26 | | - nano credentials |
27 | | - (press Ctrl-O, Enter, Ctrl-X to save and exit) |
28 | | - ``` |
29 | | -1. The URL values will already be set up correctly for testnet including using the testnet hosted wallet. You will need to update your wallet credentials, near the top of the file. If you are going to use the scripts on mainnet, the URL details can be found in your wallet connections file of your local wallet server or in the Vega Wallet desktop app. If you are uncomfortable placing your wallet password into the credentials file, you can directly set the value using the export command: |
30 | | - ```bash |
31 | | - export WALLET_PASSPHRASE="<your password>" |
32 | | - ``` |
33 | | - |
34 | | -1. Import the credentials into your local environment: `source credentials` |
35 | | - |
| 34 | + |
| 35 | +1. Import the appropriate `vega-config` into your local environment for the network you want to test against (default vega-config is Fairground testnet). |
| 36 | + ``` |
| 37 | + source vega-config |
| 38 | + ``` |
| 39 | + You can define, copy or edit your own configurations. Out of the box, the vega-config file is included for ease and defaults to the Fairground testnet with hosted wallet configuration. *Node: Don't forget to source your configs after making any changes.* |
| 40 | + |
| 41 | +1. Navigate to the API transport you would like to explore, for example: |
| 42 | + ``` |
| 43 | + cd ./rest |
| 44 | + ``` |
| 45 | + |
| 46 | +1. Follow the sub-folder README.md information on how to run the samples. |
| 47 | + |
36 | 48 | # Getting started for Windows |
37 | 49 |
|
38 | 50 | 1. Clone this repo onto your local machine so you have access to all the files and can change them as you need. |
39 | 51 | ```bash |
40 | 52 | git clone git@github.com:vegaprotocol/sample-api-scripts.git |
41 | 53 | ``` |
42 | 54 | This should create you a folder named `sample-api-scripts` that you will use for the rest of this README. |
43 | | -1. Copy or rename the `credentials-win-template` file as `credentials-win`. |
44 | | - ```bash |
45 | | - copy credentials-win-template credentials-win |
46 | | - ``` |
47 | | -1. Edit the `credentials-win` file. |
48 | | - ```bash |
49 | | - notepad credentials-win |
50 | | - ``` |
51 | | -1. The URL values will already be set up correctly for testnet including using the testnet hosted wallet. You will need to update your wallet credentials, near the top of the file. If you are going to use the scripts on mainnet, the URL details can be found in your wallet connections file of your local wallet server or in the Vega Wallet desktop app. If you are uncomfortable placing your wallet password into the credentials file, you can directly set the value using the export command: |
52 | | - ```bash |
53 | | - set WALLET_PASSPHRASE="<your password>" |
54 | | - ``` |
55 | | -1. Run the setup batch script to import the credentials into your local environment: `setup.bat` |
56 | | - |
57 | | - |
58 | | -# Prerequisites |
59 | | - |
60 | | -The following tools or applications are required for these scripts to work. Here are the commands to check they are installed on your system: |
61 | | - |
62 | | -1. python3 |
63 | | - ```bash |
64 | | - python3 --version |
65 | | - ``` |
66 | | -1. pip3 |
67 | | - ```bash |
68 | | - pip3 --version |
69 | | - ``` |
70 | | - To make sure we have all the correct libraries you can use pip with the requirements.txt to install them all |
71 | | - ```bash |
72 | | - pip3 install -r requirements.txt |
73 | | - ``` |
74 | | -1. gq (https://github.com/hasura/graphqurl) |
75 | | - ```bash |
76 | | - gq --version |
77 | | - ``` |
78 | 55 | |
79 | | - |
80 | | -To make sure you have all the tools required and have setup your environment correctly, it is best to try out the most basic `vega-time` script. |
81 | | - |
82 | | -```bash |
83 | | -python3 vega-time/get-time.py |
84 | | -``` |
85 | | - |
86 | | -If this correctly gets the time then you have everything you need to use the other scripts. If the script fails to run, check out the trouble shooting guide at the bottom of this page. |
87 | | - |
88 | | - |
89 | | -And you're good to go. Now choose a sample program to run from the following (see the link in the **Folder** column to learn how to run each sample script): |
90 | | -
|
91 | | -# Sample scripts |
92 | | -
|
93 | | -| Script description | Languages | API transport | Folder & README | |
94 | | -| :----------------- | :------- | :------------------------------ | :---------- | |
95 | | -| Get Asset | python3 | Vega node [GraphQL, REST, gRPC] | / [get-assets](get-assets) | |
96 | | -| Orders by reference | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-by-reference](get-by-reference) | |
97 | | -| List market details and market data | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-markets-and-market-data](get-markets-and-market-data) | |
98 | | -| List Vega network parameters | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-network-parameters](get-network-parameters) | |
99 | | -| List orders and trades | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-orders-and-trades](get-orders-and-trades) | |
100 | | -| Vega statistics | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-statistics](get-statistics) | |
101 | | -| List parties and accounts | bash, python3 | Vega node [REST, gRPC] | / [parties-and-accounts](parties-and-accounts) | |
102 | | -| Stream market data | python3 | Vega node [GraphQL] | / [stream-marketdata](stream-marketdata) | |
103 | | -| Stream orders and trades | python3 | Vega node [GraphQL] | / [stream-orders-and-trades](stream-orders-and-trades) | |
104 | | -| Interact with Vega wallet API | bash, python3 | Vega wallet [REST] | / [wallet](wallet) | |
105 | | -| Submit, amend and cancel orders | bash, python3 | Vega wallet [REST], Vega node [REST, gRPC] | / [submit-amend-cancel-orders](submit-amend-cancel-orders) | |
106 | | -| Submit and amend pegged orders | bash, python3 | Vega wallet [REST], Vega node [REST, gRPC] | / [submit-amend-pegged-order](submit-amend-pegged-order) | |
107 | | -| Vega/blockchain time | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [vega-time](vega-time) | |
108 | | -| Streaming events | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [stream-events](stream-events) | |
109 | | -| Fees and margins estimation | bash, python3 | Vega node [REST, gRPC] | / [fees-margins-estimation](fees-margins-estimation) | |
110 | | -| Propose, vote and enact new markets | python3 | Vega node [REST] | / [propose-markets](propose-markets) | |
111 | | -| Propose, vote and enact network parameters update | python3 | Vega node [REST] | / [propose-netparams](propose-netparams) | |
112 | | -| Propose, vote and enact new freeform proposal | python3 | Vega node [REST] | / [propose-freeform](propose-freeform) | |
113 | | -| List proposals | bash, python3 | Vega node [GraphQL, gRPC] | / [propose-votes](propose-votes) | |
114 | | -| Submit create liquidity provision | bash, python3 | Data node [GraphQL, gRPC] | / [submit-create-liquidity-provision](submit-create-liquidity-provision) | |
115 | | -| Submit amend liquidity provision | bash, python3 | Data node [GraphQL, gRPC] | / [submit-amend-liquidity-provision](submit-amend-liquidity-provision) | |
116 | | -| Submit cancel liquidity provision | bash, python3 | Data node [GraphQL, gRPC] | / [submit-cancel-liquidity-provision](submit-cancel-liquidity-provision) | |
117 | | -
|
118 | | -# Troubleshooting |
119 | | -
|
120 | | -Python/terminal: If you get `No module named 'helpers'...`, you should enter `source credentials` and check with `echo "$PYTHONPATH"` than it shows `"."`. |
| 56 | +1. Import the appropriate `vega-config-win` into your local environment for the network you want to test against (default is Fairground testnet). |
| 57 | + ``` |
| 58 | + source vega-config-win |
| 59 | + ``` |
| 60 | + You can define, copy or edit your own configurations. Out of the box, the vega-config-win file is included for ease and defaults to the Fairground testnet with hosted wallet configuration. *Node: Don't forget to source your configs after making any changes.* |
| 61 | + |
| 62 | +1. Run the setup batch script on your command prompt/terminal to import the vega-config into your local environment: |
| 63 | + ``` |
| 64 | + setenv.bat |
| 65 | + ``` |
| 66 | + |
| 67 | +1. Navigate to the API transport you would like to explore, for example: |
| 68 | + ``` |
| 69 | + cd rest |
| 70 | + ``` |
| 71 | + |
| 72 | +1. Follow the sub-folder README.md information on how to run the samples. |
121 | 73 |
|
122 | 74 | # Contributing or raising issues |
123 | 75 |
|
124 | | -Please reach out to us on the [community forums](https://community.vega.xyz/c/testnet/) or [Discord chat](https://discord.gg/bkAF3Tu) to enquire further about how to get involved with Vega. |
| 76 | +Please reach out to us on the [Discord chat](https://discord.gg/bkAF3Tu) to enquire further about how to get involved with Vega, alternatively you can check out the [Builders Club](https://vega.xyz/builders-club/). |
125 | 77 |
|
126 | | -If you have found an issue or would like to suggest an improvement with our public code samples, please raise an issue in the [Sample-API-Scripts](https://github.com/vegaprotocol/sample-api-scripts/) repository. If you'd like to submit a PR we welcome additional sample code. |
| 78 | +If you have found an issue or would like to suggest an improvement with our public code samples, please raise an issue in the [Sample-API-Scripts](https://github.com/vegaprotocol/sample-api-scripts/) repository. If you'd like to submit a PR we welcome additional sample code. |
0 commit comments