Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67ea786
refactor lib and add key file
rcgalbo Aug 23, 2019
9ef4293
update the .
rcgalbo Aug 23, 2019
aa5c44b
add simple test script, example file for api key storage and update r…
rcgalbo Aug 24, 2019
2d94a6c
rewrite test_bybit.py to match pytest standards
rcgalbo Aug 24, 2019
0884d09
fix pytest create working test for
rcgalbo Aug 24, 2019
e70c3fb
fix readme heading
rcgalbo Aug 24, 2019
3bf39b5
add file
rcgalbo Aug 24, 2019
a7d52d5
fix python version 3.7 in travis
rcgalbo Aug 24, 2019
582fb7e
fix python version 3.7 in travis ~ again ~
rcgalbo Aug 24, 2019
0e4d8a4
fix fucking travis fuck fuck fuck
rcgalbo Aug 24, 2019
18c1581
abort travis, clean up
rcgalbo Aug 24, 2019
36aeb33
Merge pull request #1 from rgalbo/refactor
rcgalbo Aug 24, 2019
f638fa6
fix test and add circleci config
rcgalbo Aug 24, 2019
9fe1ba4
ammend circle ci and add requirements.txt
rcgalbo Aug 24, 2019
03538e4
Merge pull request #2 from rgalbo/refactor
rcgalbo Aug 24, 2019
ac8febc
add proper install line
rcgalbo Aug 24, 2019
4ef43f1
add to pip install for circle
rcgalbo Aug 24, 2019
f6fd0aa
.. x2
rcgalbo Aug 24, 2019
e659e5e
add parallelism for faster circleci
rcgalbo Aug 24, 2019
e1fa9e6
Merge pull request #3 from rgalbo/refactor
rcgalbo Aug 24, 2019
03aa19b
add circleci badge to readme
rcgalbo Aug 24, 2019
9080ba5
Merge pull request #4 from rgalbo/refactor
rcgalbo Aug 24, 2019
8b9fb4c
redo env addition, rework readme examples
rcgalbo Aug 30, 2019
317d528
remove bybit egginfo
rcgalbo Aug 30, 2019
e0228e9
update readme example
rcgalbo Aug 30, 2019
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
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
jobs:
build:
docker:
- image: circleci/python:3.7.4-stretch
steps:
- checkout
- run: pip install --user .
parallelism: 4
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
key.sh
__pycache__
.vscode
*.egg-info
.pytest_cache
.ipynb_checkpoints
key.sh
File renamed without changes.
100 changes: 56 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
bybit-exchange-python-sdk
=========================

