Created
February 21, 2018 16:14
-
-
Save koheso/02118464e81db10f8e05254c1e2e292c to your computer and use it in GitHub Desktop.
Binanceで3通貨アービトラージの価格差を取得
This file contains 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
# -*- coding: utf-8 -*- | |
import csv | |
api_key = "" #空白でOK | |
api_secret = "" #空白でOK | |
from binance.client import Client | |
client = Client(api_key, api_secret) | |
# 全銘柄取得 | |
ticker = client.get_ticker() | |
x = 0.0 | |
y = 0.0 | |
z = 0.0 | |
pair1 = None | |
pair2 = None | |
strPair1 = "BTC" #BTC建て | |
strPair2 = "ETH" #ETH建て | |
#対象の通貨リストを読み込み | |
csvFile = open('targetCoins.csv', 'rt',encoding="utf-8") #config.jsonを読み込む | |
csv_in = csv.reader(csvFile, delimiter=",") | |
basePair = strPair2 + strPair1 | |
pairZ = client.get_ticker(symbol=basePair) | |
for row in csv_in: | |
target = row[0] | |
if(target == strPair1 or target == strPair2): | |
continue | |
if strPair2 == "BNB" and target == "ETH": | |
continue | |
for pair in ticker: | |
targetPairName = pair['symbol'] | |
if targetPairName.find(target) != -1: | |
if targetPairName.find(strPair1) != -1: | |
pair1 = pair | |
if targetPairName.find(strPair2) != -1: | |
pair2 = pair | |
if pair1 is not None and pair2 is not None: | |
x = float(pair1['bidPrice']) | |
y = float(pair2['askPrice']) | |
z = float(pairZ['askPrice']) | |
profitRate = (1 - ((y * z) / x)) * 100 | |
if(profitRate > 0): | |
print("★" + target + "_利益率:" + str(profitRate)) | |
print(pair1['symbol']) | |
print(pair1['askPrice']) | |
print(pair1['bidPrice']) | |
print(pair2['symbol']) | |
print(pair2['askPrice']) | |
print(pair2['bidPrice']) | |
print(pairZ['symbol']) | |
print(pairZ['askPrice']) | |
print(pairZ['bidPrice']) | |
a = float(1 / z) | |
b = a / y | |
c = b * x | |
print("①1BTCで" + str(a) + strPair2 + "購入") | |
print("②" + str(b) + target + "購入") | |
print("③" + "売却して" + str(c) + "BTCゲット") | |
pair1 = None | |
pair2 = None | |
csvFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment