Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
648533b
Clean sample-api-scripts file structure for v2 data node support
cdm Nov 18, 2022
182dde8
Add python v2 rest API examples
cdm Nov 21, 2022
17b80af
Get assets
SuDa2103 Nov 21, 2022
3603a35
Get markets
SuDa2103 Nov 21, 2022
e7dcad2
Add query names
SuDa2103 Nov 21, 2022
49c7384
Orders
SuDa2103 Nov 21, 2022
9f0ae66
Parties accounts and trades for order
SuDa2103 Nov 21, 2022
65c68ef
Subscriptions
SuDa2103 Nov 21, 2022
221af22
Added configs and readme updates
cdm Nov 21, 2022
370577f
accounts, balances and governance votes
SuDa2103 Nov 21, 2022
4153e5a
Comments and new structure added
SuDa2103 Nov 21, 2022
920c9e9
get assets
SuDa2103 Nov 22, 2022
49c6508
get markets
SuDa2103 Nov 22, 2022
9495de1
Everything up to markets
SuDa2103 Nov 22, 2022
1f9fb62
Update README.md
cdm Nov 22, 2022
f49f038
Get candles
SuDa2103 Nov 22, 2022
40fa983
Get deposits
SuDa2103 Nov 23, 2022
51c5985
transfers and withdrawals
SuDa2103 Nov 23, 2022
ae3f9c3
Get margin levels
SuDa2103 Nov 24, 2022
b16ae73
Node data
SuDa2103 Nov 24, 2022
cba8957
New format pt 1
SuDa2103 Nov 25, 2022
bd6d50d
New format pt 2
SuDa2103 Nov 25, 2022
21ac754
New format pt3
SuDa2103 Nov 25, 2022
b33b64b
New Format pt 4
SuDa2103 Nov 25, 2022
05d2543
Positions, rewards and staking data
SuDa2103 Nov 25, 2022
bd69f85
Naming
SuDa2103 Nov 25, 2022
5a8906d
Merge pull request #164 from vegaprotocol/gql-v2
SuDa2103 Nov 25, 2022
07ddcd7
readme for gql
SuDa2103 Nov 30, 2022
d4f0d15
Further detail
SuDa2103 Nov 30, 2022
3485007
Merge pull request #165 from vegaprotocol/gql-readme
SuDa2103 Nov 30, 2022
d2b80c4
Added extra streaming examples
cdm Nov 30, 2022
38e27a4
Merge branch '160-refactor-for-v2-apis' of github.com:vegaprotocol/sa…
cdm Nov 30, 2022
15dfac7
Improve market proposal script with stake linking check
cdm Dec 4, 2022
a20742f
Market depth updates stream example
cdm Dec 4, 2022
f897559
Update margin levels
cdm Dec 4, 2022
2c72b44
Add streaming examples
cdm Dec 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ credentials.*
*.tmp
.idea
.DS_Store
token.temp
13 changes: 0 additions & 13 deletions Pipfile

This file was deleted.

68 changes: 0 additions & 68 deletions Pipfile.lock

This file was deleted.

162 changes: 57 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,78 @@
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/vegaprotocol/sample-api-scripts)

# Sample API scripts
# Sample API Scripts

This repo contains sample scripts in various languages. These scripts use the
Vega core and wallet APIs to interact with Vega core nodes and wallet servers.
This repo contains Vega code examples in Python. These scripts use the Vega data-node and wallet APIs to interact with a Vega network.

# Gitpod
With Vega users can consume APIs on the network using three different options (navigate through to your desired set of scripts):