# bybit-exchange-python-sdk
This is an unofficial Bybit Exchange API python implementation for automated trading. Find the documentation [here](https://bybit-exchange.github.io/bybit-official-api-docs/en/index.html).
[![CircleCI](https://circleci.com/gh/rgalbo/bybit-exchange-python-sdk.svg?style=svg)](https://circleci.com/gh/rgalbo/bybit-exchange-python-sdk)

This is an unofficial Bybit Exchange API python implementation for automated trading. [API Documentation](https://bybit-exchange.github.io/bybit-official-api-docs/en/index.html).

Features
--------
Expand All @@ -12,69 +14,79 @@ Features
- Response exception handling
- Historical Kline/Candle fetching function


Quick Start
-----------

To register an account with Bybit [Click here](https://www.bybit.com/app/register?ref=00xv5)

To Generate an API Key and assign relevant permissions [Click here](https://www.bybit.com/app/user/api-management)

**Terminal Installation**

pip install bybit


**Python**

from bybit import Bybit
client = Client(api_key, api_secret)
Installation
------------
`$ pip install .`

# get exchange symbols
depth = Bybit().get_symbols()
or for my purposes:


# get all symbol prices
prices = Bybit().get_klines('BTCUSD', '15', '1563367231')
```
pyenv local 3.7.4
mkvirtualenv futures
workon futures
pip install -r requirements.txt
cd bybit
python -m pip install -e .
cd ..
jupyter lab
```


# Create Market Buy Orders
auth = Bybit().auth(key, secret)
prices = buy('BTCUSD', 9550, 1.000)
KEY Env Variables
-----------------
```
$ vi key_example.sh # add your api key from bybit in the parenthesis
$ cp key_example.sh key.sh
$ source key.sh # if this doesnt work, copy paste the two lines to your terminal
```

alternatively, in the disgust of all other failure you are likely to ask to just please god fucking hell make jupyter environments stop and run(see [jvp](https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/)):


# Create Market Sell Orders
auth = Bybit().auth(key, secret)
prices = buy('BTCUSD', 9550, 1.000)
for ipython:


```ipython
# follows conveintion %set_env var val:
%set_env BTKEY '[your_key_here]'
%set_env BTSECRET '[your_secret_here]'
```


# Create Market Buy Limit Orders
auth = Bybit().auth(key, secret)
prices = buy('BTCUSD', 9550, 1.000)
for last resort, (key.py):


```python
import sys,os,os.path
sys.path.append(os.path.expanduser('~/code/eol_hsrl_python'))
os.environ['HSRL_INSTRUMENT']='gvhsrl'
os.environ['HSRL_CONFIG']=os.path.expanduser('~/hsrl_config')
```


# Create Market Sell Limit Orders
auth = Bybit().auth(key, secret)
prices = buy('BTCUSD', 9550, 1.000)
API Usage Examples
------------------


```python
import os
from bybit import Bybit


# Cancelling an order
auth = Bybit().auth(key, secret)
prices = cancel_order(order_id)

KEY = os.environ['BTKEY']
SECRET = os.environ['BTSECRET']

bt = Bybit()
bt.(api_key, api_secret)

# get exchange symbols
depth = bt.get_symbols()

# get all symbol prices
prices = bt.get_klines('BTCUSD', '15', '1563367231')

For more check out the documentation
# Create Market Buy Orders
orders = bt.buy('BTCUSD', 9550, 1.000)
```

https://bybit-exchange.github.io/bybit-official-api-docs/en/index.html
check out the [documentation](https://bybit-exchange.github.io/bybit-official-api-docs/en/index.html)!

File renamed without changes.
6 changes: 2 additions & 4 deletions bybit/bybit.py → bybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def order_link_id(self, stringLength):
lettersAndDigits = string.ascii_letters + string.digits
return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))

def public_request(self, method, api_url, params):
def public_request(self, method, api_url, params=''):
'''Public Requests'''
r_url = self.base_url + api_url
try:
Expand All @@ -37,10 +37,8 @@ def get_signed(self, sig_str):
signature = base64.b64encode(hmac.new(self.secret, sig_str, digestmod=hashlib.sha1).digest())
return signature

def signed_request(self, method, api_url, params):
def signed_request(self, method, api_url, params=''):
'''Handler for a signed requests'''

param = ''
if params:
sort_pay = sorted(params.items())
# sort_pay.sort()
Expand Down
80 changes: 0 additions & 80 deletions bybit/README.md

This file was deleted.

1 change: 0 additions & 1 deletion bybit/bybit/__init__.py

This file was deleted.

Empty file added key_example.py
Empty file.
38 changes: 38 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
appdirs==1.4.3
atomicwrites==1.3.0
attrs==19.1.0
backcall==0.1.0
black==19.3b0
certifi==2019.6.16
chardet==3.0.4
Click==7.0
decorator==4.4.0
idna==2.8
importlib-metadata==0.19
influxdb==5.2.2
ipython==7.7.0
ipython-genutils==0.2.0
ipython-pytest==0.0.1
jedi==0.15.1
more-itertools==7.2.0
packaging==19.1
parso==0.5.1
pexpect==4.7.0
pickleshare==0.7.5
pluggy==0.12.0
prompt-toolkit==2.0.9
ptyprocess==0.6.0
py==1.8.0
Pygments==2.4.2
pyparsing==2.4.2
pytest==5.1.1
python-dateutil==2.8.0
pytz==2019.2
requests==2.22.0
six==1.12.0
toml==0.10.0
traitlets==4.3.2
urllib3==1.25.3
wcwidth==0.1.7
websockets==8.0.2
zipp==0.5.2
23 changes: 19 additions & 4 deletions bybit/setup.py → setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import setuptools
from setuptools import setup, find_packages
from distutils.command.sdist import sdist as sdist_orig
from distutils.errors import DistutilsExecError


class keyadd(sdist_orig):
def run(self):
try:
self.spawn(['source', 'key.sh'])
except:
self.warn('adding key env variables failed')
super().run()

# read in description
with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
setup(
name="bybit",
version="0.0.1",
author="Muema",
author="Muemrga",
author_email="hi@ssi.co.ke",
description="unofficial Bybit Exchange API python implementation for automated trading",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/m-root/bybit-exchange-python-sdk",
packages=setuptools.find_packages(),
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: GNU GENERAL PUBLIC LICENSE",
"Operating System :: OS Independent",
],
cmdclass={
'keyadd': keyadd
},
)
22 changes: 22 additions & 0 deletions test_bybit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import os
from bybit import Bybit

KEY = os.environ['BTKEY']
SECRET = os.environ['BTSECRET']

bt = Bybit()
bt.auth(KEY, SECRET)

@pytest.mark.parametrize("bt",[(bt)])
def test_get_symbols(bt):
assert len(bt.get_symbols()) > 0

@pytest.mark.parametrize("bt",[(bt)])
def test_get_klines(bt):
klines = bt.get_klines('BTCUSD', '15', '1563367231')
print(klines)
print(f'len klines: {len(klines)}')

if __name__ == "__main__":
test_get_klines(bt)