* **[REST](./rest#readme)**
* **[GraphQL](./graphql#readme)**
* gRPC - *coming soon!*

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.

Get started with the sample API scripts with zero configuration. Click on the
"Gitpod ready-to-code" button above.
For example, show me a list of trades on a particular market, stream my latest orders or submit a new liquidity commitment, etc.

# Getting started for Unix based systems (Mac OS & Linux)
1. Clone this repo onto your local machine so you have access to all the files and can change them as you need.
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**

## Gitpod

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.

[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/vegaprotocol/sample-api-scripts)

Click on the "Gitpod ready-to-code" button above to load a browser based linux development environment and start experimenting straight away.

## Getting started for Unix based systems (Gitpod, Mac OS & Linux)

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.
```bash
git clone https://github.com/vegaprotocol/sample-api-scripts.git
```
This should create you a folder named `sample-api-scripts` that you will use for the rest of this README.
1. Copy or rename the `credentials-template` file as `credentials`.
This should create you a folder named `sample-api-scripts` that you will use for the rest of this README.
*Note: When running on Gitpod this is already done for you.*
```bash
cp credentials-template credentials
```
1. Edit the `credentials` file. (`nano` and `vim` are installed, or use the built-in Gitpod text editor.)
```bash
nano credentials
(press Ctrl-O, Enter, Ctrl-X to save and exit)
```
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:
```bash
export WALLET_PASSPHRASE="<your password>"
```

1. Import the credentials into your local environment: `source credentials`


1. Import the appropriate `vega-config` into your local environment for the network you want to test against (default vega-config is Fairground testnet).
```
source vega-config
```
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.*

1. Navigate to the API transport you would like to explore, for example:
```
cd ./rest
```

1. Follow the sub-folder README.md information on how to run the samples.

# Getting started for Windows

1. Clone this repo onto your local machine so you have access to all the files and can change them as you need.
```bash
git clone git@github.com:vegaprotocol/sample-api-scripts.git
```
This should create you a folder named `sample-api-scripts` that you will use for the rest of this README.
1. Copy or rename the `credentials-win-template` file as `credentials-win`.
```bash
copy credentials-win-template credentials-win
```
1. Edit the `credentials-win` file.
```bash
notepad credentials-win
```
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:
```bash
set WALLET_PASSPHRASE="<your password>"
```
1. Run the setup batch script to import the credentials into your local environment: `setup.bat`


# Prerequisites

The following tools or applications are required for these scripts to work. Here are the commands to check they are installed on your system:

1. python3
```bash
python3 --version
```
1. pip3
```bash
pip3 --version
```
To make sure we have all the correct libraries you can use pip with the requirements.txt to install them all
```bash
pip3 install -r requirements.txt
```
1. gq (https://github.com/hasura/graphqurl)
```bash
gq --version
```


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.

```bash
python3 vega-time/get-time.py
```

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.


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):

# Sample scripts

| Script description | Languages | API transport | Folder & README |
| :----------------- | :------- | :------------------------------ | :---------- |
| Get Asset | python3 | Vega node [GraphQL, REST, gRPC] | / [get-assets](get-assets) |
| Orders by reference | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-by-reference](get-by-reference) |
| List market details and market data | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-markets-and-market-data](get-markets-and-market-data) |
| List Vega network parameters | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-network-parameters](get-network-parameters) |
| List orders and trades | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-orders-and-trades](get-orders-and-trades) |
| Vega statistics | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [get-statistics](get-statistics) |
| List parties and accounts | bash, python3 | Vega node [REST, gRPC] | / [parties-and-accounts](parties-and-accounts) |
| Stream market data | python3 | Vega node [GraphQL] | / [stream-marketdata](stream-marketdata) |
| Stream orders and trades | python3 | Vega node [GraphQL] | / [stream-orders-and-trades](stream-orders-and-trades) |
| Interact with Vega wallet API | bash, python3 | Vega wallet [REST] | / [wallet](wallet) |
| Submit, amend and cancel orders | bash, python3 | Vega wallet [REST], Vega node [REST, gRPC] | / [submit-amend-cancel-orders](submit-amend-cancel-orders) |
| Submit and amend pegged orders | bash, python3 | Vega wallet [REST], Vega node [REST, gRPC] | / [submit-amend-pegged-order](submit-amend-pegged-order) |
| Vega/blockchain time | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [vega-time](vega-time) |
| Streaming events | bash, python3 | Vega node [GraphQL, REST, gRPC] | / [stream-events](stream-events) |
| Fees and margins estimation | bash, python3 | Vega node [REST, gRPC] | / [fees-margins-estimation](fees-margins-estimation) |
| Propose, vote and enact new markets | python3 | Vega node [REST] | / [propose-markets](propose-markets) |
| Propose, vote and enact network parameters update | python3 | Vega node [REST] | / [propose-netparams](propose-netparams) |
| Propose, vote and enact new freeform proposal | python3 | Vega node [REST] | / [propose-freeform](propose-freeform) |
| List proposals | bash, python3 | Vega node [GraphQL, gRPC] | / [propose-votes](propose-votes) |
| Submit create liquidity provision | bash, python3 | Data node [GraphQL, gRPC] | / [submit-create-liquidity-provision](submit-create-liquidity-provision) |
| Submit amend liquidity provision | bash, python3 | Data node [GraphQL, gRPC] | / [submit-amend-liquidity-provision](submit-amend-liquidity-provision) |
| Submit cancel liquidity provision | bash, python3 | Data node [GraphQL, gRPC] | / [submit-cancel-liquidity-provision](submit-cancel-liquidity-provision) |

# Troubleshooting

Python/terminal: If you get `No module named 'helpers'...`, you should enter `source credentials` and check with `echo "$PYTHONPATH"` than it shows `"."`.
1. Import the appropriate `vega-config-win` into your local environment for the network you want to test against (default is Fairground testnet).
```
source vega-config-win
```
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.*

1. Run the setup batch script on your command prompt/terminal to import the vega-config into your local environment:
```
setenv.bat
```

1. Navigate to the API transport you would like to explore, for example:
```
cd rest
```

1. Follow the sub-folder README.md information on how to run the samples.

# Contributing or raising issues

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.
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/).

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.
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.
24 changes: 0 additions & 24 deletions credentials-template

This file was deleted.

11 changes: 0 additions & 11 deletions credentials-win-template

This file was deleted.

39 changes: 0 additions & 39 deletions fees-margins-estimation/README.md

This file was deleted.

Loading